Search in sources :

Example 51 with InputColumn

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));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) FetchSource(io.crate.planner.node.fetch.FetchSource) Reference(io.crate.metadata.Reference) FetchReference(io.crate.expression.symbol.FetchReference) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) IntHashSet(com.carrotsearch.hppc.IntHashSet) RowN(io.crate.data.RowN) Bucket(io.crate.data.Bucket) ArrayBucket(io.crate.data.ArrayBucket) InputColumn(io.crate.expression.symbol.InputColumn) FetchReference(io.crate.expression.symbol.FetchReference) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 52 with InputColumn

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));
}
Also used : FilterProjection(io.crate.execution.dsl.projection.FilterProjection) InputColumn(io.crate.expression.symbol.InputColumn) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 53 with InputColumn

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());
}
Also used : FetchMarker(io.crate.expression.symbol.FetchMarker) InputColumn(io.crate.expression.symbol.InputColumn) FetchReference(io.crate.expression.symbol.FetchReference)

Example 54 with InputColumn

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;
}
Also used : Symbol(io.crate.expression.symbol.Symbol) SelectSymbol(io.crate.expression.symbol.SelectSymbol) InputColumn(io.crate.expression.symbol.InputColumn) ArrayList(java.util.ArrayList) Nullable(javax.annotation.Nullable)

Example 55 with InputColumn

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);
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) Assignments(io.crate.expression.symbol.Assignments) WhereClause(io.crate.analyze.WhereClause) UpdateProjection(io.crate.execution.dsl.projection.UpdateProjection) SysUpdateProjection(io.crate.execution.dsl.projection.SysUpdateProjection)

Aggregations

InputColumn (io.crate.expression.symbol.InputColumn)61 Test (org.junit.Test)47 Symbol (io.crate.expression.symbol.Symbol)38 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)25 Reference (io.crate.metadata.Reference)15 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)11 StreamInput (org.elasticsearch.common.io.stream.StreamInput)11 MergePhase (io.crate.execution.dsl.phases.MergePhase)10 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)10 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)9 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)9 Aggregation (io.crate.expression.symbol.Aggregation)9 Function (io.crate.expression.symbol.Function)9 ArrayList (java.util.ArrayList)9 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)8 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)7 Row (io.crate.data.Row)7 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)7 Projection (io.crate.execution.dsl.projection.Projection)7 CountAggregation (io.crate.execution.engine.aggregation.impl.CountAggregation)7