use of io.crate.testing.SQLExecutor in project crate by crate.
the class UpdateSourceGenTest method testNestedGeneratedColumnRaiseErrorIfGivenByUserDoesNotMatch.
@Test
public void testNestedGeneratedColumnRaiseErrorIfGivenByUserDoesNotMatch() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (x int, obj object as (y as 'foo'))").build();
AnalyzedUpdateStatement update = e.analyze("update t set x = 4, obj = {y='bar'}");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
DocTableInfo table = (DocTableInfo) update.table().tableInfo();
UpdateSourceGen updateSourceGen = new UpdateSourceGen(txnCtx, e.nodeCtx, table, assignments.targetNames());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Given value bar for generated column obj['y'] does not match calculation 'foo' = foo");
updateSourceGen.generateSource(new Doc(1, table.concreteIndices()[0], "1", 1, 1, 1, emptyMap(), () -> "{}"), assignments.sources(), new Object[0]);
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class UpdateSourceGenTest method testNestedGeneratedColumnIsGenerated.
@Test
public void testNestedGeneratedColumnIsGenerated() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (x int, obj object as (y as x + 1))").build();
AnalyzedUpdateStatement update = e.analyze("update t set x = 4");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
DocTableInfo table = (DocTableInfo) update.table().tableInfo();
UpdateSourceGen updateSourceGen = new UpdateSourceGen(txnCtx, e.nodeCtx, table, assignments.targetNames());
Map<String, Object> updatedSource = updateSourceGen.generateSource(new Doc(1, table.concreteIndices()[0], "1", 1, 1, 1, emptyMap(), () -> "{}"), assignments.sources(), new Object[0]);
assertThat(updatedSource, is(Map.of("obj", Map.of("y", 5), "x", 4)));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class DiscardTest method test_discard_with_all_modifiers_results_in_noop_plan.
@Test
public void test_discard_with_all_modifiers_results_in_noop_plan() throws Exception {
// discard is for discarding the session state and needs special handling in `Session`
// The planner always returns a noopPlan
SQLExecutor e = SQLExecutor.builder(clusterService).build();
assertThat(e.plan("DISCARD ALL"), Matchers.sameInstance(NoopPlan.INSTANCE));
assertThat(e.plan("DISCARD PLANS"), Matchers.sameInstance(NoopPlan.INSTANCE));
assertThat(e.plan("DISCARD SEQUENCES"), Matchers.sameInstance(NoopPlan.INSTANCE));
assertThat(e.plan("DISCARD TEMPORARY"), Matchers.sameInstance(NoopPlan.INSTANCE));
assertThat(e.plan("DISCARD TEMP"), Matchers.sameInstance(NoopPlan.INSTANCE));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class RoutingBuilderTest method prepare.
@Before
public void prepare() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService, 2, Randomness.get(), List.of()).addTable("create table custom.t1 (id int)").build();
tableInfo = e.schemas().getTableInfo(relationName);
}
Aggregations