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")));
}
Aggregations