use of io.crate.sql.tree.TableFunction in project crate by crate.
the class AstBuilder method visitInsert.
@Override
public Node visitInsert(SqlBaseParser.InsertContext context) {
List<String> columns = identsToStrings(context.ident());
Table table;
try {
table = (Table) visit(context.table());
} catch (ClassCastException e) {
TableFunction tf = (TableFunction) visit(context.table());
for (Expression ex : tf.functionCall().getArguments()) {
if (!(ex instanceof QualifiedNameReference)) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "invalid table column reference %s", ex.toString()));
}
}
throw e;
}
return new Insert<>(table, (Query) visit(context.insertSource().query()), columns, getReturningItems(context.returning()), createDuplicateKeyContext(context));
}
use of io.crate.sql.tree.TableFunction in project crate by crate.
the class RelationAnalyzer method visitTableFunction.
@Override
public AnalyzedRelation visitTableFunction(TableFunction node, StatementAnalysisContext statementContext) {
RelationAnalysisContext context = statementContext.currentRelationContext();
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(statementContext.transactionContext(), nodeCtx, statementContext.paramTyeHints(), FieldProvider.UNSUPPORTED, null);
ExpressionAnalysisContext expressionContext = context.expressionAnalysisContext();
// we support `FROM scalar()` but not `FROM 'literal'` -> we turn off eager normalization
// so we can distinguish between Function and Literal.
final boolean allowEagerNormalizeOriginalValue = expressionContext.isEagerNormalizationAllowed();
expressionContext.allowEagerNormalize(false);
Symbol symbol = expressionAnalyzer.convert(node.functionCall(), expressionContext);
expressionContext.allowEagerNormalize(allowEagerNormalizeOriginalValue);
if (!(symbol instanceof Function)) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "Symbol '%s' is not supported in FROM clause", node.name()));
}
Function function = (Function) symbol;
FunctionImplementation functionImplementation = nodeCtx.functions().getQualified(function, statementContext.sessionContext().searchPath());
assert functionImplementation != null : "Function implementation not found using full qualified lookup";
TableFunctionImplementation<?> tableFunction = TableFunctionFactory.from(functionImplementation);
TableFunctionRelation tableRelation = new TableFunctionRelation(tableFunction, function);
context.addSourceRelation(tableRelation);
return tableRelation;
}
use of io.crate.sql.tree.TableFunction 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