if (errMsg == null)
{
errMsg = "Unknown parsing error.";
}
logger.error("BQL parsing error: " + errMsg + ", BQL: " + requestContext.bqlStmt);
writeEmptyResponse(req, resp, new SenseiError(errMsg, ErrorType.BQLParsingError));
return false;
}
// Handle extra BQL filter if it exists
String extraFilter = requestContext.jsonObj.optString(BQL_EXTRA_FILTER);
JSONObject predObj = null;
if (extraFilter.length() > 0)
{
String bql2 = "SELECT * WHERE " + extraFilter;
try
{
predObj = _compiler.compile(bql2);
}
catch (RecognitionException e)
{
String errMsg = _compiler.getErrorMessage(e);
if (errMsg == null)
{
errMsg = "Unknown parsing error.";
}
logger.error("BQL parsing error for additional preds: " + errMsg + ", BQL: " + bql2);
writeEmptyResponse(req, resp, new SenseiError("BQL parsing error for additional preds: " + errMsg + ", BQL: " + bql2, ErrorType.BQLParsingError));
return false;
}
// Combine filters
JSONArray filter_list = new FastJSONArray();
JSONObject currentFilter = requestContext.compiledJson.optJSONObject("filter");
if (currentFilter != null)
{
filter_list.put(currentFilter);
}
JSONArray selections = predObj.optJSONArray("selections");
if (selections != null)
{
for (int i = 0; i < selections.length(); ++i)
{
JSONObject pred = selections.getJSONObject(i);
if (pred != null)
{
filter_list.put(pred);
}
}
}
JSONObject additionalFilter = predObj.optJSONObject("filter");
if (additionalFilter != null)
{
filter_list.put(additionalFilter);
}
if (filter_list.length() > 1)
{
requestContext.compiledJson.put("filter", new FastJSONObject().put("and", filter_list));
}
else if (filter_list.length() == 1)
{
requestContext.compiledJson.put("filter", filter_list.get(0));
}
}
JSONObject metaData = requestContext.compiledJson.optJSONObject("meta");
if (metaData != null)
{
JSONArray variables = metaData.optJSONArray("variables");
if (variables != null)
{
for (int i = 0; i < variables.length(); ++i)
{
String var = variables.getString(i);
if (requestContext.templatesJson == null ||
requestContext.templatesJson.opt(var) == null)
{
writeEmptyResponse(req, resp, new SenseiError("[line:0, col:0] Variable " + var + " is not found.", ErrorType.BQLParsingError));
return false;
}
}
}
}