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());
}
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()));
}
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));
}
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));
}
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);
}
Aggregations