@Override protected Void visitFunctionCall(FunctionCall node, AtomicBoolean deterministic) { // TODO: total hack to figure out if a function is deterministic. martint should fix this when he refactors the planning code if (node.getName().equals(QualifiedName.of("rand")) || node.getName().equals(QualifiedName.of("random")) || node.getName().equals(QualifiedName.of("shuffle"))) { deterministic.set(false); } return super.visitFunctionCall(node, deterministic); } }
FunctionCall call = entry.getValue().getCall(); Symbol symbol = entry.getKey(); if (call.getName().equals(COUNT)) { List<TypeSignature> scalarAggregationSourceTypeSignatures = ImmutableList.of( symbolAllocator.getTypes().get(nonNullableAggregationSourceSymbol).getTypeSignature());
@Override public Expression rewriteFunctionCall(FunctionCall node, Object context, ExpressionTreeRewriter<Object> treeRewriter) { if (node.getName().equals(QualifiedName.of("fail"))) { return new FunctionCall(QualifiedName.of("fail"), ImmutableList.of()); } return node; } }
@Override protected Object visitFunctionCall(FunctionCall node, Object context) { List<Type> argumentTypes = new ArrayList<>(); List<Object> argumentValues = new ArrayList<>(); for (Expression expression : node.getArguments()) { Object value = process(expression, context); Type type = type(expression); argumentValues.add(value); argumentTypes.add(type); } Signature functionSignature = metadata.getFunctionRegistry().resolveFunction(node.getName(), fromTypes(argumentTypes)); ScalarFunctionImplementation function = metadata.getFunctionRegistry().getScalarFunctionImplementation(functionSignature); for (int i = 0; i < argumentValues.size(); i++) { Object value = argumentValues.get(i); if (value == null && function.getArgumentProperty(i).getNullConvention() == RETURN_NULL_ON_NULL) { return null; } } // do not optimize non-deterministic functions if (optimize && (!function.isDeterministic() || hasUnresolvedValue(argumentValues) || node.getName().equals(QualifiedName.of("fail")))) { return new FunctionCall(node.getName(), node.getWindow(), node.isDistinct(), toExpressions(argumentValues, argumentTypes)); } return functionInvoker.invoke(functionSignature, session, argumentValues); }
@Override protected Boolean visitFunctionCall(FunctionCall actual, Node expected) { if (!(expected instanceof FunctionCall)) { return false; } FunctionCall expectedFunction = (FunctionCall) expected; if (actual.isDistinct() != expectedFunction.isDistinct()) { return false; } if (!actual.getName().equals(expectedFunction.getName())) { return false; } if (!process(actual.getArguments(), expectedFunction.getArguments())) { return false; } if (!process(actual.getFilter(), expectedFunction.getFilter())) { return false; } if (!process(actual.getWindow(), expectedFunction.getWindow())) { return false; } return true; }
if (name.getPrefix().map(prefix -> prefix.equals("collection")).orElse(true)) { referencedCollections.add(name.getSuffix());
@Override public Void visitProject(ProjectNode node, Void context) { StringBuilder builder = new StringBuilder(); for (Map.Entry<Symbol, Expression> entry : node.getAssignments().entrySet()) { if ((entry.getValue() instanceof QualifiedNameReference) && ((QualifiedNameReference) entry.getValue()).getName().equals(entry.getKey().toQualifiedName())) { // skip identity assignments continue; } builder.append(format("%s := %s\\n", entry.getKey(), entry.getValue())); } printNode(node, "Project", builder.toString(), NODE_COLORS.get(NodeType.PROJECT)); return node.getSource().accept(this, context); }
@Override protected Void visitFunctionCall(FunctionCall node, AtomicBoolean deterministic) { // TODO: total hack to figure out if a function is deterministic. martint should fix this when he refactors the planning code if (node.getName().equals(new QualifiedName("rand")) || node.getName().equals(new QualifiedName("random"))) { deterministic.set(false); } return super.visitFunctionCall(node, deterministic); } }
@Override public Void visitProject(ProjectNode node, Integer indent) { print(indent, "- Project => [%s]", formatOutputs(node.getOutputSymbols())); for (Map.Entry<Symbol, Expression> entry : node.getAssignments().entrySet()) { if (entry.getValue() instanceof QualifiedNameReference && ((QualifiedNameReference) entry.getValue()).getName().equals(entry.getKey().toQualifiedName())) { // skip identity assignments continue; } print(indent + 2, "%s := %s", entry.getKey(), entry.getValue()); } return processChildren(node, indent + 1); }
@Override public PlanNode visitProject(ProjectNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); if (!node.getOutputSymbols().equals(source.getOutputSymbols())) { // Can't get rid of this projection. It constrains the output tuple from the underlying operator return replaceChildren(node, ImmutableList.of(source)); } boolean canElide = true; for (Map.Entry<Symbol, Expression> entry : node.getAssignments().entrySet()) { Expression expression = entry.getValue(); Symbol symbol = entry.getKey(); if (!(expression instanceof QualifiedNameReference && ((QualifiedNameReference) expression).getName().equals(symbol.toQualifiedName()))) { canElide = false; break; } } if (canElide) { return source; } return replaceChildren(node, ImmutableList.of(source)); } }
@Override public Expression rewriteFunctionCall(FunctionCall node, Object context, ExpressionTreeRewriter<Object> treeRewriter) { if (node.getName().equals(QualifiedName.of("fail"))) { return new FunctionCall(QualifiedName.of("fail"), ImmutableList.of()); } return node; } }