use of io.crate.analyze.WindowDefinition in project crate by crate.
the class ExpressionAnalyzer method convertFunctionCall.
private Symbol convertFunctionCall(FunctionCall node, ExpressionAnalysisContext context) {
List<Symbol> arguments = new ArrayList<>(node.getArguments().size());
for (Expression expression : node.getArguments()) {
Symbol argSymbol = expression.accept(innerAnalyzer, context);
arguments.add(argSymbol);
}
List<String> parts = node.getName().getParts();
// We don't set a default schema here because no supplied schema
// means that we first try to lookup builtin functions, followed
// by a lookup in the default schema for UDFs.
String schema = null;
String name;
if (parts.size() == 1) {
name = parts.get(0);
} else {
schema = parts.get(0);
name = parts.get(1);
}
Symbol filter = node.filter().map(expression -> convert(expression, context)).orElse(null);
WindowDefinition windowDefinition = getWindowDefinition(node.getWindow(), context);
if (node.isDistinct()) {
if (arguments.size() > 1) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "%s(DISTINCT x) does not accept more than one argument", node.getName()));
}
Symbol collectSetFunction = allocateFunction(CollectSetAggregation.NAME, arguments, filter, context, coordinatorTxnCtx, nodeCtx);
// define the outer function which contains the inner function as argument.
String nodeName = "collection_" + name;
List<Symbol> outerArguments = List.of(collectSetFunction);
try {
return allocateBuiltinOrUdfFunction(schema, nodeName, outerArguments, null, node.ignoreNulls(), windowDefinition, context);
} catch (UnsupportedOperationException ex) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "unknown function %s(DISTINCT %s)", name, arguments.get(0).valueType()), ex);
}
} else {
return allocateBuiltinOrUdfFunction(schema, name, arguments, filter, node.ignoreNulls(), windowDefinition, context);
}
}
Aggregations