use of io.crate.testing.SQLExecutor in project crate by crate.
the class TransportSchemaUpdateActionTest method testTemplateMappingUpdateFailsIfTypeIsDifferent.
@Test
public void testTemplateMappingUpdateFailsIfTypeIsDifferent() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addPartitionedTable("create table t (p int) partitioned by (p)").build();
ClusterState currentState = clusterService.state();
PlannerContext plannerContext = e.getPlannerContext(currentState);
BoundAddColumn addXLong = AlterTableAddColumnPlan.bind(e.analyze("alter table t add column x long"), plannerContext.transactionContext(), plannerContext.nodeContext(), Row.EMPTY, SubQueryResults.EMPTY, null);
BoundAddColumn addXString = AlterTableAddColumnPlan.bind(e.analyze("alter table t add column x string"), plannerContext.transactionContext(), plannerContext.nodeContext(), Row.EMPTY, SubQueryResults.EMPTY, null);
String templateName = templateName("doc", "t");
IndexTemplateMetadata template = currentState.metadata().templates().get(templateName);
ClusterState stateWithXLong = ClusterState.builder(currentState).metadata(Metadata.builder(currentState.metadata()).put(IndexTemplateMetadata.builder(templateName).patterns(template.patterns()).putMapping(Constants.DEFAULT_MAPPING_TYPE, Strings.toString(JsonXContent.contentBuilder().map(addXLong.mapping())))).build()).build();
expectedException.expect(IllegalArgumentException.class);
TransportSchemaUpdateAction.updateTemplate(NamedXContentRegistry.EMPTY, stateWithXLong, templateName, addXString.mapping());
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class DeletePartitionsTest method testIndexNameGeneration.
@Test
public void testIndexNameGeneration() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addPartitionedTable(TableDefinitions.PARTED_PKS_TABLE_DEFINITION, new PartitionName(new RelationName("doc", "parted_pks"), singletonList("1395874800000")).asIndexName(), new PartitionName(new RelationName("doc", "parted_pks"), singletonList("1395961200000")).asIndexName()).build();
DeletePartitions plan = e.plan("delete from parted_pks where date = ?");
Object[] args1 = { "1395874800000" };
assertThat(plan.getIndices(txnCtx, e.nodeCtx, new RowN(args1), SubQueryResults.EMPTY), Matchers.containsInAnyOrder(".partitioned.parted_pks.04732cpp6ks3ed1o60o30c1g"));
Object[] args2 = { "1395961200000" };
assertThat(plan.getIndices(txnCtx, e.nodeCtx, new RowN(args2), SubQueryResults.EMPTY), Matchers.containsInAnyOrder(".partitioned.parted_pks.04732cpp6ksjcc9i60o30c1g"));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class FetchRewriteTest method test_fetchrewrite_on_eval_with_nested_source_outputs.
@Test
public void test_fetchrewrite_on_eval_with_nested_source_outputs() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
DocTableInfo tableInfo = e.resolveTableInfo("tbl");
var x = new AliasSymbol("x_alias", e.asSymbol("x"));
var relation = new DocTableRelation(tableInfo);
var collect = new Collect(relation, List.of(x), WhereClause.MATCH_ALL, 1L, DataTypes.INTEGER.fixedSize());
var eval = new Eval(collect, List.of(x));
FetchRewrite fetchRewrite = eval.rewriteToFetch(new TableStats(), List.of());
assertThat(fetchRewrite, Matchers.notNullValue());
assertThat(fetchRewrite.newPlan(), isPlan("Collect[doc.tbl | [_fetchid] | true]"));
assertThat(fetchRewrite.replacedOutputs(), Matchers.hasEntry(is(x), isAlias("x_alias", isFetchStub("_doc['x']"))));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class FetchRewriteTest method test_fetch_rewrite_on_eval_removes_eval_and_extends_replaced_outputs.
@Test
public void test_fetch_rewrite_on_eval_removes_eval_and_extends_replaced_outputs() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
DocTableInfo tableInfo = e.resolveTableInfo("tbl");
var x = e.asSymbol("x");
var relation = new DocTableRelation(tableInfo);
var collect = new Collect(relation, List.of(x), WhereClause.MATCH_ALL, 1L, DataTypes.INTEGER.fixedSize());
var eval = new Eval(collect, List.of(new Function(Signature.scalar("add", DataTypes.INTEGER.getTypeSignature(), DataTypes.INTEGER.getTypeSignature(), DataTypes.INTEGER.getTypeSignature()), List.of(x, x), DataTypes.INTEGER)));
FetchRewrite fetchRewrite = eval.rewriteToFetch(new TableStats(), List.of());
assertThat(fetchRewrite, Matchers.notNullValue());
assertThat(fetchRewrite.newPlan(), isPlan("Collect[doc.tbl | [_fetchid] | true]"));
assertThat(fetchRewrite.replacedOutputs(), Matchers.hasEntry(isFunction("add", isReference("x"), isReference("x")), isFunction("add", isFetchStub("_doc['x']"), isFetchStub("_doc['x']"))));
assertThat(List.copyOf(fetchRewrite.replacedOutputs().keySet()), is(eval.outputs()));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class MapBackedSymbolReplacerTest method test_convert_symbol_without_traversing.
@Test
public void test_convert_symbol_without_traversing() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
Symbol x = e.asSymbol("x");
Symbol x_source_lookup = e.asSymbol("_doc['x']");
Symbol alias = new AliasSymbol("a_alias", x);
Symbol alias_source_lookup = new AliasSymbol("a_alias", x_source_lookup);
// Mapping contains the requested symbol directly, must not traverse alias symbols
Map<Symbol, Symbol> mapping = Map.of(alias, alias_source_lookup);
assertThat(MapBackedSymbolReplacer.convert(alias, mapping), is(alias_source_lookup));
}
Aggregations