Search in sources :

Example 1 with TableParameter

use of io.crate.analyze.TableParameter in project crate by crate.

the class AlterTableOperation method executeAlterTable.

public CompletableFuture<Long> executeAlterTable(AlterTableAnalyzedStatement analysis) {
    DocTableInfo table = analysis.table();
    if (table.isAlias() && !table.isPartitioned()) {
        return CompletableFutures.failedFuture(new AlterTableAliasException(table.ident().fqn()));
    }
    List<CompletableFuture<Long>> results = new ArrayList<>(3);
    if (table.isPartitioned()) {
        // create new filtered partition table settings
        PartitionedTableParameterInfo tableSettingsInfo = (PartitionedTableParameterInfo) table.tableParameterInfo();
        TableParameter parameterWithFilteredSettings = new TableParameter(analysis.tableParameter().settings(), tableSettingsInfo.partitionTableSettingsInfo().supportedInternalSettings());
        Optional<PartitionName> partitionName = analysis.partitionName();
        if (partitionName.isPresent()) {
            String index = partitionName.get().asIndexName();
            results.add(updateMapping(analysis.tableParameter().mappings(), index));
            results.add(updateSettings(parameterWithFilteredSettings, index));
        } else {
            // template gets all changes unfiltered
            results.add(updateTemplate(analysis.tableParameter(), table.ident()));
            if (!analysis.excludePartitions()) {
                String[] indices = table.concreteIndices();
                results.add(updateMapping(analysis.tableParameter().mappings(), indices));
                results.add(updateSettings(parameterWithFilteredSettings, indices));
            }
        }
    } else {
        results.add(updateMapping(analysis.tableParameter().mappings(), table.ident().indexName()));
        results.add(updateSettings(analysis.tableParameter(), table.ident().indexName()));
    }
    final CompletableFuture<Long> result = new CompletableFuture<>();
    applyMultiFutureCallback(result, results);
    return result;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableParameter(io.crate.analyze.TableParameter) PartitionedTableParameterInfo(io.crate.analyze.PartitionedTableParameterInfo) PartitionName(io.crate.metadata.PartitionName) CompletableFuture(java.util.concurrent.CompletableFuture) AlterTableAliasException(io.crate.exceptions.AlterTableAliasException)

Example 2 with TableParameter

use of io.crate.analyze.TableParameter in project crate by crate.

the class AlterBlobTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, params, subQueryResults);
    TableInfo tableInfo = analyzedAlterTable.tableInfo();
    AlterTable<Object> alterTable = analyzedAlterTable.alterTable().map(eval);
    TableParameter tableParameter = getTableParameter(alterTable, TableParameters.ALTER_BLOB_TABLE_PARAMETERS);
    maybeRaiseBlockedException(tableInfo, tableParameter.settings());
    BoundAlterTable stmt = new BoundAlterTable(tableInfo, null, tableParameter, true, false);
    dependencies.alterTableOperation().executeAlterTable(stmt).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : AlterTable(io.crate.sql.tree.AlterTable) TableParameter(io.crate.analyze.TableParameter) TableInfo(io.crate.metadata.table.TableInfo) BoundAlterTable(io.crate.analyze.BoundAlterTable) Function(java.util.function.Function) TableParameters(io.crate.analyze.TableParameters) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) AnalyzedAlterBlobTable(io.crate.analyze.AnalyzedAlterBlobTable) AlterTablePlan.getTableParameter(io.crate.planner.node.ddl.AlterTablePlan.getTableParameter) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) AlterTablePlan.maybeRaiseBlockedException(io.crate.planner.node.ddl.AlterTablePlan.maybeRaiseBlockedException) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) Row1(io.crate.data.Row1) BoundAlterTable(io.crate.analyze.BoundAlterTable) TableParameter(io.crate.analyze.TableParameter) AlterTablePlan.getTableParameter(io.crate.planner.node.ddl.AlterTablePlan.getTableParameter) TableInfo(io.crate.metadata.table.TableInfo)

Example 3 with TableParameter

use of io.crate.analyze.TableParameter in project crate by crate.

the class AlterTablePlan method bind.

