Search in sources :

Example 11 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class GroupByPlannerTest method testHandlerSideRoutingGroupBy.

@Test
public void testHandlerSideRoutingGroupBy() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).build();
    Collect collect = e.plan("select count(*) from sys.cluster group by name");
    // just testing the dispatching here.. making sure it is not a ESSearchNode
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.toCollect().get(0), instanceOf(Reference.class));
    assertThat(collectPhase.toCollect().size(), is(1));
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 12 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.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(clusterService().state(), routingProvider, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, SessionContext.systemSessionContext());
    List<Symbol> toCollect = new ArrayList<>();
    for (Reference ref : tableInfo.columns()) {
        if (Set.of("column_name", "data_type", "table_name").contains(ref.column().name())) {
            toCollect.add(ref);
        }
    }
    RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC);
    List<Object[]> result = StreamSupport.stream(collect(collectNode).spliterator(), false).limit(10).map(Row::materialize).collect(Collectors.toList());
    String expected = "character_repertoire| text| character_sets\n" + "character_set_catalog| text| character_sets\n" + "character_set_name| text| character_sets\n" + "character_set_schema| text| character_sets\n" + "default_collate_catalog| text| character_sets\n" + "default_collate_name| text| character_sets\n" + "default_collate_schema| text| character_sets\n" + "form_of_use| text| character_sets\n" + "character_maximum_length| integer| columns\n" + "character_octet_length| integer| columns\n";
    assertThat(TestingHelpers.printedTable(result.toArray(new Object[0][])), Matchers.containsString(expected));
    // second time - to check if the internal iterator resets
    result = StreamSupport.stream(collect(collectNode).spliterator(), false).limit(10).map(Row::materialize).collect(Collectors.toList());
    assertThat(TestingHelpers.printedTable(result.toArray(new Object[0][])), Matchers.containsString(expected));
}
Also used : InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) Symbol(io.crate.expression.symbol.Symbol) Reference(io.crate.metadata.Reference) ArrayList(java.util.ArrayList) Routing(io.crate.metadata.Routing) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) Row(io.crate.data.Row) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 13 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class HandlerSideLevelCollectTest method testInformationSchemaTables.

@Test
public void testInformationSchemaTables() throws Exception {
    InformationSchemaInfo schemaInfo = internalCluster().getInstance(InformationSchemaInfo.class);
    TableInfo tablesTableInfo = schemaInfo.getTableInfo("tables");
    Routing routing = tablesTableInfo.getRouting(clusterService().state(), routingProvider, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, SessionContext.systemSessionContext());
    List<Symbol> toCollect = new ArrayList<>();
    for (Reference reference : tablesTableInfo.columns()) {
        toCollect.add(reference);
    }
    Symbol tableNameRef = toCollect.get(12);
    List<Symbol> arguments = Arrays.asList(tableNameRef, Literal.of("shards"));
    FunctionImplementation eqImpl = functions.get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
    Function whereClause = new Function(eqImpl.signature(), arguments, EqOperator.RETURN_TYPE);
    RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC, new WhereClause(whereClause));
    Bucket result = collect(collectNode);
    assertThat(TestingHelpers.printedTable(result), is("NULL| NULL| NULL| strict| NULL| NULL| NULL| SYSTEM GENERATED| NULL| NULL| NULL| sys| shards| sys| BASE TABLE| NULL\n"));
}
Also used : Function(io.crate.expression.symbol.Function) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) Symbol(io.crate.expression.symbol.Symbol) Reference(io.crate.metadata.Reference) ArrayList(java.util.ArrayList) WhereClause(io.crate.analyze.WhereClause) Routing(io.crate.metadata.Routing) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) FunctionImplementation(io.crate.metadata.FunctionImplementation) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 14 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class CollectTaskTest 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 = CollectTask.threadPoolName(collectPhase, true);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.SEARCH));
    // partition values only of a partitioned doc table (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.PARTITION);
    threadPoolExecutorName = CollectTask.threadPoolName(collectPhase, true);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.SEARCH));
    // sys.nodes (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.NODE);
    threadPoolExecutorName = CollectTask.threadPoolName(collectPhase, true);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.GET));
    // sys.shards
    when(routing.containsShards(localNodeId)).thenReturn(true);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.SHARD);
    threadPoolExecutorName = CollectTask.threadPoolName(collectPhase, true);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.GET));
    when(routing.containsShards(localNodeId)).thenReturn(false);
    // information_schema.*
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    threadPoolExecutorName = CollectTask.threadPoolName(collectPhase, false);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.SAME));
}
Also used : Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 15 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class DocLevelCollectTest method testCollectDocLevel.

@Test
public void testCollectDocLevel() throws Throwable {
    List<Symbol> toCollect = Arrays.asList(testDocLevelReference, underscoreIdReference);
    RoutedCollectPhase collectNode = getCollectNode(toCollect, WhereClause.MATCH_ALL);
    Bucket result = collect(collectNode);
    assertThat(result, containsInAnyOrder(isRow(2, "1"), isRow(4, "3")));
}
Also used : Bucket(io.crate.data.Bucket) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) Symbol(io.crate.expression.symbol.Symbol) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Aggregations

RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)50 Test (org.junit.Test)39 Collect (io.crate.planner.node.dql.Collect)23 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)23 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)18 Routing (io.crate.metadata.Routing)18 MergePhase (io.crate.execution.dsl.phases.MergePhase)14 Merge (io.crate.planner.Merge)10 Symbol (io.crate.expression.symbol.Symbol)9 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)8 Reference (io.crate.metadata.Reference)8 Row (io.crate.data.Row)7 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)7 ArrayList (java.util.ArrayList)6 Bucket (io.crate.data.Bucket)5 RelationName (io.crate.metadata.RelationName)5 UUID (java.util.UUID)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)3 OrderBy (io.crate.analyze.OrderBy)3