Search in sources :

Example 6 with LindenType

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);
}
Also used : LindenFacetDimAndPath(com.xiaomi.linden.thrift.common.LindenFacetDimAndPath) LindenFacetParam(com.xiaomi.linden.thrift.common.LindenFacetParam) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) LindenType(com.xiaomi.linden.thrift.common.LindenType) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 7 with LindenType

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);
    }
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) LindenType(com.xiaomi.linden.thrift.common.LindenType) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 8 with LindenType

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);
    }
}
Also used : LindenQueryFilter(com.xiaomi.linden.thrift.common.LindenQueryFilter) LindenWildcardQuery(com.xiaomi.linden.thrift.common.LindenWildcardQuery) LindenBooleanFilter(com.xiaomi.linden.thrift.common.LindenBooleanFilter) LindenType(com.xiaomi.linden.thrift.common.LindenType) LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) LindenBooleanSubFilter(com.xiaomi.linden.thrift.common.LindenBooleanSubFilter) LindenBooleanQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 9 with LindenType

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);
    }
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) LindenType(com.xiaomi.linden.thrift.common.LindenType) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 10 with LindenType

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);
}
Also used : Aggregation(com.xiaomi.linden.thrift.common.Aggregation) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) Bucket(com.xiaomi.linden.thrift.common.Bucket) LindenType(com.xiaomi.linden.thrift.common.LindenType) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Aggregations

LindenType (com.xiaomi.linden.thrift.common.LindenType)20 AbstractMap (java.util.AbstractMap)14 HashMap (java.util.HashMap)14 Map (java.util.Map)14 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)10 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)7 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)7 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 LindenBooleanFilterBuilder (com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder)3 Aggregation (com.xiaomi.linden.thrift.common.Aggregation)2 Bucket (com.xiaomi.linden.thrift.common.Bucket)2 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)2 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)2 LindenFieldSchema (com.xiaomi.linden.thrift.common.LindenFieldSchema)2 LindenRange (com.xiaomi.linden.thrift.common.LindenRange)2 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)2 Query (org.apache.lucene.search.Query)2 AggregationResult (com.xiaomi.linden.thrift.common.AggregationResult)1