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