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);
}
Aggregations