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