use of io.crate.testing.SQLExecutor in project crate by crate.
the class SymbolToColumnDefinitionConverterTest method testEntireObjectToColumDefinition.
@Test
public void testEntireObjectToColumDefinition() throws IOException {
String createTableStmt = "create table tbl (" + " col_default_object object as (" + " col_nested_integer integer," + " col_nested_object object as (" + " col_nested_timestamp_with_time_zone timestamp with time zone" + " )" + " )" + ")";
SQLExecutor e = SQLExecutor.builder(clusterService).addTable(createTableStmt).build();
AnalyzedRelation analyzedRelation = e.analyze("select col_default_object from tbl");
var actual = Lists2.map(analyzedRelation.outputs(), Symbols::toColumnDefinition);
assertThat(actual.get(0), isColumnDefinition("col_default_object", isObjectColumnType(DataTypes.UNTYPED_OBJECT.getName(), isColumnPolicy(OBJECT_TYPE_DEFAULT_COLUMN_POLICY), containsInAnyOrder(isColumnDefinition("col_nested_integer", isColumnType(DataTypes.INTEGER.getName())), isColumnDefinition("col_nested_object", isObjectColumnType(DataTypes.UNTYPED_OBJECT.getName(), isColumnPolicy(OBJECT_TYPE_DEFAULT_COLUMN_POLICY), contains(isColumnDefinition("col_nested_timestamp_with_time_zone", isColumnType(DataTypes.TIMESTAMPZ.getName())))))))));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class SymbolToColumnDefinitionConverterTest method testSymbolFromViewToColumnDefinition.
@Test
public void testSymbolFromViewToColumnDefinition() throws IOException {
String createTableStmt = "create table tbl (" + " col_default_object object as (" + " col_nested_integer integer," + " col_nested_object object as (" + " col_nested_timestamp_with_time_zone timestamp with time zone" + " )" + " )" + ")";
SQLExecutor e = SQLExecutor.builder(clusterService).addTable(createTableStmt).addView(new RelationName("doc", "tbl_view"), "select * from doc.tbl").build();
String selectStmt = "select " + " col_default_object['col_nested_integer'] as col1, " + " col_default_object['col_nested_object']['col_nested_timestamp_with_time_zone'] as col2, " + " col_default_object['col_nested_object'] as col3 " + "from tbl_view";
var analyzedRelation = e.analyze(selectStmt);
var actual = Lists2.map(analyzedRelation.outputs(), Symbols::toColumnDefinition);
assertThat(actual, containsInAnyOrder(isColumnDefinition("col1", isColumnType(DataTypes.INTEGER.getName())), isColumnDefinition("col2", isColumnType(DataTypes.TIMESTAMPZ.getName())), isColumnDefinition("col3", isObjectColumnType(DataTypes.UNTYPED_OBJECT.getName(), isColumnPolicy(OBJECT_TYPE_DEFAULT_COLUMN_POLICY), contains(isColumnDefinition("col_nested_timestamp_with_time_zone", isColumnType(DataTypes.TIMESTAMPZ.getName())))))));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class SymbolToColumnDefinitionConverterTest method testSubFieldOfObjectTypeToColumnDefinition.
@Test
public void testSubFieldOfObjectTypeToColumnDefinition() throws IOException {
String createTableStmt = "create table tbl (" + " col_default_object object as (" + " col_nested_integer integer," + " col_nested_object object as (" + " col_nested_timestamp_with_time_zone timestamp with time zone" + " )" + " )" + ")";
SQLExecutor e = SQLExecutor.builder(clusterService).addTable(createTableStmt).build();
String selectStmt = "select " + " col_default_object['col_nested_integer'], " + " col_default_object['col_nested_object']['col_nested_timestamp_with_time_zone'], " + " col_default_object['col_nested_object']" + "from tbl";
var analyzedRelation = e.analyze(selectStmt);
var actual = Lists2.map(analyzedRelation.outputs(), Symbols::toColumnDefinition);
assertThat(actual, containsInAnyOrder(isColumnDefinition("col_default_object['col_nested_integer']", isColumnType(DataTypes.INTEGER.getName())), isColumnDefinition("col_default_object['col_nested_object']['col_nested_timestamp_with_time_zone']", isColumnType(DataTypes.TIMESTAMPZ.getName())), isColumnDefinition("col_default_object['col_nested_object']", isObjectColumnType(DataTypes.UNTYPED_OBJECT.getName(), isColumnPolicy(OBJECT_TYPE_DEFAULT_COLUMN_POLICY), contains(isColumnDefinition("col_nested_timestamp_with_time_zone", isColumnType(DataTypes.TIMESTAMPZ.getName())))))));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class SelectStatementAnalyzerTest method testCustomSchemaSubSelectWithAccessToParentRelation.
@Test
public void testCustomSchemaSubSelectWithAccessToParentRelation() throws Exception {
var executor = SQLExecutor.builder(clusterService).addTable(T3.T1_DEFINITION).build();
SQLExecutor sqlExecutor2 = SQLExecutor.builder(clusterService).setSearchPath("foo").addTable("create table foo.t1 (id bigint primary key, name text)").build();
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("Cannot use relation \"foo.t1\" in this context. It is only accessible in the parent context");
sqlExecutor2.analyze("select * from t1 where id = (select 1 from t1 as x where x.id = t1.id)");
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class SelectStatementAnalyzerTest method testQueryUsesSearchPath.
@Test
public void testQueryUsesSearchPath() throws IOException {
SQLExecutor executor = SQLExecutor.builder(clusterService).setSearchPath("first", "second", "third").addTable("create table \"first\".t (id int)").addTable("create table third.t1 (id int)").build();
QueriedSelectRelation queriedTable = executor.analyze("select * from t");
assertThat(queriedTable.from(), contains(isDocTable(new RelationName("first", "t"))));
queriedTable = executor.analyze("select * from t1");
assertThat(queriedTable.from(), contains(isDocTable(new RelationName("third", "t1"))));
}
Aggregations