use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitSelect_stmt.
@Override
public void exitSelect_stmt(BQLParser.Select_stmtContext ctx) {
if (ctx.order_by_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.order_by_clause(1), "ORDER BY clause can only appear once."));
}
if (ctx.limit_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.limit_clause(1), "LIMIT clause can only appear once."));
}
if (ctx.group_by_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.group_by_clause(1), "GROUP BY clause can only appear once."));
}
if (ctx.browse_by_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.browse_by_clause(1), "BROWSE BY clause can only appear once."));
}
if (ctx.drill_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.drill_clause(1), "DRILL clause can only appear once."));
}
if (ctx.source_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.source_clause(1), "SOURCE clause can only appear once."));
}
if (ctx.route_by_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.route_by_clause(1), "ROUTE BY clause can only appear once."));
}
if (ctx.score_model_clause().size() > 1) {
throw new ParseCancellationException(new SemanticException(ctx.score_model_clause(1), "USING SCORE MODEL clause can only appear once."));
}
LindenSearchRequest lindenRequest = new LindenSearchRequest();
if (ctx.cols != null) {
lindenRequest.setSourceFields((List<String>) valProperty.get(ctx.cols));
}
if (ctx.tables != null) {
lindenRequest.setIndexNames((List<String>) valProperty.get(ctx.tables));
}
if (ctx.group_by != null) {
GroupParam groupParam = (GroupParam) valProperty.get(ctx.group_by);
if (groupParam != null) {
lindenRequest.setGroupParam(groupParam);
}
}
if (ctx.limit != null) {
lindenRequest.setOffset(offsetProperty.get(ctx.limit));
lindenRequest.setLength(countProperty.get(ctx.limit));
}
if (ctx.source != null && (Boolean) valProperty.get(ctx.source)) {
lindenRequest.setSource(true);
}
if (ctx.explain != null && (Boolean) valProperty.get(ctx.explain)) {
lindenRequest.setExplain(true);
}
LindenQuery query = null;
if (ctx.q != null) {
query = queryProperty.get(ctx.q);
}
if (query == null) {
query = LindenQueryBuilder.buildMatchAllQuery();
}
lindenRequest.setQuery(query);
if (ctx.w != null) {
LindenFilter filter = filterProperty.get(ctx.w);
lindenRequest.setFilter(filter);
}
if (ctx.scoring_model != null) {
LindenScoreModel scoreModel = (LindenScoreModel) valProperty.get(ctx.scoring_model);
lindenRequest.getQuery().setScoreModel(scoreModel);
}
if (ctx.boost_by != null && ctx.boost_by.numeric_value().PLACEHOLDER() == null) {
lindenRequest.getQuery().setBoost(Double.valueOf(ctx.boost_by.numeric_value().getText()));
}
if (spatialParam != null) {
lindenRequest.setSpatialParam(spatialParam);
}
if (ctx.order_by != null) {
lindenRequest.setSort((LindenSort) valProperty.get(ctx.order_by));
}
if (ctx.snippet != null) {
lindenRequest.setSnippetParam((SnippetParam) valProperty.get(ctx.snippet));
}
if (ctx.in_top != null) {
lindenRequest.setEarlyParam((EarlyParam) valProperty.get(ctx.in_top));
}
if (ctx.route_param != null) {
lindenRequest.setRouteParam((SearchRouteParam) valProperty.get(ctx.route_param));
}
if (facetRequest.isSetFacetParams() || facetRequest.isSetDrillDownDimAndPaths() || facetRequest.isSetAggregations()) {
lindenRequest.setFacet(facetRequest);
}
lindenSearchRequestProperty.put(ctx, lindenRequest);
}
use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitLike_predicate.
@Override
public void exitLike_predicate(BQLParser.Like_predicateContext ctx) {
if (ctx.PLACEHOLDER() != null) {
return;
}
String col = unescapeColumnName(ctx.column_name());
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
LindenType type = fieldNameAndType.getValue();
if (type != LindenType.STRING && type != LindenType.FACET) {
throw new ParseCancellationException(new SemanticException(ctx.column_name(), "Non-string type column \"" + col + "\" can not be used in LIKE predicates."));
}
col = fieldNameAndType.getKey();
String likeString = unescapeStringLiteral(ctx.STRING_LITERAL());
LindenWildcardQuery wildcardQuery = new LindenWildcardQuery().setField(col).setQuery(likeString);
if (inQueryWhere) {
if (ctx.NOT() != null) {
LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
builder.addQuery(LindenRangeQueryBuilder.buildMatchAllQuery(), LindenBooleanClause.MUST);
builder.addQuery(new LindenQuery().setWildcardQuery(wildcardQuery), LindenBooleanClause.MUST_NOT);
queryProperty.put(ctx, builder.build());
} else {
queryProperty.put(ctx, new LindenQuery().setWildcardQuery(wildcardQuery));
}
} else {
LindenFilter filter = new LindenFilter().setQueryFilter(new LindenQueryFilter().setQuery(new LindenQuery().setWildcardQuery(wildcardQuery)));
if (ctx.NOT() != null) {
LindenBooleanFilter booleanFilter = new LindenBooleanFilter();
booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(filter).setClause(LindenBooleanClause.MUST_NOT));
filter = new LindenFilter().setBooleanFilter(booleanFilter);
}
filterProperty.put(ctx, filter);
}
}
use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitRange_predicate.
@Override
public void exitRange_predicate(BQLParser.Range_predicateContext ctx) {
// ignore unassigned value
if (ctx.val.PLACEHOLDER() != null) {
return;
}
Object val = valProperty.get(ctx.val);
String col = unescapeColumnName(ctx.column_name());
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
LindenType type = fieldNameAndType.getValue();
col = fieldNameAndType.getKey();
if (!checkValueType(type, val)) {
throw new ParseCancellationException("Value: " + val + " in RANGE predicate doesn't correspond to field type: " + type);
}
String strVal1;
String strVal2;
boolean isStartClosed = false;
boolean isEndClosed = false;
if (ctx.op.getText().charAt(0) == '>') {
strVal1 = val.toString();
strVal2 = null;
if (">=".equals(ctx.op.getText())) {
isStartClosed = true;
}
} else {
strVal1 = null;
strVal2 = val.toString();
if ("<=".equals(ctx.op.getText())) {
isEndClosed = true;
}
}
if (inQueryWhere) {
LindenQuery query = LindenRangeQueryBuilder.buildRangeQuery(col, type, strVal1, strVal2, isStartClosed, isEndClosed);
queryProperty.put(ctx, query);
} else {
LindenFilter filter = LindenRangeFilterBuilder.buildRangeFilter(col, type, strVal1, strVal2, isStartClosed, isEndClosed);
filterProperty.put(ctx, filter);
}
}
use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitDistance_predicate.
@Override
public void exitDistance_predicate(BQLParser.Distance_predicateContext ctx) {
if (ctx.range.PLACEHOLDER() != null || ctx.lat.PLACEHOLDER() != null || ctx.lon.PLACEHOLDER() != null) {
return;
}
LindenFilter spatialFilter = LindenSpatialFilterBuilder.buildSpatialParam(Double.valueOf(ctx.lon.getText()), Double.valueOf(ctx.lat.getText()), Double.valueOf(ctx.range.getText()));
spatialParam = spatialFilter.getSpatialFilter().getSpatialParam();
filterProperty.put(ctx, spatialFilter);
}
use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitBetween_predicate.
@Override
public void exitBetween_predicate(BQLParser.Between_predicateContext ctx) {
if (ctx.val1.PLACEHOLDER() != null || ctx.val2.PLACEHOLDER() != null) {
return;
}
String val1 = valProperty.get(ctx.val1).toString();
String val2 = valProperty.get(ctx.val2).toString();
String col = unescapeColumnName(ctx.column_name());
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
LindenType type = fieldNameAndType.getValue();
col = fieldNameAndType.getKey();
if (!validateValueString(type, val1)) {
throw new ParseCancellationException("Filed value: " + val1 + " doesn't corresponds to field type: " + type);
}
if (!validateValueString(type, val2)) {
throw new ParseCancellationException("Filed value: " + val2 + " doesn't corresponds to field type: " + type);
}
if (inQueryWhere) {
LindenQuery query;
if (ctx.not == null) {
query = LindenRangeQueryBuilder.buildRangeQuery(col, type, val1, val2, true, true);
} else {
LindenQuery query1 = LindenRangeQueryBuilder.buildRangeQuery(col, type, null, val1, false, false);
LindenQuery query2 = LindenRangeQueryBuilder.buildRangeQuery(col, type, val2, null, false, false);
LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
builder.addQuery(query1, LindenBooleanClause.SHOULD);
builder.addQuery(query2, LindenBooleanClause.SHOULD);
query = builder.build();
}
queryProperty.put(ctx, query);
} else {
LindenFilter filter;
if (ctx.not == null) {
filter = LindenRangeFilterBuilder.buildRangeFilter(col, type, val1, val2, true, true);
} else {
LindenFilter filter1 = LindenRangeFilterBuilder.buildRangeFilter(col, type, null, val1, false, false);
LindenFilter filter2 = LindenRangeFilterBuilder.buildRangeFilter(col, type, val2, null, false, false);
LindenBooleanFilterBuilder builder = new LindenBooleanFilterBuilder();
builder.addFilter(filter1, LindenBooleanClause.SHOULD);
builder.addFilter(filter2, LindenBooleanClause.SHOULD);
filter = builder.build();
}
if (filter != null) {
filterProperty.put(ctx, filter);
}
}
}
Aggregations