use of io.crate.common.collections.Lists2.mapTail in project crate by crate.
the class DocIndexMetadataTest method testExtractColumnDefinitionsWithDefaultExpression.
@Test
public void testExtractColumnDefinitionsWithDefaultExpression() throws Exception {
// @formatter:off
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").field("primary_keys", "integerIndexed").endObject().startObject("properties").startObject("integerIndexed").field("type", "integer").field("default_expr", "1").endObject().startObject("integerNotIndexed").field("type", "integer").field("index", "false").field("default_expr", "1").endObject().startObject("stringNotIndexed").field("type", "string").field("index", "false").field("default_expr", "'default'").endObject().startObject("stringNotAnalyzed").field("type", "keyword").field("default_expr", "'default'").endObject().startObject("stringAnalyzed").field("type", "text").field("analyzer", "standard").field("default_expr", "'default'").endObject().startObject("birthday").field("type", "date").field("default_expr", "current_timestamp(3)").endObject().endObject().endObject();
// @formatter:on
IndexMetadata metadata = getIndexMetadata("test1", builder);
DocIndexMetadata md = newMeta(metadata, "test1");
assertThat(md.columns().size(), is(6));
assertThat(md.references().size(), is(16));
Reference birthday = md.references().get(new ColumnIdent("birthday"));
assertThat(birthday.valueType(), is(DataTypes.TIMESTAMPZ));
assertThat(birthday.defaultExpression(), isFunction("current_timestamp", List.of(DataTypes.INTEGER)));
Reference integerIndexed = md.references().get(new ColumnIdent("integerIndexed"));
assertThat(integerIndexed.indexType(), is(Reference.IndexType.PLAIN));
assertThat(integerIndexed.defaultExpression(), isLiteral(1));
Reference integerNotIndexed = md.references().get(new ColumnIdent("integerNotIndexed"));
assertThat(integerNotIndexed.indexType(), is(Reference.IndexType.NONE));
assertThat(integerNotIndexed.defaultExpression(), isLiteral(1));
Reference stringNotIndexed = md.references().get(new ColumnIdent("stringNotIndexed"));
assertThat(stringNotIndexed.indexType(), is(Reference.IndexType.NONE));
assertThat(stringNotIndexed.defaultExpression(), isLiteral("default"));
Reference stringNotAnalyzed = md.references().get(new ColumnIdent("stringNotAnalyzed"));
assertThat(stringNotAnalyzed.indexType(), is(Reference.IndexType.PLAIN));
assertThat(stringNotAnalyzed.defaultExpression(), isLiteral("default"));
Reference stringAnalyzed = md.references().get(new ColumnIdent("stringAnalyzed"));
assertThat(stringAnalyzed.indexType(), is(Reference.IndexType.FULLTEXT));
assertThat(stringAnalyzed.defaultExpression(), isLiteral("default"));
assertThat(Lists2.map(md.references().values(), r -> r.column().fqn()), containsInAnyOrder("_raw", "_doc", "_seq_no", "_version", "_id", "_uid", "_score", "_fetchid", "_primary_term", "_docid", "birthday", "integerIndexed", "integerNotIndexed", "stringAnalyzed", "stringNotAnalyzed", "stringNotIndexed"));
}
Aggregations