Search in sources :

Example 1 with CreateSnapshot

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

the class CreateSnapshotAnalyzer method analyze.

public AnalyzedCreateSnapshot analyze(CreateSnapshot<Expression> createSnapshot, ParamTypeHints paramTypeHints, CoordinatorTxnCtx txnCtx) {
    String repositoryName = createSnapshot.name().getPrefix().map(name -> {
        validateRepository(name);
        return name.toString();
    }).orElseThrow(() -> new IllegalArgumentException("Snapshot must be specified by \"<repository_name>\".\"<snapshot_name>\""));
    String snapshotName = createSnapshot.name().getSuffix();
    Snapshot snapshot = new Snapshot(repositoryName, new SnapshotId(snapshotName, UUIDs.dirtyUUID().toString()));
    var exprCtx = new ExpressionAnalysisContext(txnCtx.sessionContext());
    var exprAnalyzerWithoutFields = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, FieldProvider.UNSUPPORTED, null);
    var exprAnalyzerWithFieldsAsString = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, FieldProvider.FIELDS_AS_LITERAL, null);
    List<Table<Symbol>> tables = Lists2.map(createSnapshot.tables(), (table) -> table.map(x -> exprAnalyzerWithFieldsAsString.convert(x, exprCtx)));
    GenericProperties<Symbol> properties = createSnapshot.properties().map(x -> exprAnalyzerWithoutFields.convert(x, exprCtx));
    return new AnalyzedCreateSnapshot(snapshot, tables, properties);
}
Also used : ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) NodeContext(io.crate.metadata.NodeContext) SnapshotId(org.elasticsearch.snapshots.SnapshotId) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) RepositoryService(io.crate.execution.ddl.RepositoryService) FieldProvider(io.crate.analyze.relations.FieldProvider) CreateSnapshot(io.crate.sql.tree.CreateSnapshot) UUIDs(org.elasticsearch.common.UUIDs) Table(io.crate.sql.tree.Table) GenericProperties(io.crate.sql.tree.GenericProperties) Lists2(io.crate.common.collections.Lists2) List(java.util.List) Symbol(io.crate.expression.symbol.Symbol) Locale(java.util.Locale) QualifiedName(io.crate.sql.tree.QualifiedName) Snapshot(org.elasticsearch.snapshots.Snapshot) Expression(io.crate.sql.tree.Expression) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Table(io.crate.sql.tree.Table) Symbol(io.crate.expression.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) CreateSnapshot(io.crate.sql.tree.CreateSnapshot) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId)

Aggregations

ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 FieldProvider (io.crate.analyze.relations.FieldProvider)1 Lists2 (io.crate.common.collections.Lists2)1 RepositoryService (io.crate.execution.ddl.RepositoryService)1 Symbol (io.crate.expression.symbol.Symbol)1 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)1 NodeContext (io.crate.metadata.NodeContext)1 CreateSnapshot (io.crate.sql.tree.CreateSnapshot)1 Expression (io.crate.sql.tree.Expression)1 GenericProperties (io.crate.sql.tree.GenericProperties)1 QualifiedName (io.crate.sql.tree.QualifiedName)1 Table (io.crate.sql.tree.Table)1 List (java.util.List)1 Locale (java.util.Locale)1 UUIDs (org.elasticsearch.common.UUIDs)1 Snapshot (org.elasticsearch.snapshots.Snapshot)1 SnapshotId (org.elasticsearch.snapshots.SnapshotId)1