Search in sources :

Example 56 with SQLExecutor

use of io.crate.testing.SQLExecutor in project crate by crate.

the class SchemasTest method testResolveTableInfoLooksUpRelationInSearchPath.

@Test
public void testResolveTableInfoLooksUpRelationInSearchPath() throws IOException {
    SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t"), "doc", "schema").build();
    QualifiedName tableQn = QualifiedName.of("t");
    SessionContext sessionContext = sqlExecutor.getSessionContext();
    TableInfo tableInfo = sqlExecutor.schemas().resolveTableInfo(tableQn, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
    RelationName relation = tableInfo.ident();
    assertThat(relation.schema(), is("schema"));
    assertThat(relation.name(), is("t"));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) SessionContext(io.crate.action.sql.SessionContext) TableInfo(io.crate.metadata.table.TableInfo) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 57 with SQLExecutor

use of io.crate.testing.SQLExecutor in project crate by crate.

the class SchemasTest method testResolveRelationThrowsRelationUnknownfForInvalidFQN.

@Test
public void testResolveRelationThrowsRelationUnknownfForInvalidFQN() throws IOException {
    SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t"), "schema").build();
    QualifiedName invalidFqn = QualifiedName.of("bogus_schema", "t");
    expectedException.expect(RelationUnknown.class);
    expectedException.expectMessage("Relation 'bogus_schema.t' unknown");
    sqlExecutor.schemas().resolveRelation(invalidFqn, sqlExecutor.getSessionContext().searchPath());
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 58 with SQLExecutor

use of io.crate.testing.SQLExecutor in project crate by crate.

the class CheckConstraintsTest method setUpExecutor.

@Before
public void setUpExecutor() throws Exception {
    SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).addTable("CREATE TABLE t (" + "    id int," + "    qty int," + "    sentinel boolean CONSTRAINT sentinel CHECK(sentinel)," + "    CONSTRAINT id_is_even CHECK(id % 2 = 0))").build();
    DocTableInfo docTableInfo = sqlExecutor.resolveTableInfo("t");
    TransactionContext txnCtx = CoordinatorTxnCtx.systemTransactionContext();
    checkConstraints = new CheckConstraints(txnCtx, new InputFactory(sqlExecutor.nodeCtx), FromSourceRefResolver.WITHOUT_PARTITIONED_BY_REFS, docTableInfo);
}
Also used : InputFactory(io.crate.expression.InputFactory) DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) TransactionContext(io.crate.metadata.TransactionContext) Before(org.junit.Before)

Example 59 with SQLExecutor

use of io.crate.testing.SQLExecutor in project crate by crate.

the class ReturnValueGenTest method setupStatement.

private void setupStatement(String stmt) throws IOException {
    SQLExecutor executor = SQLExecutor.builder(clusterService).addTable(CREATE_TEST_TABLE).build();
    AnalyzedUpdateStatement update = executor.analyze(stmt);
    tableInfo = (DocTableInfo) update.table().tableInfo();
    returnValueGen = new ReturnValueGen(txnCtx, executor.nodeCtx, tableInfo, update.outputs() == null ? null : update.outputs().toArray(new Symbol[0]));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) AnalyzedUpdateStatement(io.crate.analyze.AnalyzedUpdateStatement) Symbol(io.crate.expression.symbol.Symbol)

Example 60 with SQLExecutor

use of io.crate.testing.SQLExecutor in project crate by crate.

the class UpdateSourceGenTest method test_update_child_of_object_column_that_is_null_implicitly_creates_the_object.

@Test
public void test_update_child_of_object_column_that_is_null_implicitly_creates_the_object() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (obj object as (x int))").build();
    AnalyzedUpdateStatement update = e.analyze("update t set obj['x'] = 10");
    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, Collections.singletonMap("obj", null), () -> "{\"obj\": null}"), assignments.sources(), new Object[0]);
    assertThat(updatedSource, is(Map.of("obj", Map.of("x", 10))));
}
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)

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