Search in sources :

Example 71 with RelationName

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

the class EqualityExtractorTest method test_primary_key_extraction_on_subscript_with_any.

@Test
public void test_primary_key_extraction_on_subscript_with_any() {
    Map<RelationName, AnalyzedRelation> sources = T3.sources(List.of(T3.T4), clusterService);
    DocTableRelation tr4 = (DocTableRelation) sources.get(T3.T4);
    var expressionsT4 = new SqlExpressions(sources, tr4);
    var pkCol = new ColumnIdent("obj");
    var query = expressionsT4.normalize(expressionsT4.asSymbol("obj = any([{i = 1}])"));
    List<List<Symbol>> matches = analyzeExact(query, List.of(pkCol));
    assertThat(matches, contains(contains(isLiteral(Map.of("i", 1)))));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) List(java.util.List) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 72 with RelationName

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

the class ColumnPolicyIntegrationTest method testStrictPartitionedTableInsert.

@Test
public void testStrictPartitionedTableInsert() throws Exception {
    execute("create table numbers (" + "  num int, " + "  odd boolean," + "  prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)");
    ensureYellow();
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(PartitionName.templateName(sqlExecutor.getCurrentSchema(), "numbers")).execute().actionGet();
    assertThat(response.getIndexTemplates().size(), is(1));
    IndexTemplateMetadata template = response.getIndexTemplates().get(0);
    CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(mappingStr, is(notNullValue()));
    Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false, XContentType.JSON);
    @SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(decodeMappingValue(mapping.get("dynamic")), is(ColumnPolicy.STRICT));
    execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[] { 6, true, false });
    execute("refresh table numbers");
    Map<String, Object> sourceMap = getSourceMap(new PartitionName(new RelationName("doc", "numbers"), Arrays.asList("true")).asIndexName());
    assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.STRICT));
    assertThrowsMatches(() -> execute("insert into numbers (num, odd, prime, perfect) values (?, ?, ?, ?)", new Object[] { 28, true, false, true }), isSQLError(is("Column perfect unknown"), UNDEFINED_COLUMN, NOT_FOUND, 4043));
}
Also used : PartitionName(io.crate.metadata.PartitionName) XContentType(org.elasticsearch.common.xcontent.XContentType) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) RelationName(io.crate.metadata.RelationName) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 73 with RelationName

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

the class ColumnPolicyIntegrationTest method testResetColumnPolicyPartitioned.

@Test
public void testResetColumnPolicyPartitioned() throws Exception {
    execute("create table dynamic_table (" + "  id integer, " + "  score double" + ") partitioned by (score) with (number_of_replicas=0)");
    ensureYellow();
    execute("insert into dynamic_table (id, score) values (1, 10)");
    execute("refresh table dynamic_table");
    execute("alter table dynamic_table set (column_policy = 'dynamic')");
    waitNoPendingTasksOnAll();
    String indexName = new PartitionName(new RelationName("doc", "dynamic_table"), Arrays.asList("10.0")).asIndexName();
    Map<String, Object> sourceMap = getSourceMap(indexName);
    assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.DYNAMIC));
    execute("alter table dynamic_table reset (column_policy)");
    waitNoPendingTasksOnAll();
    sourceMap = getSourceMap(indexName);
    assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.STRICT));
}
Also used : PartitionName(io.crate.metadata.PartitionName) RelationName(io.crate.metadata.RelationName) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 74 with RelationName

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

the class PartitionedTableIntegrationTest method testInsertPartitionedTableReversedPartitionedColumns.

@Test
public void testInsertPartitionedTableReversedPartitionedColumns() {
    execute("create table parted (" + "   id integer," + "   name string," + "   date timestamp with time zone" + ") partitioned by (name, date)");
    ensureYellow();
    Long dateValue = System.currentTimeMillis();
    execute("insert into parted (id, date, name) values (?, ?, ?)", new Object[] { 1, dateValue, "Trillian" });
    assertThat(response.rowCount(), is(1L));
    ensureYellow();
    refresh();
    String partitionName = new PartitionName(new RelationName(sqlExecutor.getCurrentSchema(), "parted"), Arrays.asList("Trillian", dateValue.toString())).asIndexName();
    assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metadata().indices().get(partitionName).getAliases().get(getFqn("parted")));
}
Also used : PartitionName(io.crate.metadata.PartitionName) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test)

Example 75 with RelationName

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

the class PartitionedTableIntegrationTest method testInsertPartitionedTable.

@Test
public void testInsertPartitionedTable() {
    execute("create table parted (" + "   id integer," + "   name string," + "   date timestamp with time zone" + ") partitioned by (date)");
    ensureYellow();
    String templateName = PartitionName.templateName(sqlExecutor.getCurrentSchema(), "parted");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    assertThat(templatesResponse.getIndexTemplates().get(0).patterns(), contains(is(templateName + "*")));
    assertThat(templatesResponse.getIndexTemplates().get(0).name(), is(templateName));
    assertTrue(templatesResponse.getIndexTemplates().get(0).getAliases().get(getFqn("parted")) != null);
    execute("insert into parted (id, name, date) values (?, ?, ?)", new Object[] { 1, "Ford", 13959981214861L });
    assertThat(response.rowCount(), is(1L));
    ensureYellow();
    refresh();
    assertTrue(clusterService().state().metadata().hasAlias(getFqn("parted")));
    String partitionName = new PartitionName(new RelationName(sqlExecutor.getCurrentSchema(), "parted"), Collections.singletonList(String.valueOf(13959981214861L))).asIndexName();
    Metadata metadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata();
    assertNotNull(metadata.indices().get(partitionName).getAliases().get(getFqn("parted")));
    execute("select id, name, date from parted");
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) response.rows()[0][0], is(1));
    assertThat((String) response.rows()[0][1], is("Ford"));
    assertThat((Long) response.rows()[0][2], is(13959981214861L));
}
Also used : PartitionName(io.crate.metadata.PartitionName) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) MappingMetadata(org.elasticsearch.cluster.metadata.MappingMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test)

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