Search in sources :

Example 31 with InputColumn

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

the class RowShardResolverTest method testMultiPrimaryKeyNullException.

@Test
public void testMultiPrimaryKeyNullException() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("A primary key value must not be NULL");
    List<Symbol> primaryKeySymbols = List.of(new InputColumn(1), new InputColumn(0));
    RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(ci("id"), ci("foo")), primaryKeySymbols, null, new InputColumn(1));
    rowShardResolver.setNextRow(row(1, null));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) Test(org.junit.Test)

Example 32 with InputColumn

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

the class RowShardResolverTest method testMultipleRows.

@Test
public void testMultipleRows() {
    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"));
    assertThat(rowShardResolver.id(), is("AgZob3NjaGkBMQ=="));
    assertThat(rowShardResolver.routing(), is("hoschi"));
    rowShardResolver.setNextRow(row(2, "galoschi"));
    assertThat(rowShardResolver.id(), is("AghnYWxvc2NoaQEy"));
    assertThat(rowShardResolver.routing(), is("galoschi"));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) Test(org.junit.Test)

Example 33 with InputColumn

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

the class RowShardResolverTest method testPrimaryKeyNullException.

@Test
public void testPrimaryKeyNullException() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("A primary key value must not be NULL");
    List<Symbol> primaryKeySymbols = List.of(new InputColumn(0));
    RowShardResolver rowShardResolver = new RowShardResolver(txnCtx, nodeCtx, List.of(ci("id")), primaryKeySymbols, null, null);
    rowShardResolver.setNextRow(row(new Object[] { null }));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) Test(org.junit.Test)

Example 34 with InputColumn

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

the class RowShardResolverTest method testPrimaryKeyNoRouting.

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

Example 35 with InputColumn

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

the class ColumnIndexWriterProjectionTest method testTargetColumnRefsAndSymbolsAreCorrectAfterExclusionOfPartitionColumns.

@Test
public void testTargetColumnRefsAndSymbolsAreCorrectAfterExclusionOfPartitionColumns() {
    /*
         *  pk:             [ymd, domain, area, isp]
         *  partitioned by: [ymd, isp]
         *  insert into t   (ymd, domain, area, isp, h) select ...
         *
         *  We don't write PartitionedBy columns, so they're excluded from the allTargetColumns:
         *
         *  expected targetRefs:      [ domain, area, h ]
         *  expected column symbols:  [ ic1,   ic2, ic4 ]
         */
    ColumnIdent ymd = new ColumnIdent("ymd");
    ColumnIdent domain = new ColumnIdent("domain");
    ColumnIdent area = new ColumnIdent("area");
    ColumnIdent isp = new ColumnIdent("isp");
    ColumnIdent h = new ColumnIdent("h");
    Reference ymdRef = partitionRef(ymd, DataTypes.STRING);
    Reference domainRef = ref(domain, DataTypes.STRING);
    Reference areaRef = ref(area, DataTypes.STRING);
    Reference ispRef = partitionRef(isp, DataTypes.STRING);
    Reference hRef = ref(h, DataTypes.INTEGER);
    List<ColumnIdent> primaryKeys = Arrays.asList(ymd, domain, area, isp);
    List<Reference> targetColumns = Arrays.asList(ymdRef, domainRef, areaRef, ispRef, hRef);
    List<Reference> targetColumnsExclPartitionColumns = Arrays.asList(domainRef, areaRef, hRef);
    InputColumns.SourceSymbols targetColsCtx = new InputColumns.SourceSymbols(targetColumns);
    List<Symbol> primaryKeySymbols = InputColumns.create(Arrays.asList(ymdRef, domainRef, areaRef, ispRef), targetColsCtx);
    List<Symbol> partitionedBySymbols = InputColumns.create(Arrays.asList(ymdRef, ispRef), targetColsCtx);
    List<Symbol> columnSymbols = InputColumns.create(targetColumnsExclPartitionColumns, targetColsCtx);
    ColumnIndexWriterProjection projection = new ColumnIndexWriterProjection(relationName, null, primaryKeys, targetColumns, targetColumnsExclPartitionColumns, columnSymbols, false, null, primaryKeySymbols, partitionedBySymbols, null, null, Settings.EMPTY, true, List.of(), null);
    assertThat(projection.columnReferencesExclPartition(), is(Arrays.asList(domainRef, areaRef, hRef)));
    assertThat(projection.columnSymbolsExclPartition(), is(Arrays.asList(new InputColumn(1, DataTypes.STRING), new InputColumn(2, DataTypes.STRING), new InputColumn(4, DataTypes.INTEGER))));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) Reference(io.crate.metadata.Reference) 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