Search in sources :

Example 6 with InputColumn

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

the class Comparators method createComparator.

@Nullable
public static <T extends CollectExpression<Row, ?>> Comparator<Object[]> createComparator(Supplier<InputFactory.Context<T>> createInputFactoryCtx, @Nullable OrderBy orderBy) {
    if (orderBy == null) {
        return null;
    }
    List<Symbol> orderBySymbols = orderBy.orderBySymbols();
    int[] positions = new int[orderBySymbols.size()];
    for (int i = 0; i < orderBySymbols.size(); i++) {
        Symbol symbol = orderBySymbols.get(i);
        if (symbol instanceof InputColumn) {
            positions[i] = ((InputColumn) symbol).index();
        } else {
            return createComparatorWithEval(createInputFactoryCtx, orderBy);
        }
    }
    return arrayOrdering(positions, orderBy.reverseFlags(), orderBy.nullsFirst());
}
Also used : Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) Nullable(javax.annotation.Nullable)

Example 7 with InputColumn

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

the class UpdateProjectionTest method testEquals.

@Test
public void testEquals() throws Exception {
    UpdateProjection u1 = new UpdateProjection(Literal.of(1), new String[] { "foo" }, new Symbol[] { Literal.of(1) }, new Symbol[] { new InputColumn(0, DataTypes.STRING) }, null, null);
    UpdateProjection u2 = new UpdateProjection(Literal.of(1), new String[] { "foo" }, new Symbol[] { Literal.of(1) }, new Symbol[] { new InputColumn(0, DataTypes.STRING) }, null, null);
    assertThat(u2.equals(u1), is(true));
    assertThat(u1.equals(u2), is(true));
    assertThat(u1.hashCode(), is(u2.hashCode()));
}
Also used : InputColumn(io.crate.expression.symbol.InputColumn) Test(org.junit.Test)

Example 8 with InputColumn

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

the class UpdateProjectionTest method test_serialization.

@Test
public void test_serialization() throws Exception {
    UpdateProjection expected = new UpdateProjection(Literal.of(1), new String[] { "foo" }, new Symbol[] { Literal.of(1) }, new Symbol[] { new InputColumn(0, DataTypes.STRING) }, new Symbol[] { Literal.of(1) }, null);
    BytesStreamOutput out = new BytesStreamOutput();
    expected.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    UpdateProjection result = new UpdateProjection(in);
    assertThat(result, equalTo(expected));
}
Also used : InputColumn(io.crate.expression.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 9 with InputColumn

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

the class UpdateProjectionTest method test_serialization_backward_compatibility.

@Test
public void test_serialization_backward_compatibility() throws Exception {
    UpdateProjection expected = new UpdateProjection(Literal.of(1), new String[] { "foo" }, new Symbol[] { Literal.of(1) }, new Symbol[] {}, new Symbol[] { Literal.of(1) }, null);
    BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(Version.V_4_0_0);
    expected.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    in.setVersion(Version.V_4_0_0);
    UpdateProjection result = new UpdateProjection(in);
    assertThat(result.uidSymbol, equalTo(expected.uidSymbol));
    assertThat(result.assignments(), equalTo(expected.assignments()));
    assertThat(result.assignmentsColumns(), equalTo(expected.assignmentsColumns()));
    assertThat(result.requiredVersion(), equalTo(expected.requiredVersion()));
    // Pre 4.1 versions of UpdateProjection have default output fields set to a long representing
    // a count which need to set when reading from an pre 4.1 node.
    assertThat(result.outputs(), equalTo(List.of(new InputColumn(0, DataTypes.LONG))));
    assertThat(result.returnValues(), equalTo(null));
}
Also used : InputColumn(io.crate.expression.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 10 with InputColumn

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

the class WriterProjectionTest method testStreamingBefore4_8_0.

@Test
public void testStreamingBefore4_8_0() throws Exception {
    WriterProjection actualInput = new WriterProjection(List.of(new InputColumn(1)), Literal.of("/foo.json"), WriterProjection.CompressionType.GZIP, MapBuilder.<ColumnIdent, Symbol>newMapBuilder().put(new ColumnIdent("partitionColumn"), Literal.of(1)).map(), List.of("foo"), WriterProjection.OutputFormat.JSON_OBJECT, Settings.builder().put("protocol", "dummyHTTPS").build());
    WriterProjection expected = new WriterProjection(List.of(new InputColumn(1)), Literal.of("/foo.json"), WriterProjection.CompressionType.GZIP, MapBuilder.<ColumnIdent, Symbol>newMapBuilder().put(new ColumnIdent("partitionColumn"), Literal.of(1)).map(), List.of("foo"), WriterProjection.OutputFormat.JSON_OBJECT, Settings.EMPTY);
    BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(Version.V_4_7_0);
    Projection.toStream(actualInput, out);
    StreamInput in = out.bytes().streamInput();
    in.setVersion(Version.V_4_7_0);
    WriterProjection actual = (WriterProjection) Projection.fromStream(in);
    assertEquals(expected, actual);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) InputColumn(io.crate.expression.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) 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