use of io.crate.testing.SQLExecutor in project crate by crate.
the class UserDefinedFunctionServiceTest method test_validate_partitioned_table_while_dropping_udf.
@Test
public void test_validate_partitioned_table_while_dropping_udf() throws Exception {
UserDefinedFunctionsMetadata metadataWithoutFunction = UserDefinedFunctionsMetadata.of();
SQLExecutor executor = SQLExecutor.builder(clusterService).addUDFLanguage(DUMMY_LANG).addUDF(FOO).addPartitionedTable("create table doc.p1 (id int, p int, gen as foo(id)) partitioned by (p)").build();
Assertions.assertThrows(IllegalArgumentException.class, () -> executor.udfService().validateFunctionIsNotInUseByGeneratedColumn(Schemas.DOC_SCHEMA_NAME, "foo", metadataWithoutFunction, clusterService.state()), "Cannot drop function 'foo', it is still in use by 'doc.p1.gen AS doc.foo(id)'");
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class UserDefinedFunctionServiceTest method test_validate_table_while_dropping_udf.
@Test
public void test_validate_table_while_dropping_udf() throws Exception {
UserDefinedFunctionsMetadata metadataWithoutFunction = UserDefinedFunctionsMetadata.of();
SQLExecutor executor = SQLExecutor.builder(clusterService).addUDFLanguage(DUMMY_LANG).addUDF(FOO).addTable("create table doc.t1 (id int, gen as foo(id))").build();
Assertions.assertThrows(IllegalArgumentException.class, () -> executor.udfService().validateFunctionIsNotInUseByGeneratedColumn(Schemas.DOC_SCHEMA_NAME, "foo", metadataWithoutFunction, clusterService.state()), "Cannot drop function 'foo', it is still in use by 'doc.t1.gen AS doc.foo(id)'");
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class SymbolToColumnDefinitionConverterTest method testAliasedNameToColumnDefinition.
@Test
public void testAliasedNameToColumnDefinition() 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'] 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";
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 getAllColumnDefinitionsFrom.
private List<ColumnDefinition<Expression>> getAllColumnDefinitionsFrom(String createTableStmt) throws IOException {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable(createTableStmt).build();
AnalyzedRelation analyzedRelation = e.analyze("select * from tbl");
return Lists2.map(analyzedRelation.outputs(), Symbols::toColumnDefinition);
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class SymbolToColumnDefinitionConverterTest method testTypeCastedSymbolToColumnDefinition.
@Test
public void testTypeCastedSymbolToColumnDefinition() {
// check for naming of the target columns
String selectStmt = "select cast([0,1,5] as array(boolean)) AS active_threads, " + " cast(port['http']as boolean) from sys.nodes limit 1 ";
SQLExecutor e = SQLExecutor.builder(clusterService).build();
var analyzedRelation = e.analyze(selectStmt);
var actual = Lists2.map(analyzedRelation.outputs(), Symbols::toColumnDefinition);
assertThat(actual, containsInAnyOrder(isColumnDefinition("cast(port['http'] AS boolean)", isColumnType(DataTypes.BOOLEAN.getName())), isColumnDefinition("active_threads", isCollectionColumnType(ArrayType.NAME.toUpperCase(), isColumnType(DataTypes.BOOLEAN.getName())))));
}
Aggregations