Search in sources :

Example 6 with FlinkPlannerImpl

use of org.apache.flink.table.planner.calcite.FlinkPlannerImpl in project flink by apache.

the class SqlToOperationConverterTest method testSqlRichExplainWithStatementSet.

@Test
public void testSqlRichExplainWithStatementSet() {
    final String sql = "explain plan for statement set begin " + "insert into t1 select a, b, c, d from t2 where a > 1;" + "insert into t1 select a, b, c, d from t2 where a > 2;" + "end";
    FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
    Operation operation = parse(sql, planner, parser);
    assertThat(operation).isInstanceOf(ExplainOperation.class);
}
Also used : FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) AlterTableAddConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableAddConstraintOperation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) Test(org.junit.Test)

Example 7 with FlinkPlannerImpl

use of org.apache.flink.table.planner.calcite.FlinkPlannerImpl in project flink by apache.

the class SqlToOperationConverterTest method testDynamicTableWithInvalidOptions.

@Test
public void testDynamicTableWithInvalidOptions() {
    final String sql = "select * from t1 /*+ OPTIONS('opt1', 'opt2') */";
    FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
    assertThatThrownBy(() -> parse(sql, planner, parser)).isInstanceOf(AssertionError.class).hasMessageContaining("Hint [OPTIONS] only support " + "non empty key value options");
}
Also used : FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) Test(org.junit.Test)

Example 8 with FlinkPlannerImpl

use of org.apache.flink.table.planner.calcite.FlinkPlannerImpl in project flink by apache.

the class SqlToOperationConverterTest method testCreateTableWithPrimaryKeyEnforced.

@Test
public void testCreateTableWithPrimaryKeyEnforced() {
    final String sql = "CREATE TABLE tbl1 (\n" + "  a bigint,\n" + "  b varchar, \n" + "  c int, \n" + "  d varchar, \n" + // Default is enforced.
    "  constraint ct1 primary key(a, b)\n" + ") with (\n" + "  'connector' = 'kafka', \n" + "  'kafka.topic' = 'log.test'\n" + ")\n";
    FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
    assertThatThrownBy(() -> parse(sql, planner, parser)).isInstanceOf(ValidationException.class).hasMessageContaining("Flink doesn't support ENFORCED mode for PRIMARY KEY " + "constraint. ENFORCED/NOT ENFORCED  controls if the constraint " + "checks are performed on the incoming/outgoing data. " + "Flink does not own the data therefore the only supported mode is the NOT ENFORCED mode");
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) Test(org.junit.Test)

Example 9 with FlinkPlannerImpl

use of org.apache.flink.table.planner.calcite.FlinkPlannerImpl in project flink by apache.

the class SqlToOperationConverterTest method testCreateTableWithPrimaryKey.

@Test
public void testCreateTableWithPrimaryKey() {
    final String sql = "CREATE TABLE tbl1 (\n" + "  a bigint,\n" + "  b varchar, \n" + "  c int, \n" + "  d varchar, \n" + "  constraint ct1 primary key(a, b) not enforced\n" + ") with (\n" + "  'connector' = 'kafka', \n" + "  'kafka.topic' = 'log.test'\n" + ")\n";
    FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
    Operation operation = parse(sql, planner, parser);
    assertThat(operation).isInstanceOf(CreateTableOperation.class);
    CreateTableOperation op = (CreateTableOperation) operation;
    CatalogTable catalogTable = op.getCatalogTable();
    TableSchema tableSchema = catalogTable.getSchema();
    assertThat(tableSchema.getPrimaryKey().map(UniqueConstraint::asSummaryString).orElse("fakeVal")).isEqualTo("CONSTRAINT ct1 PRIMARY KEY (a, b)");
    assertThat(tableSchema.getFieldNames()).isEqualTo(new String[] { "a", "b", "c", "d" });
    assertThat(tableSchema.getFieldDataTypes()).isEqualTo(new DataType[] { DataTypes.BIGINT().notNull(), DataTypes.STRING().notNull(), DataTypes.INT(), DataTypes.STRING() });
}
Also used : TableSchema(org.apache.flink.table.api.TableSchema) FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) AlterTableAddConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableAddConstraintOperation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) CatalogTable(org.apache.flink.table.catalog.CatalogTable) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) Test(org.junit.Test)

Example 10 with FlinkPlannerImpl

use of org.apache.flink.table.planner.calcite.FlinkPlannerImpl in project flink by apache.

the class SqlToOperationConverterTest method testExplainDetailsWithStatementSet.

@Test
public void testExplainDetailsWithStatementSet() {
    final String sql = "explain estimated_cost, changelog_mode statement set begin " + "insert into t1 select a, b, c, d from t2 where a > 1;" + "insert into t1 select a, b, c, d from t2 where a > 2;" + "end";
    FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
    assertExplainDetails(parse(sql, planner, parser));
}
Also used : FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) Test(org.junit.Test)

Aggregations

FlinkPlannerImpl (org.apache.flink.table.planner.calcite.FlinkPlannerImpl)25 CalciteParser (org.apache.flink.table.planner.parse.CalciteParser)23 Test (org.junit.Test)21 Operation (org.apache.flink.table.operations.Operation)17 BeginStatementSetOperation (org.apache.flink.table.operations.BeginStatementSetOperation)16 EndStatementSetOperation (org.apache.flink.table.operations.EndStatementSetOperation)16 ExplainOperation (org.apache.flink.table.operations.ExplainOperation)16 LoadModuleOperation (org.apache.flink.table.operations.LoadModuleOperation)16 QueryOperation (org.apache.flink.table.operations.QueryOperation)16 ShowFunctionsOperation (org.apache.flink.table.operations.ShowFunctionsOperation)16 ShowModulesOperation (org.apache.flink.table.operations.ShowModulesOperation)16 SinkModifyOperation (org.apache.flink.table.operations.SinkModifyOperation)16 SourceQueryOperation (org.apache.flink.table.operations.SourceQueryOperation)16 StatementSetOperation (org.apache.flink.table.operations.StatementSetOperation)16 UnloadModuleOperation (org.apache.flink.table.operations.UnloadModuleOperation)16 UseCatalogOperation (org.apache.flink.table.operations.UseCatalogOperation)16 UseDatabaseOperation (org.apache.flink.table.operations.UseDatabaseOperation)16 UseModulesOperation (org.apache.flink.table.operations.UseModulesOperation)16 AddJarOperation (org.apache.flink.table.operations.command.AddJarOperation)16 RemoveJarOperation (org.apache.flink.table.operations.command.RemoveJarOperation)16