use of io.crate.sql.tree.FunctionCall in project crate by crate.
the class AstBuilder method visitLeft.
@Override
public Node visitLeft(SqlBaseParser.LeftContext context) {
Expression strOrColName = (Expression) visit(context.strOrColName);
Expression len = (Expression) visit(context.len);
return new FunctionCall(QualifiedName.of("left"), List.of(strOrColName, len));
}
use of io.crate.sql.tree.FunctionCall in project crate by crate.
the class AstBuilder method visitAtTimezone.
@Override
public Node visitAtTimezone(SqlBaseParser.AtTimezoneContext context) {
Expression zone = (Expression) visit(context.zone);
Expression timestamp = (Expression) visit(context.timestamp);
return new FunctionCall(QualifiedName.of("timezone"), List.of(zone, timestamp));
}
use of io.crate.sql.tree.FunctionCall in project crate by crate.
the class AtTimezoneSyntaxFunctionTest method test_at_time_zone_is_parsed_as_timezone_function_call.
@Test
public void test_at_time_zone_is_parsed_as_timezone_function_call() {
FunctionCall func = (FunctionCall) SqlParser.createExpression("'1978-02-28T10:00:00+01:00' AT TIME ZONE 'Europe/Madrid'");
assertEquals(func.getName(), QualifiedName.of("timezone"));
assertEquals(func.getArguments().size(), 2);
assertEquals(func.getArguments().get(0), StringLiteral.fromObject("Europe/Madrid"));
assertEquals(func.getArguments().get(1), StringLiteral.fromObject("1978-02-28T10:00:00+01:00"));
}
use of io.crate.sql.tree.FunctionCall 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);
}
}
use of io.crate.sql.tree.FunctionCall in project crate by crate.
the class AstBuilder method visitTableFunction.
@Override
public Node visitTableFunction(SqlBaseParser.TableFunctionContext ctx) {
QualifiedName qualifiedName = getQualifiedName(ctx.qname());
List<Expression> arguments = visitCollection(ctx.valueExpression(), Expression.class);
return new TableFunction(new FunctionCall(qualifiedName, arguments));
}
Aggregations