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