Search in sources :

Example 46 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class UpdateSourceGenTest method testGeneratedColumnUsingFunctionDependingOnActiveTransaction.

@Test
public void testGeneratedColumnUsingFunctionDependingOnActiveTransaction() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (x int, gen as current_schema)").build();
    AnalyzedUpdateStatement update = e.analyze("update t set x = 1");
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    DocTableInfo table = (DocTableInfo) update.table().tableInfo();
    UpdateSourceGen sourceGen = new UpdateSourceGen(TransactionContext.of(DUMMY_SESSION_INFO), e.nodeCtx, table, assignments.targetNames());
    Map<String, Object> source = sourceGen.generateSource(new Doc(1, table.concreteIndices()[0], "1", 1, 1, 1, emptyMap(), () -> "{}"), assignments.sources(), new Object[0]);
    assertThat(source, is(Map.of("gen", "dummySchema", "x", 1)));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) AnalyzedUpdateStatement(io.crate.analyze.AnalyzedUpdateStatement) Assignments(io.crate.expression.symbol.Assignments) Doc(io.crate.expression.reference.Doc) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 47 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class UpdateSourceGenTest method testSourceGenerationWithAssignmentUsingDocumentPrimaryKey.

@Test
public void testSourceGenerationWithAssignmentUsingDocumentPrimaryKey() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (y int)").build();
    AnalyzedUpdateStatement update = e.analyze("update t set y = _id::integer * 2");
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    DocTableInfo table = (DocTableInfo) update.table().tableInfo();
    UpdateSourceGen updateSourceGen = new UpdateSourceGen(txnCtx, e.nodeCtx, table, assignments.targetNames());
    BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("y", 100).endObject());
    Map<String, Object> updatedSource = updateSourceGen.generateSource(new Doc(1, table.concreteIndices()[0], "4", 1, 1, 1, emptyMap(), source::utf8ToString), assignments.sources(), new Object[0]);
    assertThat(updatedSource, is(Map.of("y", 8)));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) AnalyzedUpdateStatement(io.crate.analyze.AnalyzedUpdateStatement) Assignments(io.crate.expression.symbol.Assignments) Doc(io.crate.expression.reference.Doc) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 48 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo 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 49 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo 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 50 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo 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)

Aggregations

DocTableInfo (io.crate.metadata.doc.DocTableInfo)127 Test (org.junit.Test)56 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)40 Symbol (io.crate.expression.symbol.Symbol)27 Reference (io.crate.metadata.Reference)27 SQLExecutor (io.crate.testing.SQLExecutor)25 RelationName (io.crate.metadata.RelationName)24 DocTableRelation (io.crate.analyze.relations.DocTableRelation)20 ColumnIdent (io.crate.metadata.ColumnIdent)20 TableInfo (io.crate.metadata.table.TableInfo)18 Assignments (io.crate.expression.symbol.Assignments)16 Row (io.crate.data.Row)14 PlannerContext (io.crate.planner.PlannerContext)13 Before (org.junit.Before)13 RowConsumer (io.crate.data.RowConsumer)12 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)12 PartitionName (io.crate.metadata.PartitionName)12 DependencyCarrier (io.crate.planner.DependencyCarrier)12 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12