use of com.xiaomi.linden.thrift.common.LindenType in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitIn_predicate.
@Override
public void exitIn_predicate(BQLParser.In_predicateContext ctx) {
String col = unescapeColumnName(ctx.column_name());
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
LindenType type = fieldNameAndType.getValue();
col = fieldNameAndType.getKey();
List<Object> values = (List<Object>) valProperty.get(ctx.value_list());
List<Object> excludes = (List<Object>) valProperty.get(ctx.except_clause());
List<Map.Entry<String, LindenBooleanClause>> subClauses = new ArrayList<>();
LindenBooleanClause clause = LindenBooleanClause.SHOULD;
if (ctx.not != null) {
clause = LindenBooleanClause.MUST_NOT;
}
for (int i = 0; values != null && i < values.size(); ++i) {
if (values.get(i) == null) {
continue;
}
subClauses.add(new AbstractMap.SimpleEntry<>(values.get(i).toString(), clause));
}
clause = LindenBooleanClause.MUST_NOT;
if (ctx.not != null) {
clause = LindenBooleanClause.SHOULD;
}
for (int i = 0; excludes != null && i < excludes.size(); ++i) {
if (excludes.get(i) == null) {
continue;
}
subClauses.add(new AbstractMap.SimpleEntry<>(excludes.get(i).toString(), clause));
}
if (subClauses.size() == 0) {
return;
}
if (inQueryWhere) {
LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
for (Map.Entry<String, LindenBooleanClause> clauseEntry : subClauses) {
LindenQuery query;
switch(type) {
case STRING:
case FACET:
query = LindenQueryBuilder.buildTermQuery(col, clauseEntry.getKey());
break;
case LONG:
case INTEGER:
case FLOAT:
case DOUBLE:
query = LindenRangeQueryBuilder.buildRangeQuery(col, type, clauseEntry.getKey(), clauseEntry.getKey(), true, true);
break;
default:
throw new ParseCancellationException("IN predicate doesn't support this type " + type);
}
builder.addQuery(query, clauseEntry.getValue());
}
queryProperty.put(ctx, builder.build());
} else {
LindenBooleanFilterBuilder builder = new LindenBooleanFilterBuilder();
for (Map.Entry<String, LindenBooleanClause> clauseEntry : subClauses) {
LindenFilter filter;
switch(type) {
case STRING:
case FACET:
filter = LindenTermFilterBuilder.buildTermFilter(col, clauseEntry.getKey());
break;
case LONG:
case INTEGER:
case FLOAT:
case DOUBLE:
filter = LindenRangeFilterBuilder.buildRangeFilter(col, type, clauseEntry.getKey(), clauseEntry.getKey(), true, true);
break;
default:
throw new ParseCancellationException("IN predicate doesn't support this type " + type);
}
builder.addFilter(filter, clauseEntry.getValue());
}
filterProperty.put(ctx, builder.build());
}
}
use of com.xiaomi.linden.thrift.common.LindenType in project linden by XiaoMi.
the class BQLCompilerAnalyzer method getFieldNameAndType.
private Map.Entry<String, LindenType> getFieldNameAndType(String col) {
LindenType type = fieldTypeMap.get(col);
if (type != null) {
return new AbstractMap.SimpleEntry<>(col, type);
}
LindenFieldSchema fieldSchema = LindenUtil.parseDynamicFieldSchema(col);
return new AbstractMap.SimpleEntry<>(fieldSchema.getName(), fieldSchema.getType());
}
use of com.xiaomi.linden.thrift.common.LindenType in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitNot_equal_predicate.
@Override
public void exitNot_equal_predicate(BQLParser.Not_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) {
LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
builder.addQuery(LindenQueryBuilder.buildMatchAllQuery(), LindenBooleanClause.MUST);
switch(type) {
case STRING:
case FACET:
builder.addQuery(LindenRangeQueryBuilder.buildTermQuery(col, value), LindenBooleanClause.MUST_NOT);
break;
case INTEGER:
case LONG:
case FLOAT:
case DOUBLE:
builder.addQuery(LindenRangeQueryBuilder.buildRangeQuery(col, type, value, value, true, true), LindenBooleanClause.MUST_NOT);
break;
default:
throw new ParseCancellationException("NOT EQUAL predicate doesn't support this type " + type);
}
queryProperty.put(ctx, builder.build());
} else {
LindenBooleanFilterBuilder builder = new LindenBooleanFilterBuilder();
switch(type) {
case STRING:
case FACET:
builder.addFilter(LindenTermFilterBuilder.buildTermFilter(col, value), LindenBooleanClause.MUST_NOT);
break;
case INTEGER:
case LONG:
case FLOAT:
case DOUBLE:
builder.addFilter(LindenRangeFilterBuilder.buildRangeFilter(col, type, value, value, true, true), LindenBooleanClause.MUST_NOT);
break;
default:
throw new ParseCancellationException("NOT EQUAL predicate doesn't support this type " + type);
}
filterProperty.put(ctx, builder.build());
}
}
use of com.xiaomi.linden.thrift.common.LindenType in project linden by XiaoMi.
the class RangeFilterConstructor method construct.
@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws IOException {
LindenRangeFilter lindenRangeFilter = lindenFilter.getRangeFilter();
LindenRange range = lindenRangeFilter.getRange();
LindenType type = range.getType();
String start = range.getStartValue();
String end = range.getEndValue();
String fieldName = range.getField();
boolean startClose = range.isStartClosed();
boolean endClose = range.isEndClosed();
Filter filter = null;
switch(type) {
case STRING:
case FACET:
filter = new TermRangeFilter(fieldName, bytesRefVal(start), bytesRefVal(end), startClose, endClose);
break;
case INTEGER:
filter = NumericRangeFilter.newIntRange(fieldName, intVal(start), intVal(end), startClose, endClose);
break;
case LONG:
filter = NumericRangeFilter.newLongRange(fieldName, longVal(start), longVal(end), startClose, endClose);
break;
case DOUBLE:
filter = NumericRangeFilter.newDoubleRange(fieldName, doubleVal(start), doubleVal(end), startClose, endClose);
break;
case FLOAT:
filter = NumericRangeFilter.newFloatRange(fieldName, floatVal(start), floatVal(end), startClose, endClose);
break;
}
return filter;
}
use of com.xiaomi.linden.thrift.common.LindenType in project linden by XiaoMi.
the class RangeQueryConstructor method construct.
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException {
if (lindenQuery.isSetRangeQuery()) {
LindenRangeQuery lindenRangeQuery = lindenQuery.getRangeQuery();
LindenRange range = lindenRangeQuery.getRange();
String fieldName = range.getField();
LindenType type = range.getType();
String start = range.getStartValue();
String end = range.getEndValue();
boolean startClose = range.isStartClosed();
boolean endClose = range.isEndClosed();
Query query = null;
switch(type) {
case STRING:
case FACET:
query = new TermRangeQuery(fieldName, bytesRefVal(start), bytesRefVal(end), startClose, endClose);
break;
case INTEGER:
query = NumericRangeQuery.newIntRange(fieldName, intVal(start), intVal(end), startClose, endClose);
break;
case LONG:
query = NumericRangeQuery.newLongRange(fieldName, longVal(start), longVal(end), startClose, endClose);
break;
case DOUBLE:
query = NumericRangeQuery.newDoubleRange(fieldName, doubleVal(start), doubleVal(end), startClose, endClose);
break;
case FLOAT:
query = NumericRangeQuery.newFloatRange(fieldName, floatVal(start), floatVal(end), startClose, endClose);
break;
}
return query;
}
// todo throw exception.
return null;
}
Aggregations