Search in sources :

Example 56 with RelationName

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

the class MetadataIndexUpgraderTest method test__all_is_removed_from_mapping.

@Test
public void test__all_is_removed_from_mapping() throws Throwable {
    IndexMetadata indexMetadata = IndexMetadata.builder(new RelationName("doc", "users").indexNameOrAlias()).settings(Settings.builder().put("index.version.created", Version.V_3_2_0)).numberOfShards(1).numberOfReplicas(0).putMapping(Constants.DEFAULT_MAPPING_TYPE, "{" + "   \"_all\": {\"enabled\": false}," + "   \"properties\": {" + "       \"name\": {" + "           \"type\": \"keyword\"" + "       }" + "   }" + "}").build();
    MetadataIndexUpgrader metadataIndexUpgrader = new MetadataIndexUpgrader();
    IndexMetadata updatedMetadata = metadataIndexUpgrader.apply(indexMetadata);
    MappingMetadata mapping = updatedMetadata.mapping();
    assertThat(mapping.source().string(), Matchers.is("{\"default\":{\"properties\":{\"name\":{\"type\":\"keyword\"}}}}"));
}
Also used : RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) MappingMetadata(org.elasticsearch.cluster.metadata.MappingMetadata) Test(org.junit.Test)

Example 57 with RelationName

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

the class InsertPlannerTest method testInsertFromQueryWithPartitionedColumn.

@Test
public void testInsertFromQueryWithPartitionedColumn() {
    Merge planNode = e.plan("insert into users (id, date) (select id, date from parted_pks)");
    Collect queryAndFetch = (Collect) planNode.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) queryAndFetch.collectPhase());
    List<Symbol> toCollect = collectPhase.toCollect();
    assertThat(toCollect.size(), is(2));
    assertThat(toCollect.get(0), isReference("_doc['id']"));
    assertThat(toCollect.get(1), equalTo(new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "parted_pks"), "date"), RowGranularity.PARTITION, DataTypes.TIMESTAMPZ, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 3, null)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Symbol(io.crate.expression.symbol.Symbol) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) RelationName(io.crate.metadata.RelationName) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) ReferenceIdent(io.crate.metadata.ReferenceIdent) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 58 with RelationName

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

the class WhereClauseAnalyzerTest method testSelectWherePartitionedByColumn.

@Test
public void testSelectWherePartitionedByColumn() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select id from parted where date = 1395874800000");
    assertThat(whereClause.queryOrFallback(), isLiteral(true));
    assertThat(whereClause.partitions(), Matchers.contains(new PartitionName(new RelationName("doc", "parted"), Arrays.asList("1395874800000")).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) RelationName(io.crate.metadata.RelationName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 59 with RelationName

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

the class WhereClauseAnalyzerTest method registerTables.

private void registerTables(SQLExecutor.Builder builder) throws IOException {
    builder.addTable("create table users (" + "  id string primary key," + "  name string," + "  tags array(string)" + ") clustered by (id)");
    RelationName docParted = new RelationName("doc", "parted");
    builder.addPartitionedTable("create table doc.parted (" + "   id integer," + "   name string," + "   date timestamp with time zone," + "   obj object (ignored)" + ") partitioned by (date)", new PartitionName(docParted, singletonList("1395874800000")).asIndexName(), new PartitionName(docParted, singletonList("1395961200000")).asIndexName(), new PartitionName(docParted, singletonList(null)).asIndexName());
    builder.addTable("create table doc.users_multi_pk (" + "   id long primary key," + "   name string primary key," + "   details object," + "   awesome boolean," + "   friends array(object)" + ") clustered by (id)");
    builder.addTable("create table doc.pk4 (" + "   i1 integer primary key," + "   i2 integer primary key," + "   i3 integer primary key," + "   i4 integer primary key" + ")");
}
Also used : PartitionName(io.crate.metadata.PartitionName) RelationName(io.crate.metadata.RelationName)

Example 60 with RelationName

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

the class WhereClauseAnalyzerTest method prepare.

@Before
public void prepare() throws IOException {
    SQLExecutor.Builder builder = SQLExecutor.builder(clusterService);
    registerTables(builder);
    RelationName docGeneratedCol = new RelationName("doc", "generated_col");
    builder.addPartitionedTable("create table doc.generated_col (" + "   ts timestamp with time zone ," + "   x integer," + "   y long," + "   day as date_trunc('day', ts)," + "   minus_y as y * -1," + "   x_incr as x + 1" + ") partitioned by (day, minus_y)", new PartitionName(docGeneratedCol, Arrays.asList("1420070400000", "-1")).asIndexName(), new PartitionName(docGeneratedCol, Arrays.asList("1420156800000", "-2")).asIndexName());
    RelationName docDoubleGenParted = new RelationName(DocSchemaInfo.NAME, "double_gen_parted");
    builder.addPartitionedTable("create table doc.double_gen_parted (" + "   x integer," + "   x1 as x + 1," + "   x2 as x + 2" + ") partitioned by (x1, x2)", new PartitionName(docDoubleGenParted, Arrays.asList("4", "5")).toString(), new PartitionName(docDoubleGenParted, Arrays.asList("5", "6")).toString());
    e = builder.build();
}
Also used : PartitionName(io.crate.metadata.PartitionName) SQLExecutor(io.crate.testing.SQLExecutor) RelationName(io.crate.metadata.RelationName) Before(org.junit.Before)

Aggregations

RelationName (io.crate.metadata.RelationName)180 Test (org.junit.Test)100 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 PartitionName (io.crate.metadata.PartitionName)47 Symbol (io.crate.expression.symbol.Symbol)42 Reference (io.crate.metadata.Reference)37 ColumnIdent (io.crate.metadata.ColumnIdent)31 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)21 ReferenceIdent (io.crate.metadata.ReferenceIdent)21 DocTableInfo (io.crate.metadata.doc.DocTableInfo)21 Map (java.util.Map)20 HashMap (java.util.HashMap)19 SqlExpressions (io.crate.testing.SqlExpressions)18 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Before (org.junit.Before)17 DocTableRelation (io.crate.analyze.relations.DocTableRelation)13 SQLExecutor (io.crate.testing.SQLExecutor)11 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)10