Search in sources :

Example 26 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class HandlerSideLevelCollectTest method testClusterLevel.

@Test
public void testClusterLevel() throws Exception {
    Schemas schemas = internalCluster().getInstance(Schemas.class);
    TableInfo tableInfo = schemas.getTableInfo(new RelationName("sys", "cluster"));
    Routing routing = tableInfo.getRouting(clusterService().state(), routingProvider, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, SessionContext.systemSessionContext());
    Reference clusterNameRef = new Reference(new ReferenceIdent(SysClusterTableInfo.IDENT, new ColumnIdent("name")), RowGranularity.CLUSTER, DataTypes.STRING, 1, null);
    RoutedCollectPhase collectNode = collectNode(routing, List.of(clusterNameRef), RowGranularity.CLUSTER);
    Bucket result = collect(collectNode);
    assertThat(result.size(), is(1));
    assertThat(((String) result.iterator().next().get(0)), Matchers.startsWith("SUITE-"));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) Routing(io.crate.metadata.Routing) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) Schemas(io.crate.metadata.Schemas) ReferenceIdent(io.crate.metadata.ReferenceIdent) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 27 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class SystemCollectSourceTest method testOrderBySymbolsDoNotAppearTwiceInRows.

@Test
public void testOrderBySymbolsDoNotAppearTwiceInRows() throws Exception {
    SystemCollectSource systemCollectSource = internalCluster().getDataNodeInstance(SystemCollectSource.class);
    Reference shardId = new Reference(new ReferenceIdent(new RelationName("sys", "shards"), "id"), RowGranularity.SHARD, DataTypes.INTEGER, 0, null);
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Map.of()), RowGranularity.SHARD, Collections.singletonList(shardId), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    collectPhase.orderBy(new OrderBy(Collections.singletonList(shardId), new boolean[] { false }, new boolean[] { false }));
    Iterable<? extends Row> rows = systemCollectSource.toRowsIterableTransformation(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), unassignedShardRefResolver(), false).apply(Collections.singletonList(new UnassignedShard(1, "foo", mock(ClusterService.class), true, ShardRoutingState.UNASSIGNED)));
    Row next = rows.iterator().next();
    assertThat(next.numColumns(), is(1));
}
Also used : OrderBy(io.crate.analyze.OrderBy) ClusterService(org.elasticsearch.cluster.service.ClusterService) Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) Routing(io.crate.metadata.Routing) Row(io.crate.data.Row) UnassignedShard(io.crate.metadata.shard.unassigned.UnassignedShard) ReferenceIdent(io.crate.metadata.ReferenceIdent) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 28 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class CountAggregationTest method test_count_on_object_with_not_null_sibling_not_use_DocValueAggregator.

@Test
public void test_count_on_object_with_not_null_sibling_not_use_DocValueAggregator() {
    Reference notNullSibling = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_Integer")), RowGranularity.DOC, DataTypes.INTEGER, 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.UNTYPED, 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of(notNullSibling.column()));
    when(sourceTable.getReference(eq(notNullSibling.column()))).thenReturn(notNullSibling);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, null);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(0)).getReference(eq(notNullSibling.column()));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 29 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class CountAggregationTest method test_count_on_object_with_not_null_siblings_child_not_use_DocValueAggregator.

@Test
public void test_count_on_object_with_not_null_siblings_child_not_use_DocValueAggregator() {
    Reference notNullSibilingsChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_sibling", List.of("not_null_subcol"))), RowGranularity.DOC, DataTypes.STRING, 0, null);
    Reference sibling = new // unused
    Reference(new ReferenceIdent(null, new ColumnIdent("top_level_sibling")), RowGranularity.DOC, ObjectType.builder().setInnerType(notNullSibilingsChild.column().leafName(), notNullSibilingsChild.valueType()).build(), 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.UNTYPED, 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of(notNullSibilingsChild.column()));
    when(sourceTable.getReference(eq(notNullSibilingsChild.column()))).thenReturn(notNullSibilingsChild);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, null);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(0)).getReference(eq(notNullSibilingsChild.column()));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 30 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class AbstractTableFunctionsTest method prepareFunctions.

@Before
public void prepareFunctions() {
    DocTableRelation relation = mock(DocTableRelation.class);
    RelationName relationName = new RelationName(null, "t");
    when(relation.getField(any(ColumnIdent.class), any(Operation.class), any(Boolean.class))).thenReturn(new Reference(new ReferenceIdent(relationName, "name"), RowGranularity.NODE, DataTypes.STRING, 0, null));
    sqlExpressions = new SqlExpressions(Map.of(relationName, relation));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DocTableRelation(io.crate.analyze.relations.DocTableRelation) RelationName(io.crate.metadata.RelationName) Operation(io.crate.metadata.table.Operation) SqlExpressions(io.crate.testing.SqlExpressions) ReferenceIdent(io.crate.metadata.ReferenceIdent) Before(org.junit.Before)

Aggregations

Reference (io.crate.metadata.Reference)44 ReferenceIdent (io.crate.metadata.ReferenceIdent)44 Test (org.junit.Test)31 RelationName (io.crate.metadata.RelationName)21 ColumnIdent (io.crate.metadata.ColumnIdent)19 DynamicReference (io.crate.expression.symbol.DynamicReference)12 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)12 SymbolMatchers.isReference (io.crate.testing.SymbolMatchers.isReference)9 VoidReference (io.crate.expression.symbol.VoidReference)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)8 Symbol (io.crate.expression.symbol.Symbol)6 FetchReference (io.crate.expression.symbol.FetchReference)5 OrderBy (io.crate.analyze.OrderBy)4 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)4 CollectorContext (io.crate.expression.reference.doc.lucene.CollectorContext)3 TestingRowConsumer (io.crate.testing.TestingRowConsumer)3 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)3 Before (org.junit.Before)3 Bucket (io.crate.data.Bucket)2 SumAggregation (io.crate.execution.engine.aggregation.impl.SumAggregation)2