Search in sources :

Example 16 with GeneratedReference

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

the class DocIndexMetadataTest method testSchemaWithGeneratedColumn.

@Test
public void testSchemaWithGeneratedColumn() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").startObject("generated_columns").field("week", "date_trunc('week', ts)").endObject().endObject().startObject("properties").startObject("ts").field("type", "date").endObject().startObject("week").field("type", "long").endObject().endObject().endObject();
    IndexMetadata metadata = getIndexMetadata("test1", builder);
    DocIndexMetadata md = newMeta(metadata, "test1");
    assertThat(md.columns().size(), is(2));
    Reference week = md.references().get(new ColumnIdent("week"));
    assertThat(week, Matchers.notNullValue());
    assertThat(week, instanceOf(GeneratedReference.class));
    assertThat(((GeneratedReference) week).formattedGeneratedExpression(), is("date_trunc('week', ts)"));
    assertThat(((GeneratedReference) week).generatedExpression(), isFunction("date_trunc", isLiteral("week"), isReference("ts")));
    assertThat(((GeneratedReference) week).referencedReferences(), contains(isReference("ts")));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) GeneratedReference(io.crate.metadata.GeneratedReference) GeneratedReference(io.crate.metadata.GeneratedReference) BytesReference(org.elasticsearch.common.bytes.BytesReference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) IndexReference(io.crate.metadata.IndexReference) Reference(io.crate.metadata.Reference) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

GeneratedReference (io.crate.metadata.GeneratedReference)16 Reference (io.crate.metadata.Reference)14 ColumnIdent (io.crate.metadata.ColumnIdent)9 IndexReference (io.crate.metadata.IndexReference)4 ArrayList (java.util.ArrayList)4 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)3 Symbol (io.crate.expression.symbol.Symbol)3 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)3 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)2 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)2 TableReferenceResolver (io.crate.analyze.expressions.TableReferenceResolver)2 Lists2 (io.crate.common.collections.Lists2)2 GeoReference (io.crate.metadata.GeoReference)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 Test (org.junit.Test)2 AnalyzedCopyTo (io.crate.analyze.AnalyzedCopyTo)1 BoundCopyTo (io.crate.analyze.BoundCopyTo)1