Search in sources :

Example 21 with Lists2.mapTail

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"));
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) Arrays(java.util.Arrays) SessionContext(io.crate.action.sql.SessionContext) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Environment(org.elasticsearch.env.Environment) Matchers.not(org.hamcrest.Matchers.not) UserDefinedFunctionService(io.crate.expression.udf.UserDefinedFunctionService) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Matchers.hasKey(org.hamcrest.Matchers.hasKey) ArrayType(io.crate.types.ArrayType) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) CreateTableStatementAnalyzer(io.crate.analyze.CreateTableStatementAnalyzer) Path(java.nio.file.Path) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) BoundCreateTable(io.crate.analyze.BoundCreateTable) FulltextAnalyzerResolver(io.crate.metadata.FulltextAnalyzerResolver) AnalyzedCreateTable(io.crate.analyze.AnalyzedCreateTable) NodeContext(io.crate.metadata.NodeContext) GeneratedReference(io.crate.metadata.GeneratedReference) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) BytesReference(org.elasticsearch.common.bytes.BytesReference) Collectors(java.util.stream.Collectors) Lists2(io.crate.common.collections.Lists2) CheckConstraint(io.crate.sql.tree.CheckConstraint) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Row(io.crate.data.Row) MappingMetadata(org.elasticsearch.cluster.metadata.MappingMetadata) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DataTypes(io.crate.types.DataTypes) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SubQueryResults(io.crate.planner.operators.SubQueryResults) Statement(io.crate.sql.tree.Statement) Matchers.is(org.hamcrest.Matchers.is) Expression(io.crate.sql.tree.Expression) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) XContentType(org.elasticsearch.common.xcontent.XContentType) Analysis(io.crate.analyze.Analysis) ViewInfoFactory(io.crate.metadata.view.ViewInfoFactory) HashMap(java.util.HashMap) ObjectType(io.crate.types.ObjectType) IndexReference(io.crate.metadata.IndexReference) ArrayList(java.util.ArrayList) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) Constants(io.crate.Constants) CreateTablePlan(io.crate.planner.node.ddl.CreateTablePlan) ColumnPolicy(io.crate.sql.tree.ColumnPolicy) SqlParser(io.crate.sql.parser.SqlParser) Before(org.junit.Before) CreateTable(io.crate.sql.tree.CreateTable) Collections.emptyMap(java.util.Collections.emptyMap) StringType(io.crate.types.StringType) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) NumberOfShards(io.crate.analyze.NumberOfShards) TreeMap(java.util.TreeMap) Schemas(io.crate.metadata.Schemas) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) ColumnIdent(io.crate.metadata.ColumnIdent) 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

Lists2 (io.crate.common.collections.Lists2)21 Symbol (io.crate.expression.symbol.Symbol)17 List (java.util.List)17 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)13 Map (java.util.Map)13 NodeContext (io.crate.metadata.NodeContext)12 ArrayList (java.util.ArrayList)12 Row (io.crate.data.Row)10 DocTableInfo (io.crate.metadata.doc.DocTableInfo)10 Nullable (javax.annotation.Nullable)10 RelationName (io.crate.metadata.RelationName)8 SubQueryResults (io.crate.planner.operators.SubQueryResults)8 HashMap (java.util.HashMap)8 Function (java.util.function.Function)8 Literal (io.crate.expression.symbol.Literal)7 PlannerContext (io.crate.planner.PlannerContext)7 DataType (io.crate.types.DataType)7 Schemas (io.crate.metadata.Schemas)6 RowConsumer (io.crate.data.RowConsumer)5 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)5