use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class FetchRowsTest method test_fetch_rows_can_map_inputs_and_buckets_to_outputs.
@Test
public void test_fetch_rows_can_map_inputs_and_buckets_to_outputs() throws Exception {
var e = SQLExecutor.builder(clusterService).addTable("create table t1 (x text)").addTable("create table t2 (y text, z int)").build();
var t1 = e.resolveTableInfo("t1");
var x = (Reference) e.asSymbol("x");
var fetchSource1 = new FetchSource();
fetchSource1.addFetchIdColumn(new InputColumn(0, DataTypes.LONG));
fetchSource1.addRefToFetch(x);
var t2 = e.resolveTableInfo("t2");
var y = (Reference) e.asSymbol("y");
var fetchSource2 = new FetchSource();
fetchSource2.addFetchIdColumn(new InputColumn(1, DataTypes.LONG));
fetchSource2.addRefToFetch(y);
var fetchSources = Map.of(t1.ident(), fetchSource1, t2.ident(), fetchSource2);
var fetchRows = FetchRows.create(CoordinatorTxnCtx.systemTransactionContext(), createNodeContext(), fetchSources, List.of(new FetchReference(new InputColumn(0, DataTypes.LONG), x), new FetchReference(new InputColumn(1, DataTypes.LONG), y), new InputColumn(2, DataTypes.INTEGER)));
long fetchIdRel1 = FetchId.encode(1, 1);
long fetchIdRel2 = FetchId.encode(2, 1);
var readerBuckets = new ReaderBuckets(fetchRows, reader -> reader == 1 ? fetchSource1 : fetchSource2, cells -> 0, RamAccounting.NO_ACCOUNTING);
IntHashSet readerIds = new IntHashSet(2);
readerIds.add(1);
readerIds.add(2);
readerBuckets.add(new RowN(fetchIdRel1, fetchIdRel2, 42));
readerBuckets.generateToFetch(readerIds);
IntObjectHashMap<Bucket> results = new IntObjectHashMap<>();
results.put(1, new ArrayBucket($$($("Arthur"))));
results.put(2, new ArrayBucket($$($("Trillian"))));
var it = readerBuckets.getOutputRows(List.of(results));
assertThat(it.hasNext(), is(true));
var outputRow = it.next();
assertThat(outputRow.get(0), is("Arthur"));
assertThat(outputRow.get(1), is("Trillian"));
assertThat(outputRow.get(2), is(42));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class ProjectorsTest method testProjectionsWithCorrectGranularityAreApplied.
@Test
public void testProjectionsWithCorrectGranularityAreApplied() {
GroupProjection groupProjection = new GroupProjection(new ArrayList<>(), new ArrayList<>(), AggregateMode.ITER_FINAL, RowGranularity.SHARD);
FilterProjection filterProjection = new FilterProjection(new InputColumn(0), Collections.emptyList());
filterProjection.requiredGranularity(RowGranularity.DOC);
Projectors projectors = new Projectors(Arrays.asList(filterProjection, groupProjection), UUID.randomUUID(), CoordinatorTxnCtx.systemTransactionContext(), RamAccounting.NO_ACCOUNTING, memoryManager, projectorFactory);
assertThat(projectors.providesIndependentScroll(), is(true));
assertThat(projectors.projectors.size(), is(1));
assertThat(projectors.projectors.get(0), instanceOf(GroupingProjector.class));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class InputColumns method visitFetchStub.
@Override
public Symbol visitFetchStub(FetchStub fetchStub, SourceSymbols sourceSymbols) {
FetchMarker fetchMarker = fetchStub.fetchMarker();
InputColumn fetchId = sourceSymbols.inputs.get(fetchMarker);
if (fetchId == null) {
throw new IllegalArgumentException("Could not find fetchMarker " + fetchMarker + " in sources: " + sourceSymbols);
}
return new FetchReference(fetchId, fetchStub.ref());
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class EvalProjection method castValues.
@Nullable
public static EvalProjection castValues(List<DataType<?>> targetTypes, List<Symbol> sources) {
ArrayList<Symbol> casts = new ArrayList<>(targetTypes.size());
boolean requiresCasts = false;
for (int i = 0; i < sources.size(); i++) {
Symbol source = sources.get(i);
DataType<?> targetType = targetTypes.get(i);
InputColumn inputColumn = new InputColumn(i, source.valueType());
if (targetType.id() == DataTypes.UNDEFINED.id() || targetType.equals(source.valueType())) {
casts.add(inputColumn);
} else {
requiresCasts = true;
casts.add(inputColumn.cast(targetType));
}
}
return requiresCasts ? new EvalProjection(casts) : null;
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class UpdatePlanner method updateByQuery.
private static ExecutionPlan updateByQuery(PlannerContext plannerCtx, DocTableRelation table, Map<Reference, Symbol> assignmentByTargetCol, WhereClauseOptimizer.DetailedQuery detailedQuery, Row params, SubQueryResults subQueryResults, @Nullable List<Symbol> returnValues) {
DocTableInfo tableInfo = table.tableInfo();
Reference idReference = requireNonNull(tableInfo.getReference(DocSysColumns.ID), "Table must have a _id column");
Assignments assignments = Assignments.convert(assignmentByTargetCol, plannerCtx.nodeContext());
Symbol[] assignmentSources = assignments.bindSources(tableInfo, params, subQueryResults);
Symbol[] outputSymbols;
if (returnValues == null) {
// When there are no return values, set the output to a long representing the count of updated rows
outputSymbols = new Symbol[] { new InputColumn(0, DataTypes.LONG) };
} else {
outputSymbols = new Symbol[returnValues.size()];
for (int i = 0; i < returnValues.size(); i++) {
outputSymbols[i] = new InputColumn(i, returnValues.get(i).valueType());
}
}
UpdateProjection updateProjection = new UpdateProjection(new InputColumn(0, idReference.valueType()), assignments.targetNames(), assignmentSources, outputSymbols, returnValues == null ? null : returnValues.toArray(new Symbol[0]), null);
WhereClause where = detailedQuery.toBoundWhereClause(tableInfo, params, subQueryResults, plannerCtx.transactionContext(), plannerCtx.nodeContext());
if (where.hasVersions()) {
throw VersioningValidationException.versionInvalidUsage();
} else if (where.hasSeqNoAndPrimaryTerm()) {
throw VersioningValidationException.seqNoAndPrimaryTermUsage();
}
if (returnValues == null) {
return createCollectAndMerge(plannerCtx, tableInfo, idReference, updateProjection, where, 1, 1, MergeCountProjection.INSTANCE);
} else {
return createCollectAndMerge(plannerCtx, tableInfo, idReference, updateProjection, where, updateProjection.outputs().size(), -1);
}
}
Aggregations