Search in sources :

Example 41 with ReferenceIdent

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

the class SourceIndexWriterProjectionSerializationTest method testSerializationFailFast.

@Test
public void testSerializationFailFast() throws IOException {
    RelationName relationName = new RelationName("doc", "test");
    ReferenceIdent referenceIdent = new ReferenceIdent(relationName, "object_column");
    Reference reference = new Reference(referenceIdent, RowGranularity.DOC, new ArrayType<>(DataTypes.UNTYPED_OBJECT), ColumnPolicy.STRICT, Reference.IndexType.FULLTEXT, false, true, 0, Literal.of(Map.of("f", 10)));
    String partitionIdent = "pIdent";
    InputColumn inputColumn = new InputColumn(123);
    List<ColumnIdent> primaryKeys = List.of(new ColumnIdent("colIdent"));
    List<Symbol> partitionedBySymbols = List.of(reference);
    ColumnIdent clusteredByColumn = new ColumnIdent("col1");
    Settings settings = Settings.builder().put("fail_fast", true).build();
    // fail_fast property set to true
    SourceIndexWriterProjection expected = new SourceIndexWriterProjection(relationName, partitionIdent, reference, inputColumn, primaryKeys, partitionedBySymbols, clusteredByColumn, settings, null, null, List.of(), null, AbstractIndexWriterProjection.OUTPUTS, false);
    BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(Version.V_4_6_0);
    expected.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    in.setVersion(Version.V_4_6_0);
    assertThat(new SourceIndexWriterProjection(in).failFast(), is((!expected.failFast())));
    BytesStreamOutput out2 = new BytesStreamOutput();
    out2.setVersion(Version.V_4_7_0);
    expected.writeTo(out2);
    StreamInput in2 = out2.bytes().streamInput();
    in2.setVersion(Version.V_4_7_0);
    assertThat(new SourceIndexWriterProjection(in2).failFast(), is((expected.failFast())));
}
Also used : Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) ReferenceIdent(io.crate.metadata.ReferenceIdent) ColumnIdent(io.crate.metadata.ColumnIdent) InputColumn(io.crate.expression.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) RelationName(io.crate.metadata.RelationName) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 42 with ReferenceIdent

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

the class LuceneReferenceResolverTest method testGetImplementationForPrimaryTerm.

@Test
public void testGetImplementationForPrimaryTerm() {
    Reference primaryTerm = new Reference(new ReferenceIdent(name, "_primary_term"), RowGranularity.DOC, DataTypes.LONG, 0, null);
    assertThat(luceneReferenceResolver.getImplementation(primaryTerm), instanceOf(PrimaryTermCollectorExpression.class));
}
Also used : DynamicReference(io.crate.expression.symbol.DynamicReference) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 43 with ReferenceIdent

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

the class DocTableInfoTest method testGetColumnInfo.

