Search in sources :

Example 6 with InputColumn

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

the class FetchBatchAccumulatorTest method buildFetchProjectorContext.

private FetchProjectorContext buildFetchProjectorContext() {
    Map<String, IntSet> nodeToReaderIds = new HashMap<>(2);
    IntSet nodeReadersNodeOne = new IntHashSet();
    nodeReadersNodeOne.add(0);
    IntSet nodeReadersNodeTwo = new IntHashSet();
    nodeReadersNodeTwo.add(2);
    nodeToReaderIds.put("nodeOne", nodeReadersNodeOne);
    nodeToReaderIds.put("nodeTwo", nodeReadersNodeTwo);
    TreeMap<Integer, String> readerIndices = new TreeMap<>();
    readerIndices.put(0, "t1");
    Map<String, TableIdent> indexToTable = new HashMap<>(1);
    indexToTable.put("t1", USER_TABLE_IDENT);
    Map<TableIdent, FetchSource> tableToFetchSource = new HashMap<>(2);
    FetchSource fetchSource = new FetchSource(Collections.emptyList(), Collections.singletonList(new InputColumn(0)), Collections.singletonList(ID));
    tableToFetchSource.put(USER_TABLE_IDENT, fetchSource);
    return new FetchProjectorContext(tableToFetchSource, nodeToReaderIds, readerIndices, indexToTable);
}
Also used : FetchSource(io.crate.planner.node.fetch.FetchSource) TableIdent(io.crate.metadata.TableIdent) InputColumn(io.crate.analyze.symbol.InputColumn)

Example 7 with InputColumn

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

the class DeleteStatementPlanner method collectWithDeleteProjection.

private static Plan collectWithDeleteProjection(TableInfo tableInfo, WhereClause whereClause, Planner.Context plannerContext) {
    // for delete, we always need to collect the `_uid`
    Reference idReference = tableInfo.getReference(DocSysColumns.ID);
    DeleteProjection deleteProjection = new DeleteProjection(new InputColumn(0, DataTypes.STRING));
    Routing routing = plannerContext.allocateRouting(tableInfo, whereClause, Preference.PRIMARY.type());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), ImmutableList.of(idReference), ImmutableList.of(deleteProjection), whereClause, DistributionInfo.DEFAULT_BROADCAST);
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, 1, 1, null);
    return Merge.ensureOnHandler(collect, plannerContext, Collections.singletonList(MergeCountProjection.INSTANCE));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) DeleteProjection(io.crate.planner.projection.DeleteProjection) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 8 with InputColumn

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

the class UpdateConsumer method upsertByQuery.

private static Plan upsertByQuery(UpdateAnalyzedStatement.NestedAnalyzedStatement nestedAnalysis, Planner.Context plannerContext, DocTableInfo tableInfo, WhereClause whereClause) {
    Symbol versionSymbol = null;
    if (whereClause.hasVersions()) {
        versionSymbol = VersionRewriter.get(whereClause.query());
        whereClause = new WhereClause(whereClause.query(), whereClause.docKeys().orElse(null), whereClause.partitions());
    }
    if (!whereClause.noMatch() || !(tableInfo.isPartitioned() && whereClause.partitions().isEmpty())) {
        // for updates, we always need to collect the `_id`
        Reference idReference = tableInfo.getReference(DocSysColumns.ID);
        Tuple<String[], Symbol[]> assignments = Assignments.convert(nestedAnalysis.assignments());
        Long version = null;
        if (versionSymbol != null) {
            version = ValueSymbolVisitor.LONG.process(versionSymbol);
        }
        UpdateProjection updateProjection = new UpdateProjection(new InputColumn(0, DataTypes.STRING), assignments.v1(), assignments.v2(), version);
        Routing routing = plannerContext.allocateRouting(tableInfo, whereClause, Preference.PRIMARY.type());
        return createPlan(plannerContext, routing, tableInfo, idReference, updateProjection, whereClause);
    } else {
        return null;
    }
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) WhereClause(io.crate.analyze.WhereClause) Routing(io.crate.metadata.Routing) SysUpdateProjection(io.crate.planner.projection.SysUpdateProjection) UpdateProjection(io.crate.planner.projection.UpdateProjection)

Example 9 with InputColumn

use of io.crate.analyze.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 = ImmutableList.<Symbol>of(new InputColumn(1), new InputColumn(0));
    RowShardResolver rowShardResolver = new RowShardResolver(functions, ImmutableList.of(ci("id"), ci("foo")), primaryKeySymbols, null, new InputColumn(1));
    rowShardResolver.setNextRow(row(1, null));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) InputColumn(io.crate.analyze.symbol.InputColumn) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with InputColumn

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

the class RowShardResolverTest method testPrimaryKeyNoRouting.

@Test
public void testPrimaryKeyNoRouting() {
    List<Symbol> primaryKeySymbols = ImmutableList.<Symbol>of(new InputColumn(0), new InputColumn(1));
    RowShardResolver rowShardResolver = new RowShardResolver(functions, ImmutableList.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.analyze.symbol.Symbol) InputColumn(io.crate.analyze.symbol.InputColumn) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

InputColumn (io.crate.analyze.symbol.InputColumn)24 Test (org.junit.Test)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)17 Symbol (io.crate.analyze.symbol.Symbol)8 Reference (io.crate.metadata.Reference)5 CollectExpression (io.crate.operation.collect.CollectExpression)5 Aggregation (io.crate.analyze.symbol.Aggregation)4 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)4 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)3 Input (io.crate.data.Input)2 FunctionIdent (io.crate.metadata.FunctionIdent)2 FunctionInfo (io.crate.metadata.FunctionInfo)2 Routing (io.crate.metadata.Routing)2 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)2 BytesRef (org.apache.lucene.util.BytesRef)2 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)2