Search in sources :

Example 1 with CopyTo

use of io.crate.sql.tree.CopyTo in project crate by crate.

the class CopyAnalyzer method analyzeCopyTo.

AnalyzedCopyTo analyzeCopyTo(CopyTo<Expression> node, ParamTypeHints paramTypeHints, CoordinatorTxnCtx txnCtx) {
    if (!node.directoryUri()) {
        throw new UnsupportedOperationException("Using COPY TO without specifying a DIRECTORY is not supported");
    }
    TableInfo tableInfo = schemas.resolveTableInfo(node.table().getName(), Operation.COPY_TO, txnCtx.sessionContext().sessionUser(), txnCtx.sessionContext().searchPath());
    Operation.blockedRaiseException(tableInfo, Operation.READ);
    DocTableRelation tableRelation = new DocTableRelation((DocTableInfo) tableInfo);
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, tableRelation);
    var exprCtx = new ExpressionAnalysisContext(txnCtx.sessionContext());
    var expressionAnalyzer = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, new NameFieldProvider(tableRelation), null);
    var exprAnalyzerWithFieldsAsString = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, FieldProvider.FIELDS_AS_LITERAL, null);
    var uri = expressionAnalyzer.convert(node.targetUri(), exprCtx);
    var table = node.table().map(x -> exprAnalyzerWithFieldsAsString.convert(x, exprCtx));
    var properties = node.properties().map(x -> expressionAnalyzer.convert(x, exprCtx));
    var columns = Lists2.map(node.columns(), c -> normalizer.normalize(expressionAnalyzer.convert(c, exprCtx), txnCtx));
    var whereClause = node.whereClause().map(w -> normalizer.normalize(expressionAnalyzer.convert(w, exprCtx), txnCtx)).orElse(null);
    return new AnalyzedCopyTo(tableInfo, table, normalizer.normalize(uri, txnCtx), properties, columns, whereClause);
}
Also used : ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) TableRelation(io.crate.analyze.relations.TableRelation) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) FieldProvider(io.crate.analyze.relations.FieldProvider) CopyFrom(io.crate.sql.tree.CopyFrom) Table(io.crate.sql.tree.Table) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) GenericProperties(io.crate.sql.tree.GenericProperties) Operation(io.crate.metadata.table.Operation) Lists2(io.crate.common.collections.Lists2) CopyTo(io.crate.sql.tree.CopyTo) RowGranularity(io.crate.metadata.RowGranularity) DocTableRelation(io.crate.analyze.relations.DocTableRelation) Symbol(io.crate.expression.symbol.Symbol) NameFieldProvider(io.crate.analyze.relations.NameFieldProvider) Schemas(io.crate.metadata.Schemas) Expression(io.crate.sql.tree.Expression) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) NameFieldProvider(io.crate.analyze.relations.NameFieldProvider) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) DocTableRelation(io.crate.analyze.relations.DocTableRelation) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo)

Aggregations

ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 FieldProvider (io.crate.analyze.relations.FieldProvider)1 NameFieldProvider (io.crate.analyze.relations.NameFieldProvider)1 TableRelation (io.crate.analyze.relations.TableRelation)1 Lists2 (io.crate.common.collections.Lists2)1 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 Symbol (io.crate.expression.symbol.Symbol)1 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)1 NodeContext (io.crate.metadata.NodeContext)1 RowGranularity (io.crate.metadata.RowGranularity)1 Schemas (io.crate.metadata.Schemas)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 Operation (io.crate.metadata.table.Operation)1 TableInfo (io.crate.metadata.table.TableInfo)1 CopyFrom (io.crate.sql.tree.CopyFrom)1 CopyTo (io.crate.sql.tree.CopyTo)1 Expression (io.crate.sql.tree.Expression)1 GenericProperties (io.crate.sql.tree.GenericProperties)1