@Test
public void testGetColumnInfo() throws Exception {
    RelationName relationName = new RelationName(Schemas.DOC_SCHEMA_NAME, "dummy");
    DocTableInfo info = new DocTableInfo(relationName, List.of(new Reference(new ReferenceIdent(relationName, new ColumnIdent("o", List.of())), RowGranularity.DOC, DataTypes.UNTYPED_OBJECT, 1, null)), List.of(), List.of(), List.of(), Map.of(), Map.of(), Map.of(), List.of(), List.of(), null, true, new String[0], new String[0], new IndexNameExpressionResolver(), 5, "0", Settings.EMPTY, List.of(), List.of(), ColumnPolicy.DYNAMIC, Version.CURRENT, null, false, Operation.ALL);
    final ColumnIdent col = new ColumnIdent("o", List.of("foobar"));
    Reference foobar = info.getReference(col);
    assertNull(foobar);
    // forWrite: false, errorOnUnknownObjectKey: true, parentPolicy: dynamic
    DynamicReference reference = info.getDynamic(col, false, true);
    assertNull(reference);
    // forWrite: true, errorOnUnknownObjectKey: true, parentPolicy: dynamic
    reference = info.getDynamic(col, true, true);
    assertNotNull(reference);
    assertSame(reference.valueType(), DataTypes.UNDEFINED);
    // forWrite: true, errorOnUnknownObjectKey: false, parentPolicy: dynamic
    reference = info.getDynamic(col, true, false);
    assertNotNull(reference);
    assertSame(reference.valueType(), DataTypes.UNDEFINED);
    // forWrite: false, errorOnUnknownObjectKey: false, parentPolicy: dynamic
    reference = info.getDynamic(col, false, false);
    assertNotNull(reference);
    assertTrue(reference instanceof VoidReference);
    assertSame(reference.valueType(), DataTypes.UNDEFINED);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) VoidReference(io.crate.expression.symbol.VoidReference) Reference(io.crate.metadata.Reference) DynamicReference(io.crate.expression.symbol.DynamicReference) VoidReference(io.crate.expression.symbol.VoidReference) DynamicReference(io.crate.expression.symbol.DynamicReference) RelationName(io.crate.metadata.RelationName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 44 with ReferenceIdent

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

the class DocTableInfoTest method testGetColumnInfoStrictParent.

@Test
public void testGetColumnInfoStrictParent() throws Exception {
    RelationName dummy = new RelationName(Schemas.DOC_SCHEMA_NAME, "dummy");
    ReferenceIdent foobarIdent = new ReferenceIdent(dummy, new ColumnIdent("foobar"));
    Reference strictParent = new Reference(foobarIdent, RowGranularity.DOC, DataTypes.UNTYPED_OBJECT, ColumnPolicy.STRICT, Reference.IndexType.PLAIN, true, false, 1, null);
    Map<ColumnIdent, Reference> references = Map.of(new ColumnIdent("foobar"), strictParent);
    DocTableInfo info = new DocTableInfo(dummy, List.of(strictParent), List.of(), List.of(), List.of(), Map.of(), references, Map.of(), List.of(), List.of(), null, true, new String[0], new String[0], new IndexNameExpressionResolver(), 5, "0", Settings.EMPTY, List.of(), List.of(), ColumnPolicy.DYNAMIC, Version.CURRENT, null, false, Operation.ALL);
    final ColumnIdent columnIdent = new ColumnIdent("foobar", Arrays.asList("foo", "bar"));
    assertNull(info.getReference(columnIdent));
    // forWrite: false, errorOnUnknownObjectKey: true, parentPolicy: strict
    assertNull(info.getDynamic(columnIdent, false, true));
    // forWrite: true, errorOnUnknownObjectKey: true, parentPolicy: strict
    Asserts.assertThrowsMatches(() -> info.getDynamic(columnIdent, true, true), ColumnUnknownException.class, "Column foobar['foo']['bar'] unknown");
    // forWrite: false, errorOnUnknownObjectKey: false, parentPolicy: strict
    assertNull(info.getDynamic(columnIdent, false, false));
    // forWrite: true, errorOnUnknownObjectKey: false, parentPolicy: strict
    Asserts.assertThrowsMatches(() -> assertNull(info.getDynamic(columnIdent, true, false)), ColumnUnknownException.class, "Column foobar['foo']['bar'] unknown");
    final ColumnIdent columnIdent2 = new ColumnIdent("foobar", Collections.singletonList("foo"));
    assertNull(info.getReference(columnIdent2));
    // forWrite: false, errorOnUnknownObjectKey: true, parentPolicy: strict
    assertNull(info.getDynamic(columnIdent2, false, true));
    // forWrite: true, errorOnUnknownObjectKey: true, parentPolicy: strict
    Asserts.assertThrowsMatches(() -> assertNull(info.getDynamic(columnIdent2, true, true)), ColumnUnknownException.class, "Column foobar['foo'] unknown");
    // forWrite: false, errorOnUnknownObjectKey: false, parentPolicy: strict
    assertNull(info.getDynamic(columnIdent2, false, false));
    // forWrite: true, errorOnUnknownObjectKey: false, parentPolicy: strict
    Asserts.assertThrowsMatches(() -> assertNull(info.getDynamic(columnIdent2, true, false)), ColumnUnknownException.class, "Column foobar['foo'] unknown");
    Reference colInfo = info.getReference(new ColumnIdent("foobar"));
    assertNotNull(colInfo);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DynamicReference(io.crate.expression.symbol.DynamicReference) VoidReference(io.crate.expression.symbol.VoidReference) RelationName(io.crate.metadata.RelationName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

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