Search in sources :

Example 6 with ReferenceIdent

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

the class BlobTableInfo method registerStaticColumns.

private void registerStaticColumns() {
    int pos = 0;
    for (Tuple<String, DataType> column : STATIC_COLUMNS) {
        Reference ref = new Reference(new ReferenceIdent(ident(), column.v1(), null), RowGranularity.DOC, column.v2(), pos, null);
        assert ref.column().isTopLevel() : "only top-level columns should be added to columns list";
        pos++;
        columns.add(ref);
        infos.put(ref.column(), ref);
    }
}
Also used : Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) ReferenceIdent(io.crate.metadata.ReferenceIdent)

Example 7 with ReferenceIdent

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

the class CountAggregationTest method test_count_on_object_with_deeper_not_null_subcolumn_uses_DocValueAggregator.

@Test
public void test_count_on_object_with_deeper_not_null_subcolumn_uses_DocValueAggregator() {
    Reference notNullGrandChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", List.of("second_level_object", "not_null_subcol"))), RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    Reference immediateChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", "second_level_object")), RowGranularity.DOC, ObjectType.builder().setInnerType(notNullGrandChild.column().leafName(), notNullGrandChild.valueType()).build(), ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.builder().setInnerType(immediateChild.column().leafName(), immediateChild.valueType()).build(), ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of(notNullGrandChild.column()));
    when(sourceTable.getReference(eq(notNullGrandChild.column()))).thenReturn(notNullGrandChild);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, BinaryDocValueAggregator.class);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(1)).getReference(eq(notNullGrandChild.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 8 with ReferenceIdent

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

the class CountAggregationTest method test_count_on_object_with_multiple_not_null_candidates.

@Test
public void test_count_on_object_with_multiple_not_null_candidates() {
    Reference notNullGrandChild1 = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", List.of("second_level_object", "not_null_subcol1"))), RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    Reference notNullGrandChild2 = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", List.of("second_level_object", "not_null_subcol2"))), RowGranularity.DOC, DataTypes.BYTE, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    Reference immediateChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", "second_level_object")), RowGranularity.DOC, ObjectType.builder().setInnerType(notNullGrandChild1.column().leafName(), notNullGrandChild1.valueType()).setInnerType(notNullGrandChild2.column().leafName(), notNullGrandChild2.valueType()).build(), ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    Reference notNullImmediateChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", "not_null_subcol")), RowGranularity.DOC, DataTypes.IP, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.builder().setInnerType(immediateChild.column().leafName(), immediateChild.valueType()).setInnerType(notNullImmediateChild.column().leafName(), notNullImmediateChild.valueType()).build(), ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of(notNullGrandChild1.column(), notNullGrandChild2.column(), notNullImmediateChild.column()));
    when(sourceTable.getReference(eq(notNullGrandChild1.column()))).thenReturn(notNullGrandChild1);
    when(sourceTable.getReference(eq(notNullGrandChild2.column()))).thenReturn(notNullGrandChild2);
    when(sourceTable.getReference(eq(notNullImmediateChild.column()))).thenReturn(notNullImmediateChild);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, BinaryDocValueAggregator.class);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(1)).getReference(eq(notNullGrandChild1.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 9 with ReferenceIdent

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

the class CountAggregationTest method test_count_on_object_with_nullable_subcolumn_not_use_DocValueAggregator.

@Test
public void test_count_on_object_with_nullable_subcolumn_not_use_DocValueAggregator() {
    Reference nullableChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", "nullable_subcol")), RowGranularity.DOC, DataTypes.INTEGER, 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.builder().setInnerType(nullableChild.column().leafName(), nullableChild.valueType()).build(), 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of());
    when(sourceTable.getReference(eq(nullableChild.column()))).thenReturn(nullableChild);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, null);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(0)).getReference(eq(nullableChild.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 10 with ReferenceIdent

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

the class CountAggregationTest method helper_count_on_object_with_not_null_immediate_child.

private void helper_count_on_object_with_not_null_immediate_child(DataType<?> childType, Class<?> expectedAggregatorClass) {
    Reference notNullImmediateChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", "not_null_subcol")), RowGranularity.DOC, childType, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.builder().setInnerType(notNullImmediateChild.column().leafName(), notNullImmediateChild.valueType()).build(), ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of(notNullImmediateChild.column()));
    when(sourceTable.getReference(eq(notNullImmediateChild.column()))).thenReturn(notNullImmediateChild);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, expectedAggregatorClass);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(1)).getReference(eq(notNullImmediateChild.column()));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent)

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