Search in sources :

Example 61 with SQLExecutor

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]);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) AnalyzedUpdateStatement(io.crate.analyze.AnalyzedUpdateStatement) Assignments(io.crate.expression.symbol.Assignments) Doc(io.crate.expression.reference.Doc) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 62 with SQLExecutor

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)));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) AnalyzedUpdateStatement(io.crate.analyze.AnalyzedUpdateStatement) Assignments(io.crate.expression.symbol.Assignments) Doc(io.crate.expression.reference.Doc) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 63 with SQLExecutor

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));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 64 with SQLExecutor

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);
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Before(org.junit.Before)

Aggregations

SQLExecutor (io.crate.testing.SQLExecutor)64 Test (org.junit.Test)55 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)54 DocTableInfo (io.crate.metadata.doc.DocTableInfo)24 RelationName (io.crate.metadata.RelationName)9 AnalyzedUpdateStatement (io.crate.analyze.AnalyzedUpdateStatement)8 Doc (io.crate.expression.reference.Doc)8 Assignments (io.crate.expression.symbol.Assignments)7 Symbols (io.crate.expression.symbol.Symbols)7 CreateTable (io.crate.sql.tree.CreateTable)7 TableStats (io.crate.statistics.TableStats)7 Before (org.junit.Before)7 Symbol (io.crate.expression.symbol.Symbol)6 ViewsMetadataTest (io.crate.metadata.view.ViewsMetadataTest)6 QualifiedName (io.crate.sql.tree.QualifiedName)6 DocTableRelation (io.crate.analyze.relations.DocTableRelation)5 SessionContext (io.crate.action.sql.SessionContext)4 AliasSymbol (io.crate.expression.symbol.AliasSymbol)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 PlannerContext (io.crate.planner.PlannerContext)3