@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; }
@Nullable protected Tuple<Reference, Literal> prepare(Function input) { assert input != null; assert input.arguments().size() == 2; Symbol left = input.arguments().get(0); Symbol right = input.arguments().get(1); if (!(left instanceof Reference) || !(right.symbolType().isValueSymbol())) { return null; } assert right.symbolType() == SymbolType.LITERAL; return new Tuple<>((Reference) left, (Literal) right); }
@Override public Query apply(Function function, Context context) throws IOException { Symbol left = function.arguments().get(0); Symbol collectionSymbol = function.arguments().get(1); Preconditions.checkArgument( DataTypes.isCollectionType(collectionSymbol.valueType()), "invalid argument for ANY expression"); if (left.symbolType().isValueSymbol()) { // 1 = any (array_col) - simple eq assert collectionSymbol.symbolType().isReference() : "no reference found in ANY expression"; return applyArrayReference((Reference) collectionSymbol, (Literal) left, context); } else if (collectionSymbol.symbolType().isValueSymbol()) { assert left.symbolType().isReference() : "no reference found in ANY expression"; return applyArrayLiteral((Reference) left, (Literal) collectionSymbol, context); } else { // should never get here - 2 literal arguments must have been normalized away yet return null; } }
private boolean fieldIgnored(Function function, Context context) { if (function.arguments().size() != 2) { return false; } Symbol left = function.arguments().get(0); Symbol right = function.arguments().get(1); if (left.symbolType() == SymbolType.REFERENCE && right.symbolType().isValueSymbol()) { String columnName = ((Reference) left).info().ident().columnIdent().name(); if (Context.FILTERED_FIELDS.contains(columnName)) { context.filteredFieldValues.put(columnName, ((Input) right).value()); return true; } String unsupportedMessage = Context.UNSUPPORTED_FIELDS.get(columnName); if (unsupportedMessage != null) { throw new UnsupportedFeatureException(unsupportedMessage); } } return false; }
RefLiteralPair(Function function) { assert function.arguments().size() == 2 : "function requires 2 arguments"; Symbol left = function.arguments().get(0); Symbol right = function.arguments().get(1); if (left instanceof Reference) { reference = (Reference) left; } else if (right instanceof Reference) { reference = (Reference) right; } else { reference = null; } if (left.symbolType().isValueSymbol()) { input = (Input) left; } else if (right.symbolType().isValueSymbol()) { input = (Input) right; } else { input = null; } }
FunctionLiteralPair(Function outerFunction) { assert outerFunction.arguments().size() == 2 : "function requires 2 arguments"; Symbol left = outerFunction.arguments().get(0); Symbol right = outerFunction.arguments().get(1); functionName = outerFunction.info().ident().name(); if (left instanceof Function) { function = (Function) left; } else if (right instanceof Function) { function = (Function) right; } else { function = null; } if (left.symbolType().isValueSymbol()) { input = (Input) left; } else if (right.symbolType().isValueSymbol()) { input = (Input) right; } else { input = null; } }
@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); }
private Query queryFromInnerFunction(Function function, Context context) { for (Symbol symbol : function.arguments()) { if (symbol.symbolType() == SymbolType.FUNCTION) { String functionName = ((Function) symbol).info().ident().name(); InnerFunctionToQuery functionToQuery = innerFunctions.get(functionName); if (functionToQuery != null) { try { Query query = functionToQuery.apply(function, (Function) symbol, context); if (query != null) { return query; } } catch (IOException e) { throw ExceptionsHelper.convertToRuntime(e); } } } } return null; }