Search in sources :

Example 21 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class RemoteCollectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of("remoteNode", ImmutableMap.of("dummyTable", Collections.singletonList(1)))), RowGranularity.DOC, Collections.<Symbol>singletonList(createReference("name", DataTypes.STRING)), Collections.<Projection>emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    transportKillJobsNodeAction = mock(TransportKillJobsNodeAction.class);
    consumer = new TestingBatchConsumer();
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    JobContextService jobContextService = new JobContextService(Settings.EMPTY, new NoopClusterService(), jobsLogs);
    remoteCollector = new RemoteCollector(jobId, "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, jobContextService, mock(RamAccountingContext.class), consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.action.job.TransportJobAction) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) JobsLogs(io.crate.operation.collect.stats.JobsLogs) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) JobContextService(io.crate.jobs.JobContextService) Before(org.junit.Before)

Example 22 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class DocLevelCollectTest method testCollectWithPartitionedColumns.

@Test
public void testCollectWithPartitionedColumns() throws Throwable {
    TableIdent tableIdent = new TableIdent(Schemas.DEFAULT_SCHEMA_NAME, PARTITIONED_TABLE_NAME);
    Routing routing = schemas.getTableInfo(tableIdent).getRouting(WhereClause.MATCH_ALL, null);
    RoutedCollectPhase collectNode = getCollectNode(Arrays.<Symbol>asList(new Reference(new ReferenceIdent(tableIdent, "id"), RowGranularity.DOC, DataTypes.INTEGER), new Reference(new ReferenceIdent(tableIdent, "date"), RowGranularity.SHARD, DataTypes.TIMESTAMP)), routing, WhereClause.MATCH_ALL);
    Bucket result = collect(collectNode);
    for (Row row : result) {
        System.out.println("Row:" + Arrays.toString(row.materialize()));
    }
    assertThat(result, containsInAnyOrder(isRow(1, 0L), isRow(2, 1L)));
}
Also used : Bucket(io.crate.data.Bucket) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) Row(io.crate.data.Row) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 23 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class DocLevelCollectTest method testCollectDocLevel.

@Test
public void testCollectDocLevel() throws Throwable {
    List<Symbol> toCollect = Arrays.<Symbol>asList(testDocLevelReference, underscoreRawReference, underscoreIdReference);
    RoutedCollectPhase collectNode = getCollectNode(toCollect, WhereClause.MATCH_ALL);
    Bucket result = collect(collectNode);
    assertThat(result, containsInAnyOrder(isRow(2, "{\"id\":1,\"doc\":2}", "1"), isRow(4, "{\"id\":3,\"doc\":4}", "3")));
}
Also used : Bucket(io.crate.data.Bucket) Symbol(io.crate.analyze.symbol.Symbol) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 24 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class HandlerSideLevelCollectTest method testInformationSchemaColumns.

@Test
public void testInformationSchemaColumns() throws Exception {
    InformationSchemaInfo schemaInfo = internalCluster().getInstance(InformationSchemaInfo.class);
    TableInfo tableInfo = schemaInfo.getTableInfo("columns");
    assert tableInfo != null;
    Routing routing = tableInfo.getRouting(WhereClause.MATCH_ALL, null);
    List<Symbol> toCollect = new ArrayList<>();
    for (Reference ref : tableInfo.columns()) {
        toCollect.add(ref);
    }
    RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC);
    Bucket result = collect(collectNode);
    String expected = "id| string| NULL| false| true| 1| cluster| sys\n" + "master_node| string| NULL| false| true| 2| cluster| sys\n" + "name| string| NULL| false| true| 3| cluster| sys\n" + "settings| object| NULL| false| true| 4| cluster| sys\n";
    assertThat(TestingHelpers.printedTable(result), Matchers.containsString(expected));
    // second time - to check if the internal iterator resets
    result = collect(collectNode);
    assertThat(TestingHelpers.printedTable(result), Matchers.containsString(expected));
}
Also used : InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) Symbol(io.crate.analyze.symbol.Symbol) ArrayList(java.util.ArrayList) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 25 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class JobCollectContextTest method testThreadPoolNameForNonDocTables.

@Test
public void testThreadPoolNameForNonDocTables() throws Exception {
    RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(collectPhase.routing()).thenReturn(routing);
    when(routing.containsShards(localNodeId)).thenReturn(false);
    // sys.cluster (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.CLUSTER);
    String threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
    // partition values only of a partitioned doc table (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.PARTITION);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
    // sys.nodes (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.NODE);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
    // sys.shards
    when(routing.containsShards(localNodeId)).thenReturn(true);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.SHARD);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
    when(routing.containsShards(localNodeId)).thenReturn(false);
    // information_schema.*
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
}
Also used : Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)48 Test (org.junit.Test)36 CrateUnitTest (io.crate.test.integration.CrateUnitTest)25 Collect (io.crate.planner.node.dql.Collect)18 MergePhase (io.crate.planner.node.dql.MergePhase)15 Merge (io.crate.planner.Merge)14 Routing (io.crate.metadata.Routing)10 Symbol (io.crate.analyze.symbol.Symbol)8 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)8 DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)7 Bucket (io.crate.data.Bucket)6 Reference (io.crate.metadata.Reference)6 Row (io.crate.data.Row)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 OrderBy (io.crate.analyze.OrderBy)3 Function (io.crate.analyze.symbol.Function)3 CollectionBucket (io.crate.data.CollectionBucket)3