public static BoundAlterTable bind(AnalyzedAlterTable analyzedAlterTable, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row params, SubQueryResults subQueryResults) {
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, params, subQueryResults);
    DocTableInfo docTableInfo = analyzedAlterTable.tableInfo();
    AlterTable<Object> alterTable = analyzedAlterTable.alterTable().map(eval);
    Table<Object> table = alterTable.table();
    PartitionName partitionName = PartitionPropertiesAnalyzer.createPartitionName(table.partitionProperties(), docTableInfo);
    TableParameters tableParameters = getTableParameterInfo(table, partitionName);
    TableParameter tableParameter = getTableParameter(alterTable, tableParameters);
    maybeRaiseBlockedException(docTableInfo, tableParameter.settings());
    return new BoundAlterTable(docTableInfo, partitionName, tableParameter, table.excludePartitions(), docTableInfo.isPartitioned());
}
Also used : AlterTable(io.crate.sql.tree.AlterTable) AnalyzedAlterTable(io.crate.analyze.AnalyzedAlterTable) BoundAlterTable(io.crate.analyze.BoundAlterTable) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) PartitionPropertiesAnalyzer(io.crate.analyze.PartitionPropertiesAnalyzer) Operation(io.crate.metadata.table.Operation) Function(java.util.function.Function) PartitionName(io.crate.metadata.PartitionName) DependencyCarrier(io.crate.planner.DependencyCarrier) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Nullable(javax.annotation.Nullable) TableParameter(io.crate.analyze.TableParameter) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) TablePropertiesAnalyzer(io.crate.analyze.TablePropertiesAnalyzer) Table(io.crate.sql.tree.Table) TableParameters(io.crate.analyze.TableParameters) RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) PartitionName(io.crate.metadata.PartitionName) DocTableInfo(io.crate.metadata.doc.DocTableInfo) BoundAlterTable(io.crate.analyze.BoundAlterTable) TableParameter(io.crate.analyze.TableParameter) TableParameters(io.crate.analyze.TableParameters)

Example 4 with TableParameter

use of io.crate.analyze.TableParameter in project crate by crate.

the class CreateTablePlan method bind.

@VisibleForTesting
public static BoundCreateTable bind(AnalyzedCreateTable createTable, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row params, SubQueryResults subQueryResults, NumberOfShards numberOfShards, Schemas schemas, FulltextAnalyzerResolver fulltextAnalyzerResolver) {
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, params, subQueryResults);
    CreateTable<Symbol> table = createTable.createTable();
    RelationName relationName = createTable.relationName();
    GenericProperties<Object> properties = table.properties().map(eval);
    AnalyzedTableElements<Object> tableElements = createTable.analyzedTableElements().map(eval);
    TableParameter tableParameter = new TableParameter();
    Optional<ClusteredBy<Object>> mappedClusteredBy = table.clusteredBy().map(x -> x.map(eval));
    Integer numShards = mappedClusteredBy.flatMap(ClusteredBy::numberOfShards).map(numberOfShards::fromNumberOfShards).orElseGet(numberOfShards::defaultNumberOfShards);
    tableParameter.settingsBuilder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards);
    // apply default in case it is not specified in the properties,
    // if it is it will get overwritten afterwards.
    TablePropertiesAnalyzer.analyzeWithBoundValues(tableParameter, TableParameters.TABLE_CREATE_PARAMETER_INFO, properties, true);
    AnalyzedTableElements<Symbol> tableElementsWithExpressions = createTable.analyzedTableElementsWithExpressions().map(x -> SubQueryAndParamBinder.convert(x, params, subQueryResults));
    // validate table elements
    AnalyzedTableElements.finalizeAndValidate(relationName, tableElementsWithExpressions, tableElements);
    // update table settings
    Settings tableSettings = AnalyzedTableElements.validateAndBuildSettings(tableElements, fulltextAnalyzerResolver);
    tableParameter.settingsBuilder().put(tableSettings);
    ColumnIdent routingColumn = mappedClusteredBy.map(clusteredBy -> resolveRoutingFromClusteredBy(clusteredBy, tableElements)).orElse(null);
    Optional<PartitionedBy<Object>> partitionedByOptional = table.partitionedBy().map(x -> x.map(eval));
    partitionedByOptional.ifPresent(partitionedBy -> processPartitionedBy(partitionedByOptional.get(), tableElements, relationName, routingColumn));
    return new BoundCreateTable(relationName, tableElements, tableParameter, routingColumn, table.ifNotExists(), schemas);
}
Also used : AnalyzedColumnDefinition(io.crate.analyze.AnalyzedColumnDefinition) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) SENTINEL(io.crate.data.SentinelRow.SENTINEL) GenericProperties(io.crate.sql.tree.GenericProperties) Function(java.util.function.Function) DependencyCarrier(io.crate.planner.DependencyCarrier) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) OneRowActionListener(io.crate.execution.support.OneRowActionListener) BoundCreateTable(io.crate.analyze.BoundCreateTable) FulltextAnalyzerResolver(io.crate.metadata.FulltextAnalyzerResolver) Nullable(javax.annotation.Nullable) TableParameter(io.crate.analyze.TableParameter) CreateTable(io.crate.sql.tree.CreateTable) AnalyzedCreateTable(io.crate.analyze.AnalyzedCreateTable) NodeContext(io.crate.metadata.NodeContext) PartitionedBy(io.crate.sql.tree.PartitionedBy) TableCreator(io.crate.execution.ddl.tables.TableCreator) TablePropertiesAnalyzer(io.crate.analyze.TablePropertiesAnalyzer) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) ColumnIdent(io.crate.metadata.ColumnIdent) SubQueryAndParamBinder(io.crate.planner.operators.SubQueryAndParamBinder) TableParameters(io.crate.analyze.TableParameters) RowConsumer(io.crate.data.RowConsumer) AnalyzedTableElements(io.crate.analyze.AnalyzedTableElements) NumberOfShards(io.crate.analyze.NumberOfShards) ClusteredBy(io.crate.sql.tree.ClusteredBy) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Optional(java.util.Optional) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Symbol(io.crate.expression.symbol.Symbol) TableParameter(io.crate.analyze.TableParameter) PartitionedBy(io.crate.sql.tree.PartitionedBy) ColumnIdent(io.crate.metadata.ColumnIdent) BoundCreateTable(io.crate.analyze.BoundCreateTable) ClusteredBy(io.crate.sql.tree.ClusteredBy) RelationName(io.crate.metadata.RelationName) Settings(org.elasticsearch.common.settings.Settings) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 5 with TableParameter

