use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class UpdatePlanner method sysUpdate.
private static ExecutionPlan sysUpdate(PlannerContext plannerContext, TableRelation table, Map<Reference, Symbol> assignmentByTargetCol, Symbol query, Row params, SubQueryResults subQueryResults, @Nullable List<Symbol> returnValues) {
TableInfo tableInfo = table.tableInfo();
Reference idReference = requireNonNull(tableInfo.getReference(DocSysColumns.ID), "Table must have a _id column");
Symbol[] outputSymbols;
if (returnValues == null) {
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());
}
}
SysUpdateProjection updateProjection = new SysUpdateProjection(new InputColumn(0, idReference.valueType()), assignmentByTargetCol, outputSymbols, returnValues == null ? null : returnValues.toArray(new Symbol[0]));
WhereClause where = new WhereClause(SubQueryAndParamBinder.convert(query, params, subQueryResults));
if (returnValues == null) {
return createCollectAndMerge(plannerContext, tableInfo, idReference, updateProjection, where, 1, 1, MergeCountProjection.INSTANCE);
} else {
return createCollectAndMerge(plannerContext, tableInfo, idReference, updateProjection, where, updateProjection.outputs().size(), -1);
}
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class FilterProjectionTest method testStreaming.
@Test
public void testStreaming() throws Exception {
var eqFunction = new Function(EqOperator.SIGNATURE, List.of(new InputColumn(0, DataTypes.INTEGER), new InputColumn(1, DataTypes.INTEGER)), EqOperator.RETURN_TYPE);
FilterProjection p = new FilterProjection(eqFunction, Collections.singletonList(new InputColumn(0)));
p.requiredGranularity(RowGranularity.SHARD);
BytesStreamOutput out = new BytesStreamOutput();
Projection.toStream(p, out);
StreamInput in = out.bytes().streamInput();
FilterProjection p2 = (FilterProjection) Projection.fromStream(in);
assertEquals(p, p2);
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class SourceIndexWriterProjectionSerializationTest method testSerializationFailFast.
@Test
public void testSerializationFailFast() throws IOException {
RelationName relationName = new RelationName("doc", "test");
ReferenceIdent referenceIdent = new ReferenceIdent(relationName, "object_column");
Reference reference = new Reference(referenceIdent, RowGranularity.DOC, new ArrayType<>(DataTypes.UNTYPED_OBJECT), ColumnPolicy.STRICT, Reference.IndexType.FULLTEXT, false, true, 0, Literal.of(Map.of("f", 10)));
String partitionIdent = "pIdent";
InputColumn inputColumn = new InputColumn(123);
List<ColumnIdent> primaryKeys = List.of(new ColumnIdent("colIdent"));
List<Symbol> partitionedBySymbols = List.of(reference);
ColumnIdent clusteredByColumn = new ColumnIdent("col1");
Settings settings = Settings.builder().put("fail_fast", true).build();
// fail_fast property set to true
SourceIndexWriterProjection expected = new SourceIndexWriterProjection(relationName, partitionIdent, reference, inputColumn, primaryKeys, partitionedBySymbols, clusteredByColumn, settings, null, null, List.of(), null, AbstractIndexWriterProjection.OUTPUTS, false);
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(Version.V_4_6_0);
expected.writeTo(out);
StreamInput in = out.bytes().streamInput();
in.setVersion(Version.V_4_6_0);
assertThat(new SourceIndexWriterProjection(in).failFast(), is((!expected.failFast())));
BytesStreamOutput out2 = new BytesStreamOutput();
out2.setVersion(Version.V_4_7_0);
expected.writeTo(out2);
StreamInput in2 = out2.bytes().streamInput();
in2.setVersion(Version.V_4_7_0);
assertThat(new SourceIndexWriterProjection(in2).failFast(), is((expected.failFast())));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class WriterProjectionTest method testStreaming.
@Test
public void testStreaming() throws Exception {
WriterProjection p = 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", "http").build());
BytesStreamOutput out = new BytesStreamOutput();
Projection.toStream(p, out);
StreamInput in = out.bytes().streamInput();
WriterProjection p2 = (WriterProjection) Projection.fromStream(in);
assertEquals(p, p2);
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class InputFactoryTest method testProcessGroupByProjectionSymbols.
@Test
public void testProcessGroupByProjectionSymbols() throws Exception {
// select x, y * 2 ... group by x, y * 2
// keys: [ in(0), in(1) + 10 ]
List<Symbol> keys = Arrays.asList(new InputColumn(0, DataTypes.LONG), add);
InputFactory.Context<CollectExpression<Row, ?>> ctx = factory.ctxForAggregations(txnCtx);
ctx.add(keys);
ArrayList<CollectExpression<Row, ?>> expressions = new ArrayList<>(ctx.expressions());
assertThat(expressions.size(), is(2));
// keyExpressions: [ in0, in1 ]
RowN row = new RowN(1L, 2L);
for (CollectExpression<Row, ?> expression : expressions) {
expression.setNextRow(row);
}
assertThat(expressions.get(0).value(), is(1L));
// raw input value
assertThat(expressions.get(1).value(), is(2L));
// inputs: [ x, add ]
List<Input<?>> inputs = ctx.topLevelInputs();
assertThat(inputs.size(), is(2));
assertThat(inputs.get(0).value(), is(1L));
// + 10
assertThat(inputs.get(1).value(), is(12));
}
Aggregations