Search in sources :

Example 26 with InputColumn

use of io.crate.expression.symbol.InputColumn in project crate by crate.

the class FetchRows method create.

public static FetchRows create(TransactionContext txnCtx, NodeContext nodeCtx, Map<RelationName, FetchSource> fetchSourceByTable, List<Symbol> outputSymbols) {
    IntArrayList fetchIdPositions = new IntArrayList();
    ArrayList<Object[]> nullRows = new ArrayList<>();
    IntObjectHashMap<UnsafeArrayRow> fetchedRows = new IntObjectHashMap<>();
    for (var fetchSource : fetchSourceByTable.values()) {
        Object[] nullRow = new Object[fetchSource.references().size()];
        for (InputColumn ic : fetchSource.fetchIdCols()) {
            fetchIdPositions.add(ic.index());
            nullRows.add(nullRow);
            fetchedRows.put(ic.index(), new UnsafeArrayRow());
        }
    }
    final UnsafeArrayRow inputRow = new UnsafeArrayRow();
    var visitor = new BaseImplementationSymbolVisitor<Void>(txnCtx, nodeCtx) {

        @Override
        public Input<?> visitInputColumn(final InputColumn inputColumn, final Void context) {
            final int idx = inputColumn.index();
            return () -> inputRow.get(idx);
        }

        @Override
        public Input<?> visitFetchReference(final FetchReference fetchReference, final Void context) {
            var ref = fetchReference.ref();
            UnsafeArrayRow row = fetchedRows.get(fetchReference.fetchId().index());
            int posInFetchedRow = fetchSourceByTable.get(ref.ident().tableIdent()).references().indexOf(ref);
            return () -> row.get(posInFetchedRow);
        }
    };
    List<Input<?>> outputExpressions = Lists2.map(outputSymbols, x -> x.accept(visitor, null));
    return new FetchRows(fetchIdPositions, outputExpressions, inputRow, fetchedRows, nullRows);
}
Also used : IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) BaseImplementationSymbolVisitor(io.crate.expression.BaseImplementationSymbolVisitor) Input(io.crate.data.Input) UnsafeArrayRow(io.crate.data.UnsafeArrayRow) InputColumn(io.crate.expression.symbol.InputColumn) FetchReference(io.crate.expression.symbol.FetchReference) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 27 with InputColumn

use of io.crate.expression.symbol.InputColumn in project crate by crate.

the class InsertAnalyzerTest method testFromQueryWithOnDuplicateKeyValues.

@Test
public void testFromQueryWithOnDuplicateKeyValues() throws Exception {
    var insert = "insert into users (id, name) (select id, name from users) " + "on conflict (id) do update set name = substr(excluded.name, 1, 1)";
    AnalyzedInsertStatement statement = e.analyze(insert);
    Assert.assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
    for (Map.Entry<Reference, Symbol> entry : statement.onDuplicateKeyAssignments().entrySet()) {
        assertThat(entry.getKey(), isReference("name"));
        assertThat(entry.getValue(), isFunction(SubstrFunction.NAME));
        Function function = (Function) entry.getValue();
        assertThat(function.arguments().get(0), instanceOf(InputColumn.class));
        InputColumn inputColumn = (InputColumn) function.arguments().get(0);
        assertThat(inputColumn.index(), is(1));
        assertThat(inputColumn.valueType(), instanceOf(StringType.class));
    }
}
Also used : SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) Function(io.crate.expression.symbol.Function) SubstrFunction(io.crate.expression.scalar.SubstrFunction) StringType(io.crate.types.StringType) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) SymbolMatchers.isInputColumn(io.crate.testing.SymbolMatchers.isInputColumn) Map(java.util.Map) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 28 with InputColumn

use of io.crate.expression.symbol.InputColumn in project crate by crate.

the class RowShardResolverTest method testPrimaryKeyAndRouting.

@Test
public void testPrimaryKeyAndRouting() {
    List<Symbol> primaryKeySymbols = List.of(new InputColumn(0), new InputColumn(1));
    RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(ci("id"), ci("foo")), primaryKeySymbols, ci("foo"), new InputColumn(1));
    rowShardResolver.setNextRow(row(1, "hoschi"));
    // compound encoded id, special routing
    assertThat(rowShardResolver.id(), is("AgZob3NjaGkBMQ=="));
    assertThat(rowShardResolver.routing(), is("hoschi"));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) Test(org.junit.Test)

Example 29 with InputColumn

use of io.crate.expression.symbol.InputColumn in project crate by crate.

the class RowShardResolverTest method testNoPrimaryKeyButRouting.

@Test
public void testNoPrimaryKeyButRouting() {
    RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(), List.of(), ID_IDENT, new InputColumn(1));
    rowShardResolver.setNextRow(row(1, "hoschi"));
    // auto-generated id, special routing
    assertNotNull(rowShardResolver.id());
    assertThat(rowShardResolver.routing(), is("hoschi"));
}
Also used : InputColumn(io.crate.expression.symbol.InputColumn) Test(org.junit.Test)

Example 30 with InputColumn

use of io.crate.expression.symbol.InputColumn in project crate by crate.

the class RowShardResolverTest method testIdPrimaryKeyNull.

@Test
public void testIdPrimaryKeyNull() {
    List<Symbol> primaryKeySymbols = List.of(new InputColumn(2));
    RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(ID_IDENT), primaryKeySymbols, null, new InputColumn(1));
    rowShardResolver.setNextRow(row(1, "hoschi", null));
    // generated _id, special routing
    assertNotNull(rowShardResolver.id());
    assertThat(rowShardResolver.routing(), is("hoschi"));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) Test(org.junit.Test)

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