Search in sources :

Example 16 with SQLExecutor

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

Example 17 with SQLExecutor

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

Example 18 with SQLExecutor

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

Example 19 with SQLExecutor

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);
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Symbols(io.crate.expression.symbol.Symbols) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation)

Example 20 with SQLExecutor

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())))));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Symbols(io.crate.expression.symbol.Symbols) 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