Search in sources :

Example 1 with Operation

use of io.crate.metadata.table.Operation 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(functions, statementContext.sessionContext(), statementContext.convertParamFunction(), new FieldProvider() {

        @Override
        public Symbol resolveField(QualifiedName qualifiedName, Operation operation) {
            throw new UnsupportedOperationException("Can only resolve literals");
        }

        @Override
        public Symbol resolveField(QualifiedName qualifiedName, @Nullable List path, Operation operation) {
            throw new UnsupportedOperationException("Can only resolve literals");
        }
    }, null);
    Function function = (Function) expressionAnalyzer.convert(node.functionCall(), context.expressionAnalysisContext());
    FunctionImplementation functionImplementation = functions.getSafe(function.info().ident());
    if (functionImplementation.info().type() != FunctionInfo.Type.TABLE) {
        throw new UnsupportedFeatureException("Non table function " + function.info().ident().name() + " is not supported in from clause");
    }
    TableFunctionImplementation tableFunction = (TableFunctionImplementation) functionImplementation;
    TableInfo tableInfo = tableFunction.createTableInfo(clusterService);
    Operation.blockedRaiseException(tableInfo, statementContext.currentOperation());
    TableRelation tableRelation = new TableFunctionRelation(tableInfo, tableFunction, function);
    context.addSourceRelation(node.name(), tableRelation);
    return tableRelation;
}
Also used : TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) Operation(io.crate.metadata.table.Operation) Function(io.crate.analyze.symbol.Function) ImmutableList(com.google.common.collect.ImmutableList) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 Function (io.crate.analyze.symbol.Function)1 Symbol (io.crate.analyze.symbol.Symbol)1 UnsupportedFeatureException (io.crate.exceptions.UnsupportedFeatureException)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 SysClusterTableInfo (io.crate.metadata.sys.SysClusterTableInfo)1 Operation (io.crate.metadata.table.Operation)1 TableInfo (io.crate.metadata.table.TableInfo)1 TableFunctionImplementation (io.crate.metadata.tablefunctions.TableFunctionImplementation)1