@Override protected Query applyArrayReference( Reference arrayReference, Literal literal, Context context) throws IOException { QueryBuilderHelper builder = QueryBuilderHelper.forType(((CollectionType) arrayReference.valueType()).innerType()); return builder.eq(arrayReference.ident().columnIdent().fqn(), literal.value()); }
@Nullable private Function rewriteAndValidateFields(Function function, Context context) { if (function.arguments().size() == 2) { Symbol left = function.arguments().get(0); Symbol right = function.arguments().get(1); if (left.symbolType() == SymbolType.REFERENCE && right.symbolType().isValueSymbol()) { Reference ref = (Reference) left; if (ref.info().ident().columnIdent().equals(DocSysColumns.ID)) { function.setArgument( 0, new Reference(DocSysColumns.forTable(ref.ident().tableIdent(), DocSysColumns.UID))); function.setArgument( 1, Literal.newLiteral( Uid.createUid( Constants.DEFAULT_MAPPING_TYPE, ValueSymbolVisitor.STRING.process(right)))); } else { String unsupportedMessage = context.unsupportedMessage(ref.info().ident().columnIdent().name()); if (unsupportedMessage != null) { throw new UnsupportedFeatureException(unsupportedMessage); } } } } return function; }
@Override public Query visitReference(Reference symbol, Context context) { // called for queries like: where boolColumn if (symbol.valueType() == DataTypes.BOOLEAN) { return QueryBuilderHelper.forType(DataTypes.BOOLEAN) .eq(symbol.info().ident().columnIdent().fqn(), true); } return super.visitReference(symbol, context); }
public Query toQuery(Reference reference, DataType type, Object value) { String columnName = reference.info().ident().columnIdent().fqn(); QueryBuilderHelper builder = QueryBuilderHelper.forType(type); Tuple<?, ?> bounds = boundsFunction.apply(value); assert bounds != null; return builder.rangeQuery(columnName, bounds.v1(), bounds.v2(), includeLower, includeUpper); }
@Override protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context) throws IOException { // col != ANY ([1,2,3]) --> not(col=1 and col=2 and col=3) String columnName = reference.info().ident().columnIdent().fqn(); QueryBuilderHelper builder = QueryBuilderHelper.forType(reference.valueType()); BooleanFilter filter = new BooleanFilter(); BooleanFilter notFilter = new BooleanFilter(); for (Object value : toIterable(arrayLiteral.value())) { notFilter.add(builder.eqFilter(columnName, value), BooleanClause.Occur.MUST); } filter.add(notFilter, BooleanClause.Occur.MUST_NOT); return new FilteredQuery(Queries.newMatchAllQuery(), filter); }
@Override protected Query applyArrayReference( Reference arrayReference, Literal literal, Context context) throws IOException { // 1 != any ( col ) --> gt 1 or lt 1 String columnName = arrayReference.info().ident().columnIdent().fqn(); Object value = literal.value(); QueryBuilderHelper builder = QueryBuilderHelper.forType(arrayReference.valueType()); BooleanQuery query = new BooleanQuery(); query.setMinimumNumberShouldMatch(1); query.add( builder.rangeQuery(columnName, value, null, false, false), BooleanClause.Occur.SHOULD); query.add( builder.rangeQuery(columnName, null, value, false, false), BooleanClause.Occur.SHOULD); return query; }
@Override protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context) throws IOException { // col not like ANY (['a', 'b']) --> not(and(like(col, 'a'), like(col, 'b'))) BooleanQuery query = new BooleanQuery(); BooleanQuery notQuery = new BooleanQuery(); String columnName = reference.ident().columnIdent().fqn(); QueryBuilderHelper builder = QueryBuilderHelper.forType(reference.valueType()); for (Object value : toIterable(arrayLiteral.value())) { notQuery.add( builder.like(columnName, value, context.indexCache.filter()), BooleanClause.Occur.MUST); } query.add(notQuery, BooleanClause.Occur.MUST_NOT); return query; }
@Override protected Query applyArrayReference( Reference arrayReference, Literal literal, Context context) throws IOException { // 1 < ANY (array_col) --> array_col > 1 return rangeQuery.toQuery( arrayReference, ((CollectionType) arrayReference.valueType()).innerType(), literal.value()); }
@Override public Query apply(Function input, Context context) { assert input != null; assert input.arguments().size() == 1; Symbol arg = input.arguments().get(0); if (arg.symbolType() != SymbolType.REFERENCE) { return null; } Reference reference = (Reference) arg; String columnName = reference.info().ident().columnIdent().fqn(); QueryBuilderHelper builderHelper = QueryBuilderHelper.forType(reference.valueType()); BooleanFilter boolFilter = new BooleanFilter(); boolFilter.add( builderHelper.rangeFilter(columnName, null, null, true, true), BooleanClause.Occur.MUST_NOT); return new FilteredQuery(Queries.newMatchAllQuery(), boolFilter); }
@Override protected Query applyArrayReference( Reference arrayReference, Literal literal, Context context) throws IOException { String notLike = negateWildcard(convertWildcardToRegex(BytesRefs.toString(literal.value()))); return new RegexpQuery( new Term(arrayReference.info().ident().columnIdent().fqn(), notLike), RegexpFlag.COMPLEMENT.value()); }
@Override public Query apply(Function input, Context context) { Tuple<Reference, Literal> tuple = super.prepare(input); if (tuple == null) { return null; } Reference reference = tuple.v1(); Literal literal = tuple.v2(); String columnName = reference.info().ident().columnIdent().fqn(); if (DataTypes.isCollectionType(reference.valueType()) && DataTypes.isCollectionType(literal.valueType())) { // create boolean filter with term filters to pre-filter the result before applying the // functionQuery. BooleanFilter boolTermsFilter = new BooleanFilter(); DataType type = literal.valueType(); while (DataTypes.isCollectionType(type)) { type = ((CollectionType) type).innerType(); } QueryBuilderHelper builder = QueryBuilderHelper.forType(type); Object value = literal.value(); buildTermsQuery(boolTermsFilter, value, columnName, builder); if (boolTermsFilter.clauses().isEmpty()) { // all values are null... return genericFunctionQuery(input, context); } // wrap boolTermsFilter and genericFunction filter in an additional BooleanFilter to // control the ordering of the filters // termsFilter is applied first // afterwards the more expensive genericFunctionFilter BooleanFilter filterClauses = new BooleanFilter(); filterClauses.add(boolTermsFilter, BooleanClause.Occur.MUST); filterClauses.add(genericFunctionFilter(input, context), BooleanClause.Occur.MUST); return new FilteredQuery(Queries.newMatchAllQuery(), filterClauses); } QueryBuilderHelper builder = QueryBuilderHelper.forType(tuple.v1().valueType()); return builder.eq(columnName, tuple.v2().value()); }
@Override protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context) throws IOException { // col < ANY ([1,2,3]) --> or(col<1, col<2, col<3) BooleanQuery booleanQuery = new BooleanQuery(); booleanQuery.setMinimumNumberShouldMatch(1); for (Object value : toIterable(arrayLiteral.value())) { booleanQuery.add( inverseRangeQuery.toQuery(reference, reference.valueType(), value), BooleanClause.Occur.SHOULD); } return booleanQuery; }
public Query toQuery(Reference reference, Object value, Context context) { String columnName = reference.info().ident().columnIdent().fqn(); QueryBuilderHelper builder = QueryBuilderHelper.forType(reference.valueType()); return builder.like(columnName, value, context.indexCache.filter()); }
@Override protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context) throws IOException { String columnName = reference.ident().columnIdent().fqn(); return new FilteredQuery(Queries.newMatchAllQuery(), termsFilter(columnName, arrayLiteral)); }