use of io.crate.analyze.TableParameter in project crate by crate.

the class CreateBlobTablePlan method buildSettings.

@VisibleForTesting
public static Settings buildSettings(CreateBlobTable<Symbol> createBlobTable, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row params, SubQueryResults subQueryResults, NumberOfShards numberOfShards) {
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, params, subQueryResults);
    CreateBlobTable<Object> blobTable = createBlobTable.map(eval);
    GenericProperties<Object> properties = blobTable.genericProperties();
    // apply default in case it is not specified in the properties,
    // if it is it will get overwritten afterwards.
    TableParameter tableParameter = new TableParameter();
    TablePropertiesAnalyzer.analyzeWithBoundValues(tableParameter, TableParameters.CREATE_BLOB_TABLE_PARAMETERS, properties, true);
    Settings.Builder builder = Settings.builder();
    builder.put(tableParameter.settings());
    builder.put(SETTING_INDEX_BLOBS_ENABLED.getKey(), true);
    int numShards;
    ClusteredBy<Object> clusteredBy = blobTable.clusteredBy();
    if (clusteredBy != null) {
        numShards = numberOfShards.fromClusteredByClause(clusteredBy);
    } else {
        numShards = numberOfShards.defaultNumberOfShards();
    }
    builder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards);
    return builder.build();
}
Also used : SETTING_INDEX_BLOBS_ENABLED(io.crate.blob.v2.BlobIndicesService.SETTING_INDEX_BLOBS_ENABLED) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) GenericProperties(io.crate.sql.tree.GenericProperties) Function(java.util.function.Function) DependencyCarrier(io.crate.planner.DependencyCarrier) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) OneRowActionListener(io.crate.execution.support.OneRowActionListener) BlobIndex.fullIndexName(io.crate.blob.v2.BlobIndex.fullIndexName) CreateBlobTable(io.crate.sql.tree.CreateBlobTable) TableParameter(io.crate.analyze.TableParameter) NodeContext(io.crate.metadata.NodeContext) TablePropertiesAnalyzer(io.crate.analyze.TablePropertiesAnalyzer) TableParameters(io.crate.analyze.TableParameters) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) RowConsumer(io.crate.data.RowConsumer) NumberOfShards(io.crate.analyze.NumberOfShards) ClusteredBy(io.crate.sql.tree.ClusteredBy) AnalyzedCreateBlobTable(io.crate.analyze.AnalyzedCreateBlobTable) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) TableParameter(io.crate.analyze.TableParameter) Settings(org.elasticsearch.common.settings.Settings) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Aggregations

TableParameter (io.crate.analyze.TableParameter)5 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)4 TableParameters (io.crate.analyze.TableParameters)4 Row (io.crate.data.Row)4 Row1 (io.crate.data.Row1)4 RowConsumer (io.crate.data.RowConsumer)4 OneRowActionListener (io.crate.execution.support.OneRowActionListener)4 Symbol (io.crate.expression.symbol.Symbol)4 DependencyCarrier (io.crate.planner.DependencyCarrier)4 Plan (io.crate.planner.Plan)4 PlannerContext (io.crate.planner.PlannerContext)4 SubQueryResults (io.crate.planner.operators.SubQueryResults)4 Function (java.util.function.Function)4 TablePropertiesAnalyzer (io.crate.analyze.TablePropertiesAnalyzer)3 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)3 NodeContext (io.crate.metadata.NodeContext)3 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)3 Settings (org.elasticsearch.common.settings.Settings)3 BoundAlterTable (io.crate.analyze.BoundAlterTable)2 NumberOfShards (io.crate.analyze.NumberOfShards)2