Search in sources :

Example 56 with InputColumn

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);
    }
}
Also used : SysUpdateProjection(io.crate.execution.dsl.projection.SysUpdateProjection) Reference(io.crate.metadata.Reference) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) WhereClause(io.crate.analyze.WhereClause) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo)

Example 57 with InputColumn

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);
}
Also used : Function(io.crate.expression.symbol.Function) 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 58 with InputColumn

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())));
}
Also used : Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) ReferenceIdent(io.crate.metadata.ReferenceIdent) ColumnIdent(io.crate.metadata.ColumnIdent) InputColumn(io.crate.expression.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) RelationName(io.crate.metadata.RelationName) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 59 with InputColumn

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

Example 60 with InputColumn

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));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) CollectExpression(io.crate.execution.engine.collect.CollectExpression) RowN(io.crate.data.RowN) Input(io.crate.data.Input) InputColumn(io.crate.expression.symbol.InputColumn) Row(io.crate.data.Row) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) 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