use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class RefreshTablePlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
if (analysis.tables().isEmpty()) {
consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
return;
}
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, parameters, subQueryResults);
ArrayList<String> toRefresh = new ArrayList<>();
for (Map.Entry<Table<Symbol>, DocTableInfo> table : analysis.tables().entrySet()) {
var tableInfo = table.getValue();
var tableSymbol = table.getKey();
if (tableSymbol.partitionProperties().isEmpty()) {
toRefresh.addAll(Arrays.asList(tableInfo.concreteOpenIndices()));
} else {
var partitionName = toPartitionName(tableInfo, Lists2.map(tableSymbol.partitionProperties(), p -> p.map(eval)));
if (!tableInfo.partitions().contains(partitionName)) {
throw new PartitionUnknownException(partitionName);
}
toRefresh.add(partitionName.asIndexName());
}
}
RefreshRequest request = new RefreshRequest(toRefresh.toArray(String[]::new));
request.indicesOptions(IndicesOptions.lenientExpandOpen());
var transportRefreshAction = dependencies.transportActionProvider().transportRefreshAction();
transportRefreshAction.execute(request, new OneRowActionListener<>(consumer, response -> new Row1(toRefresh.isEmpty() ? -1L : (long) toRefresh.size())));
}
use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class CopyToPlan method bind.
@VisibleForTesting
public static BoundCopyTo bind(AnalyzedCopyTo copyTo, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row parameters, SubQueryResults subQueryResults) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, subQueryResults);
DocTableInfo table = (DocTableInfo) copyTo.tableInfo();
List<String> partitions = resolvePartitions(Lists2.map(copyTo.table().partitionProperties(), x -> x.map(eval)), table);
List<Symbol> outputs = new ArrayList<>();
Map<ColumnIdent, Symbol> overwrites = null;
boolean columnsDefined = false;
final List<String> outputNames = new ArrayList<>(copyTo.columns().size());
if (!copyTo.columns().isEmpty()) {
// TODO: remove outputNames?
for (Symbol symbol : copyTo.columns()) {
assert symbol instanceof Reference : "Only references are expected here";
RefVisitor.visitRefs(symbol, r -> outputNames.add(r.column().sqlFqn()));
outputs.add(DocReferences.toSourceLookup(symbol));
}
columnsDefined = true;
} else {
Reference sourceRef;
if (table.isPartitioned() && partitions.isEmpty()) {
// table is partitioned, insert partitioned columns into the output
overwrites = new HashMap<>();
for (Reference reference : table.partitionedByColumns()) {
if (!(reference instanceof GeneratedReference)) {
overwrites.put(reference.column(), reference);
}
}
if (overwrites.size() > 0) {
sourceRef = table.getReference(DocSysColumns.DOC);
} else {
sourceRef = table.getReference(DocSysColumns.RAW);
}
} else {
sourceRef = table.getReference(DocSysColumns.RAW);
}
outputs = List.of(sourceRef);
}
Settings settings = genericPropertiesToSettings(copyTo.properties().map(eval));
WriterProjection.CompressionType compressionType = settingAsEnum(WriterProjection.CompressionType.class, COMPRESSION_SETTING.get(settings));
WriterProjection.OutputFormat outputFormat = settingAsEnum(WriterProjection.OutputFormat.class, OUTPUT_FORMAT_SETTING.get(settings));
if (!columnsDefined && outputFormat == WriterProjection.OutputFormat.JSON_ARRAY) {
throw new UnsupportedFeatureException("Output format not supported without specifying columns.");
}
WhereClause whereClause = new WhereClause(copyTo.whereClause(), partitions, Collections.emptySet());
return new BoundCopyTo(outputs, table, whereClause, Literal.of(DataTypes.STRING.sanitizeValue(eval.apply(copyTo.uri()))), compressionType, outputFormat, outputNames.isEmpty() ? null : outputNames, columnsDefined, overwrites, settings);
}
use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class SetSessionPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, params, subQueryResults);
SessionContext sessionContext = plannerContext.transactionContext().sessionContext();
Assignment<Symbol> assignment = settings.get(0);
String settingName = eval.apply(assignment.columnName()).toString();
validateSetting(settingName);
SessionSetting<?> sessionSetting = sessionSettingRegistry.settings().get(settingName);
if (sessionSetting == null) {
LOGGER.info("SET SESSION STATEMENT WILL BE IGNORED: {}", settingName);
} else {
sessionSetting.apply(sessionContext, assignment.expressions(), eval);
}
consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
}
use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class MultiPhaseExecutor method execute.
public static CompletableFuture<SubQueryResults> execute(Map<LogicalPlan, SelectSymbol> dependencies, DependencyCarrier executor, PlannerContext plannerContext, Row params) {
List<CompletableFuture<?>> dependencyFutures = new ArrayList<>(dependencies.size());
IdentityHashMap<SelectSymbol, Object> valueBySubQuery = new IdentityHashMap<>();
for (Map.Entry<LogicalPlan, SelectSymbol> entry : dependencies.entrySet()) {
LogicalPlan depPlan = entry.getKey();
SelectSymbol selectSymbol = entry.getValue();
CollectingRowConsumer<?, ?> rowConsumer = getConsumer(selectSymbol.getResultType());
depPlan.execute(executor, PlannerContext.forSubPlan(plannerContext), rowConsumer, params, SubQueryResults.EMPTY);
dependencyFutures.add(rowConsumer.completionFuture().thenAccept(val -> {
synchronized (valueBySubQuery) {
valueBySubQuery.put(selectSymbol, val);
}
}));
}
return CompletableFuture.allOf(dependencyFutures.toArray(new CompletableFuture[0])).thenApply(ignored -> new SubQueryResults(valueBySubQuery));
}
use of io.crate.planner.operators.SubQueryResults in project crate by crate.
the class CreateViewPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
User owner = createViewStmt.owner();
String formattedQuery = SqlFormatter.formatSql(createViewStmt.query(), makeExpressions(params));
ensureFormattedQueryCanStillBeAnalyzed(createViewStmt.name(), dependencies.nodeContext(), dependencies.schemas(), plannerContext.transactionContext(), formattedQuery, createViewStmt.replaceExisting());
CreateViewRequest request = new CreateViewRequest(createViewStmt.name(), formattedQuery, createViewStmt.replaceExisting(), owner == null ? null : owner.name());
dependencies.createViewAction().execute(request, new OneRowActionListener<>(consumer, resp -> {
if (resp.alreadyExistsFailure()) {
throw new RelationAlreadyExists(createViewStmt.name());
}
return new Row1(1L);
}));
}
Aggregations