use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class CreateRepositoryPlan method createRequest.
@VisibleForTesting
public static PutRepositoryRequest createRequest(AnalyzedCreateRepository createRepository, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row parameters, SubQueryResults subQueryResults, RepositoryParamValidator repositoryParamValidator) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, subQueryResults);
var genericProperties = createRepository.properties().map(eval);
var settings = genericPropertiesToSettings(genericProperties, // supported settings for the repository type
repositoryParamValidator.settingsForType(createRepository.type()).all());
repositoryParamValidator.validate(createRepository.type(), createRepository.properties(), settings);
PutRepositoryRequest request = new PutRepositoryRequest(createRepository.name());
request.type(createRepository.type());
request.settings(settings);
return request;
}
use of io.crate.planner.operators.SubQueryResults 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);
}
use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class DropViewPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
DropViewRequest request = new DropViewRequest(dropView.views(), dropView.ifExists());
Function<DropViewResponse, Row> responseToRow = resp -> {
if (dropView.ifExists() || resp.missing().isEmpty()) {
return new Row1((long) dropView.views().size() - resp.missing().size());
}
throw new RelationsUnknown(resp.missing());
};
dependencies.dropViewAction().execute(request, new OneRowActionListener<>(consumer, responseToRow));
}
use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class AlterTablePlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
BoundAlterTable stmt = bind(alterTable, plannerContext.transactionContext(), dependencies.nodeContext(), params, subQueryResults);
dependencies.alterTableOperation().executeAlterTable(stmt).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
use of io.crate.planner.operators.SubQueryResults 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();
}
Aggregations