private Slot<ColumnView> createNullaryFunctionCall(final FunctionCallNode call) { assert call.getArguments().isEmpty(); final Slot<Integer> rowCount = batch.addRowCount(filterLevel, rootFormClass); return new Slot<ColumnView>() { @Override public ColumnView get() { return ((ColumnFunction) call.getFunction()).columnApply(rowCount.get(), Collections.<ColumnView>emptyList()); } }; }
private void gatherPlaceholderExprs(FormulaNode node, List<SymbolNode> placeholderExprList) { if (node instanceof SymbolNode) { placeholderExprList.add((SymbolNode) node); } else if (node instanceof FunctionCallNode) { FunctionCallNode functionCallNode = (FunctionCallNode) node; List<FormulaNode> arguments = functionCallNode.getArguments(); for (FormulaNode arg : arguments) { gatherPlaceholderExprs(arg, placeholderExprList); } } }
private static SimpleConditionList contains(Criteria criteria, FunctionCallNode call, SimpleOperator operator) { ResourceId field = parseFieldId(call.getArgument(0)); List<SimpleCondition> conditions = new ArrayList<>(); for (int i = 1; i < call.getArguments().size(); i++) { conditions.add(new SimpleCondition(field, operator, parseEnum(call.getArgument(i)))); } return new SimpleConditionList(criteria, conditions); }
@Override public ColumnPlanNode visitFunctionCall(FunctionCallNode callNode) { if(!(callNode.getFunction() instanceof ColumnFunction)) { throw new UnsupportedOperationException("TODO: " + callNode.getFunction().getId()); } List<ColumnPlanNode> arguments = new ArrayList<>(); for (FormulaNode formulaNode : callNode.getArguments()) { arguments.add(formulaNode.accept(this)); } return new VectorOp((ColumnFunction) callNode.getFunction(), arguments); }
private FunctionCallSlot createFunctionCall(final FunctionCallNode call) { resolver.enterFunction(call.getFunction()); try { final List<Slot<ColumnView>> argumentSlots = Lists.newArrayList(); for (FormulaNode argument : call.getArguments()) { argumentSlots.add(argument.accept(this)); } return new FunctionCallSlot((ColumnFunction)call.getFunction(), argumentSlots); } finally { resolver.exitFunction(call.getFunction()); } }
private static SimpleCondition parseCondition(FormulaNode node) { if(node instanceof GroupNode) { return parseCondition(((GroupNode) node).getExpr()); } else if(node instanceof FunctionCallNode) { FunctionCallNode callNode = ((FunctionCallNode) node); if(callNode.getFunction() == NotFunction.INSTANCE) { return parseCondition(callNode.getArgument(0)).negate(); } else if(callNode.getArguments().size() == 2) { return parseBinary(((FunctionCallNode) node)); } else { throw new UnsupportedOperationException("function: " + ((FunctionCallNode) node).getFunction()); } } else if(node instanceof CompoundExpr) { return parseEnumCondition((CompoundExpr) node); } else { throw new UnsupportedOperationException("cannot handle expression: " + node); } }
private FieldType validateFunctionCall(FunctionCallNode call) { // If function calls are involved, this is no longer // a simple field reference this.simpleReference = false; List<FormulaNode> arguments = call.getArguments(); List<FieldType> argumentTypes = new ArrayList<>(); boolean validationFailed = false; for (FormulaNode formulaNode : arguments) { try { argumentTypes.add(validateExpr(formulaNode)); } catch (ValidationFailed e) { // Continue validating the other arguments. validationFailed = true; } } if(validationFailed) { throw new ValidationFailed(); } try { return call.getFunction().resolveResultType(argumentTypes); } catch (ArgumentException e) { errors.add(new FormulaError(arguments.get(e.getArgumentIndex()).getSourceRange(), e.getMessage())); throw new ValidationFailed(); } catch(FormulaException e) { errors.add(new FormulaError(call, e.getMessage())); throw new ValidationFailed(); } }
@Override public Slot<ColumnView> visitFunctionCall(final FunctionCallNode call) { if(call.getFunction() instanceof ColumnFunction) { if(call.getArguments().isEmpty()) { return createNullaryFunctionCall(call); } else { return createFunctionCall(call); } } else if(call.getFunction() instanceof BoundingBoxFunction) { FormulaNode geometry = call.getArgument(0); Collection<NodeMatch> nodes; if(geometry instanceof SymbolNode) { nodes = resolver.resolveSymbol(((SymbolNode) geometry)); } else if(geometry instanceof CompoundExpr) { nodes = resolver.resolveCompoundExpr((CompoundExpr) geometry); } else { throw new QuerySyntaxException("Function " + call.getFunction().getId() + " can only be applied" + " to an argument of type GeoArea."); } return addColumn(nodes.stream().map(n -> n.withComponent(call.getFunction().getId())).collect(Collectors.toList())); } else { throw new UnsupportedOperationException("TODO: " + call.getFunction().getId()); } }
List<FormulaNode> arguments = functionCallNode.getArguments(); FormulaFunction function = functionCallNode.getFunction();
private List<ResourceId> getFieldIds(FormulaNode formulaNode) { List<ResourceId> fieldIds = new ArrayList<>(); if (formulaNode instanceof FunctionCallNode) { FunctionCallNode functionCall = (FunctionCallNode) formulaNode; for(FormulaNode arg : functionCall.getArguments()) { fieldIds.addAll(getFieldIds(arg)); } } else if (formulaNode instanceof SymbolNode) { SymbolNode symbolNode = (SymbolNode) formulaNode; fieldIds.add(ResourceId.valueOf(symbolNode.getName())); } else if (formulaNode instanceof ConstantNode) { ConstantNode constantNode = (ConstantNode) formulaNode; if (constantNode.getType() instanceof EnumType) { fieldIds.add(ResourceId.valueOf(constantNode.toString())); } } else if (formulaNode instanceof CompoundExpr) { CompoundExpr compoundExpr = (CompoundExpr) formulaNode; fieldIds.addAll(getFieldIds(compoundExpr.getValue())); fieldIds.addAll(getFieldIds(compoundExpr.getField())); } else if (formulaNode instanceof GroupNode) { GroupNode groupNode = (GroupNode) formulaNode; fieldIds.addAll(getFieldIds(groupNode.getExpr())); } return fieldIds; }