use of com.xiaomi.linden.thrift.common.LindenType in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitFacet_spec.
@Override
public void exitFacet_spec(BQLParser.Facet_specContext ctx) {
String col = unescapeColumnName(ctx.column_name());
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
LindenType type = fieldNameAndType.getValue();
if (type != LindenType.FACET) {
throw new ParseCancellationException(new SemanticException(ctx.column_name(), "Non-facet type column \"" + col + "\" can not be used in browse predicates."));
}
col = fieldNameAndType.getKey();
LindenFacetParam facetParam = new LindenFacetParam();
LindenFacetDimAndPath facetDimAndPath = new LindenFacetDimAndPath();
facetDimAndPath.setDim(col);
if (ctx.n1 != null) {
facetParam.setTopN(Integer.parseInt(ctx.n1.getText()));
}
if (ctx.path != null) {
String path = unescapeStringLiteral(ctx.STRING_LITERAL());
facetDimAndPath.setPath(path);
}
facetParam.setFacetDimAndPath(facetDimAndPath);
facetRequest.addToFacetParams(facetParam);
}
use of com.xiaomi.linden.thrift.common.LindenType in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitEqual_predicate.
@Override
public void exitEqual_predicate(BQLParser.Equal_predicateContext ctx) {
if (ctx.value().PLACEHOLDER() != null) {
return;
}
String value = valProperty.get(ctx.value()).toString();
String col = unescapeColumnName(ctx.column_name());
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
LindenType type = fieldNameAndType.getValue();
col = fieldNameAndType.getKey();
if (!validateValueString(type, value)) {
throw new ParseCancellationException("Filed value: " + value + " doesn't corresponds to field type: " + type);
}
if (inQueryWhere) {
LindenQuery query;
switch(type) {
case STRING:
case FACET:
query = LindenQueryBuilder.buildTermQuery(col, value);
break;
case INTEGER:
case LONG:
case DOUBLE:
case FLOAT:
query = LindenRangeQueryBuilder.buildRangeQuery(col, type, value, value, true, true);
break;
default:
throw new ParseCancellationException("EQUAL predicate doesn't support this type " + type);
}
queryProperty.put(ctx, query);
} else {
LindenFilter filter;
switch(type) {
case STRING:
case FACET:
filter = LindenTermFilterBuilder.buildTermFilter(col, value);
break;
case INTEGER:
case LONG:
case DOUBLE:
case FLOAT:
filter = LindenRangeFilterBuilder.buildRangeFilter(col, type, value, value, true, true);
break;
default:
throw new ParseCancellationException("EQUAL predicate doesn't support this type " + type);
}
filterProperty.put(ctx, filter);
}
}
use of com.xiaomi.linden.thrift.common.LindenType 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.LindenType 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.LindenType in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitAggregation_spec.
@Override
public void exitAggregation_spec(BQLParser.Aggregation_specContext ctx) {
String col = unescapeColumnName(ctx.column_name());
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
LindenType type = fieldNameAndType.getValue();
if (type != LindenType.INTEGER && type != LindenType.LONG && type != LindenType.DOUBLE) {
throw new ParseCancellationException(new SemanticException(ctx.column_name(), "Aggregation doesn't support the type of the field \"" + col + "\"."));
}
col = fieldNameAndType.getKey();
Aggregation aggregation = new Aggregation();
aggregation.setField(col);
aggregation.setType(type);
for (BQLParser.Bucket_specContext specContext : ctx.bucket_spec()) {
Bucket bucket = (Bucket) valProperty.get(specContext);
if (bucket != null) {
aggregation.addToBuckets(bucket);
}
}
facetRequest.addToAggregations(aggregation);
}
Aggregations