Search in sources :

Example 6 with Operation

use of org.apache.flink.table.operations.Operation in project flink by apache.

the class SqlToOperationConverter method convertCreateView.

/**
 * Convert CREATE VIEW statement.
 */
private Operation convertCreateView(SqlCreateView sqlCreateView) {
    final SqlNode query = sqlCreateView.getQuery();
    final SqlNodeList fieldList = sqlCreateView.getFieldList();
    UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlCreateView.fullViewName());
    ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
    String comment = sqlCreateView.getComment().map(c -> c.getNlsString().getValue()).orElse(null);
    CatalogView catalogView = convertViewQuery(query, fieldList.getList(), OperationConverterUtils.extractProperties(sqlCreateView.getProperties().orElse(null)), comment);
    return new CreateViewOperation(identifier, catalogView, sqlCreateView.isIfNotExists(), sqlCreateView.isTemporary());
}
Also used : SqlAlterTableReset(org.apache.flink.sql.parser.ddl.SqlAlterTableReset) ModifyOperation(org.apache.flink.table.operations.ModifyOperation) SqlShowCurrentCatalog(org.apache.flink.sql.parser.dql.SqlShowCurrentCatalog) UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) SqlTableOption(org.apache.flink.sql.parser.ddl.SqlTableOption) FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) CatalogTable(org.apache.flink.table.catalog.CatalogTable) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) ShowCurrentDatabaseOperation(org.apache.flink.table.operations.ShowCurrentDatabaseOperation) SqlDropPartitions(org.apache.flink.sql.parser.ddl.SqlDropPartitions) SqlShowViews(org.apache.flink.sql.parser.dql.SqlShowViews) SqlAlterFunction(org.apache.flink.sql.parser.ddl.SqlAlterFunction) SqlEndStatementSet(org.apache.flink.sql.parser.dml.SqlEndStatementSet) SqlRichDescribeTable(org.apache.flink.sql.parser.dql.SqlRichDescribeTable) SqlShowPartitions(org.apache.flink.sql.parser.dql.SqlShowPartitions) Map(java.util.Map) SqlRemoveJar(org.apache.flink.sql.parser.ddl.SqlRemoveJar) FlinkHints(org.apache.flink.table.planner.hint.FlinkHints) CatalogPartitionImpl(org.apache.flink.table.catalog.CatalogPartitionImpl) SqlCreateTable(org.apache.flink.sql.parser.ddl.SqlCreateTable) SqlShowCreateTable(org.apache.flink.sql.parser.dql.SqlShowCreateTable) ExecutePlanOperation(org.apache.flink.table.operations.command.ExecutePlanOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SqlUseModules(org.apache.flink.sql.parser.ddl.SqlUseModules) SqlUseDatabase(org.apache.flink.sql.parser.ddl.SqlUseDatabase) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) SqlChangeColumn(org.apache.flink.sql.parser.ddl.SqlChangeColumn) ShowColumnsOperation(org.apache.flink.table.operations.ShowColumnsOperation) SqlKind(org.apache.calcite.sql.SqlKind) SqlAlterTable(org.apache.flink.sql.parser.ddl.SqlAlterTable) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) Set(java.util.Set) TableSchema(org.apache.flink.table.api.TableSchema) SqlAddReplaceColumns(org.apache.flink.sql.parser.ddl.SqlAddReplaceColumns) CompilePlanOperation(org.apache.flink.table.operations.ddl.CompilePlanOperation) CreateCatalogOperation(org.apache.flink.table.operations.ddl.CreateCatalogOperation) SqlDropDatabase(org.apache.flink.sql.parser.ddl.SqlDropDatabase) ShowCreateViewOperation(org.apache.flink.table.operations.ShowCreateViewOperation) OperationConverterUtils(org.apache.flink.table.planner.utils.OperationConverterUtils) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) FactoryUtil(org.apache.flink.table.factories.FactoryUtil) ShowCatalogsOperation(org.apache.flink.table.operations.ShowCatalogsOperation) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) SqlAlterTableAddConstraint(org.apache.flink.sql.parser.ddl.SqlAlterTableAddConstraint) RichSqlInsert(org.apache.flink.sql.parser.dml.RichSqlInsert) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) CatalogDatabase(org.apache.flink.table.catalog.CatalogDatabase) SqlAlterViewRename(org.apache.flink.sql.parser.ddl.SqlAlterViewRename) QueryOperation(org.apache.flink.table.operations.QueryOperation) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier) SqlAlterDatabase(org.apache.flink.sql.parser.ddl.SqlAlterDatabase) CompileAndExecutePlanOperation(org.apache.flink.table.operations.CompileAndExecutePlanOperation) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl) SqlUnloadModule(org.apache.flink.sql.parser.dql.SqlUnloadModule) DatabaseNotExistException(org.apache.flink.table.catalog.exceptions.DatabaseNotExistException) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SqlShowCreateView(org.apache.flink.sql.parser.dql.SqlShowCreateView) SqlAlterView(org.apache.flink.sql.parser.ddl.SqlAlterView) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) CatalogView(org.apache.flink.table.catalog.CatalogView) Catalog(org.apache.flink.table.catalog.Catalog) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) DropCatalogFunctionOperation(org.apache.flink.table.operations.ddl.DropCatalogFunctionOperation) Expander(org.apache.flink.table.planner.utils.Expander) CalciteSqlDialect(org.apache.calcite.sql.dialect.CalciteSqlDialect) ShowTablesOperation(org.apache.flink.table.operations.ShowTablesOperation) SqlDropTable(org.apache.flink.sql.parser.ddl.SqlDropTable) DescribeTableOperation(org.apache.flink.table.operations.DescribeTableOperation) SqlLoadModule(org.apache.flink.sql.parser.dql.SqlLoadModule) ShowCurrentCatalogOperation(org.apache.flink.table.operations.ShowCurrentCatalogOperation) FunctionScope(org.apache.flink.table.operations.ShowFunctionsOperation.FunctionScope) SqlCreateFunction(org.apache.flink.sql.parser.ddl.SqlCreateFunction) SqlAddJar(org.apache.flink.sql.parser.ddl.SqlAddJar) SqlCreateDatabase(org.apache.flink.sql.parser.ddl.SqlCreateDatabase) TableException(org.apache.flink.table.api.TableException) SqlTableConstraint(org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint) SqlAddPartitions(org.apache.flink.sql.parser.ddl.SqlAddPartitions) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) SqlCompileAndExecutePlan(org.apache.flink.sql.parser.dml.SqlCompileAndExecutePlan) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec) SqlShowColumns(org.apache.flink.sql.parser.dql.SqlShowColumns) SqlCreateView(org.apache.flink.sql.parser.ddl.SqlCreateView) SqlStatementSet(org.apache.flink.sql.parser.dml.SqlStatementSet) SqlShowCurrentDatabase(org.apache.flink.sql.parser.dql.SqlShowCurrentDatabase) AlterPartitionPropertiesOperation(org.apache.flink.table.operations.ddl.AlterPartitionPropertiesOperation) SqlParser(org.apache.calcite.sql.parser.SqlParser) SqlShowFunctions(org.apache.flink.sql.parser.dql.SqlShowFunctions) SqlAlterTableOptions(org.apache.flink.sql.parser.ddl.SqlAlterTableOptions) TableSchemaUtils(org.apache.flink.table.utils.TableSchemaUtils) ShowPartitionsOperation(org.apache.flink.table.operations.ShowPartitionsOperation) Schema(org.apache.flink.table.api.Schema) SqlUseCatalog(org.apache.flink.sql.parser.ddl.SqlUseCatalog) SqlExecutePlan(org.apache.flink.sql.parser.dml.SqlExecutePlan) SqlShowDatabases(org.apache.flink.sql.parser.dql.SqlShowDatabases) SqlDropView(org.apache.flink.sql.parser.ddl.SqlDropView) AlterViewPropertiesOperation(org.apache.flink.table.operations.ddl.AlterViewPropertiesOperation) SqlNode(org.apache.calcite.sql.SqlNode) SqlUtil(org.apache.calcite.sql.SqlUtil) SetOperation(org.apache.flink.table.operations.command.SetOperation) RelHint(org.apache.calcite.rel.hint.RelHint) SqlAlterViewAs(org.apache.flink.sql.parser.ddl.SqlAlterViewAs) SqlAlterTableRename(org.apache.flink.sql.parser.ddl.SqlAlterTableRename) ManagedTableListener(org.apache.flink.table.catalog.ManagedTableListener) SqlDropCatalog(org.apache.flink.sql.parser.ddl.SqlDropCatalog) SqlDropFunction(org.apache.flink.sql.parser.ddl.SqlDropFunction) SqlShowCatalogs(org.apache.flink.sql.parser.dql.SqlShowCatalogs) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) AlterCatalogFunctionOperation(org.apache.flink.table.operations.ddl.AlterCatalogFunctionOperation) SqlAlterTableDropConstraint(org.apache.flink.sql.parser.ddl.SqlAlterTableDropConstraint) SqlCompilePlan(org.apache.flink.sql.parser.ddl.SqlCompilePlan) DropTempSystemFunctionOperation(org.apache.flink.table.operations.ddl.DropTempSystemFunctionOperation) ShowViewsOperation(org.apache.flink.table.operations.ShowViewsOperation) ShowDatabasesOperation(org.apache.flink.table.operations.ShowDatabasesOperation) SqlAlterTableCompact(org.apache.flink.sql.parser.ddl.SqlAlterTableCompact) FunctionLanguage(org.apache.flink.table.catalog.FunctionLanguage) StringUtils(org.apache.flink.util.StringUtils) Collectors(java.util.stream.Collectors) List(java.util.List) SqlShowModules(org.apache.flink.sql.parser.dql.SqlShowModules) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SqlRichExplain(org.apache.flink.sql.parser.dql.SqlRichExplain) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) ValidationException(org.apache.flink.table.api.ValidationException) DropTableOperation(org.apache.flink.table.operations.ddl.DropTableOperation) Optional(java.util.Optional) CatalogViewImpl(org.apache.flink.table.catalog.CatalogViewImpl) AlterViewAsOperation(org.apache.flink.table.operations.ddl.AlterViewAsOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) DropViewOperation(org.apache.flink.table.operations.ddl.DropViewOperation) SqlSet(org.apache.flink.sql.parser.ddl.SqlSet) CatalogManager(org.apache.flink.table.catalog.CatalogManager) SqlAlterViewProperties(org.apache.flink.sql.parser.ddl.SqlAlterViewProperties) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddPartitionsOperation(org.apache.flink.table.operations.ddl.AddPartitionsOperation) RelRoot(org.apache.calcite.rel.RelRoot) HashMap(java.util.HashMap) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) DropPartitionsOperation(org.apache.flink.table.operations.ddl.DropPartitionsOperation) AlterTableAddConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableAddConstraintOperation) HashSet(java.util.HashSet) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) HintStrategyTable(org.apache.calcite.rel.hint.HintStrategyTable) SqlShowTables(org.apache.flink.sql.parser.dql.SqlShowTables) CatalogPartition(org.apache.flink.table.catalog.CatalogPartition) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) SqlBeginStatementSet(org.apache.flink.sql.parser.dml.SqlBeginStatementSet) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) DropCatalogOperation(org.apache.flink.table.operations.ddl.DropCatalogOperation) ContextResolvedTable(org.apache.flink.table.catalog.ContextResolvedTable) SqlReset(org.apache.flink.sql.parser.ddl.SqlReset) SqlShowJars(org.apache.flink.sql.parser.dql.SqlShowJars) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) SqlDialect(org.apache.calcite.sql.SqlDialect) SqlCreateCatalog(org.apache.flink.sql.parser.ddl.SqlCreateCatalog) SqlExecute(org.apache.flink.sql.parser.dml.SqlExecute) ShowCreateTableOperation(org.apache.flink.table.operations.ShowCreateTableOperation) AlterViewRenameOperation(org.apache.flink.table.operations.ddl.AlterViewRenameOperation) CreateCatalogFunctionOperation(org.apache.flink.table.operations.ddl.CreateCatalogFunctionOperation) CreateTempSystemFunctionOperation(org.apache.flink.table.operations.ddl.CreateTempSystemFunctionOperation) SqlNodeList(org.apache.calcite.sql.SqlNodeList) Collections(java.util.Collections) ShowCreateViewOperation(org.apache.flink.table.operations.ShowCreateViewOperation) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) SqlNodeList(org.apache.calcite.sql.SqlNodeList) UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) CatalogView(org.apache.flink.table.catalog.CatalogView) SqlNode(org.apache.calcite.sql.SqlNode) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 7 with Operation

use of org.apache.flink.table.operations.Operation in project flink by apache.

the class SqlToOperationConverter method convertRichExplain.

/**
 * Convert RICH EXPLAIN statement.
 */
private Operation convertRichExplain(SqlRichExplain sqlExplain) {
    SqlNode sqlNode = sqlExplain.getStatement();
    Operation operation;
    if (sqlNode instanceof RichSqlInsert) {
        operation = convertSqlInsert((RichSqlInsert) sqlNode);
    } else if (sqlNode instanceof SqlStatementSet) {
        operation = convertSqlStatementSet((SqlStatementSet) sqlNode);
    } else if (sqlNode.getKind().belongsTo(SqlKind.QUERY)) {
        operation = convertSqlQuery(sqlExplain.getStatement());
    } else {
        throw new ValidationException(String.format("EXPLAIN statement doesn't support %s", sqlNode.getKind()));
    }
    return new ExplainOperation(operation, sqlExplain.getExplainDetails());
}
Also used : ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ValidationException(org.apache.flink.table.api.ValidationException) SqlStatementSet(org.apache.flink.sql.parser.dml.SqlStatementSet) ModifyOperation(org.apache.flink.table.operations.ModifyOperation) ShowCurrentDatabaseOperation(org.apache.flink.table.operations.ShowCurrentDatabaseOperation) ExecutePlanOperation(org.apache.flink.table.operations.command.ExecutePlanOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) ShowColumnsOperation(org.apache.flink.table.operations.ShowColumnsOperation) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) CompilePlanOperation(org.apache.flink.table.operations.ddl.CompilePlanOperation) CreateCatalogOperation(org.apache.flink.table.operations.ddl.CreateCatalogOperation) ShowCreateViewOperation(org.apache.flink.table.operations.ShowCreateViewOperation) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) ShowCatalogsOperation(org.apache.flink.table.operations.ShowCatalogsOperation) 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) CompileAndExecutePlanOperation(org.apache.flink.table.operations.CompileAndExecutePlanOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) DropCatalogFunctionOperation(org.apache.flink.table.operations.ddl.DropCatalogFunctionOperation) ShowTablesOperation(org.apache.flink.table.operations.ShowTablesOperation) DescribeTableOperation(org.apache.flink.table.operations.DescribeTableOperation) ShowCurrentCatalogOperation(org.apache.flink.table.operations.ShowCurrentCatalogOperation) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) AlterPartitionPropertiesOperation(org.apache.flink.table.operations.ddl.AlterPartitionPropertiesOperation) ShowPartitionsOperation(org.apache.flink.table.operations.ShowPartitionsOperation) AlterViewPropertiesOperation(org.apache.flink.table.operations.ddl.AlterViewPropertiesOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) AlterCatalogFunctionOperation(org.apache.flink.table.operations.ddl.AlterCatalogFunctionOperation) DropTempSystemFunctionOperation(org.apache.flink.table.operations.ddl.DropTempSystemFunctionOperation) ShowViewsOperation(org.apache.flink.table.operations.ShowViewsOperation) ShowDatabasesOperation(org.apache.flink.table.operations.ShowDatabasesOperation) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) DropTableOperation(org.apache.flink.table.operations.ddl.DropTableOperation) AlterViewAsOperation(org.apache.flink.table.operations.ddl.AlterViewAsOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) DropViewOperation(org.apache.flink.table.operations.ddl.DropViewOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddPartitionsOperation(org.apache.flink.table.operations.ddl.AddPartitionsOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) DropPartitionsOperation(org.apache.flink.table.operations.ddl.DropPartitionsOperation) 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) DropCatalogOperation(org.apache.flink.table.operations.ddl.DropCatalogOperation) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) ShowCreateTableOperation(org.apache.flink.table.operations.ShowCreateTableOperation) AlterViewRenameOperation(org.apache.flink.table.operations.ddl.AlterViewRenameOperation) CreateCatalogFunctionOperation(org.apache.flink.table.operations.ddl.CreateCatalogFunctionOperation) CreateTempSystemFunctionOperation(org.apache.flink.table.operations.ddl.CreateTempSystemFunctionOperation) RichSqlInsert(org.apache.flink.sql.parser.dml.RichSqlInsert) SqlNode(org.apache.calcite.sql.SqlNode)

Example 8 with Operation

use of org.apache.flink.table.operations.Operation in project flink by apache.

the class SqlToOperationConverterTest method testCreateTableWithMetadataColumn.

@Test
public void testCreateTableWithMetadataColumn() {
    final String sql = "CREATE TABLE tbl1 (\n" + "  a INT,\n" + "  b STRING,\n" + "  c INT METADATA,\n" + "  d INT METADATA FROM 'other.key',\n" + "  e INT METADATA VIRTUAL\n" + ")\n" + "  WITH (\n" + "    'connector' = 'kafka',\n" + "    'kafka.topic' = 'log.test'\n" + ")\n";
    final FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final Operation operation = parse(sql, planner, getParserBySqlDialect(SqlDialect.DEFAULT));
    assertThat(operation).isInstanceOf(CreateTableOperation.class);
    final CreateTableOperation op = (CreateTableOperation) operation;
    final TableSchema actualSchema = op.getCatalogTable().getSchema();
    final TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("a", DataTypes.INT())).add(TableColumn.physical("b", DataTypes.STRING())).add(TableColumn.metadata("c", DataTypes.INT())).add(TableColumn.metadata("d", DataTypes.INT(), "other.key")).add(TableColumn.metadata("e", DataTypes.INT(), true)).build();
    assertThat(actualSchema).isEqualTo(expectedSchema);
}
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) Test(org.junit.Test)

Example 9 with Operation

use of org.apache.flink.table.operations.Operation in project flink by apache.

the class SqlToOperationConverterTest method testCreateTableWithMinusInOptionKey.

@Test
public void testCreateTableWithMinusInOptionKey() {
    final String sql = "create table source_table(\n" + "  a int,\n" + "  b bigint,\n" + "  c varchar\n" + ") with (\n" + "  'a-B-c-d124' = 'Ab',\n" + "  'a.b-c-d.e-f.g' = 'ada',\n" + "  'a.b-c-d.e-f1231.g' = 'ada',\n" + "  'a.b-c-d.*' = 'adad')\n";
    final FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
    SqlNode node = parser.parse(sql);
    assertThat(node).isInstanceOf(SqlCreateTable.class);
    Operation operation = SqlToOperationConverter.convert(planner, catalogManager, node).get();
    assertThat(operation).isInstanceOf(CreateTableOperation.class);
    CreateTableOperation op = (CreateTableOperation) operation;
    CatalogTable catalogTable = op.getCatalogTable();
    Map<String, String> options = catalogTable.getOptions().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    Map<String, String> sortedProperties = new TreeMap<>(options);
    final String expected = "{a-B-c-d124=Ab, " + "a.b-c-d.*=adad, " + "a.b-c-d.e-f.g=ada, " + "a.b-c-d.e-f1231.g=ada}";
    assertThat(sortedProperties.toString()).isEqualTo(expected);
}
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) 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) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 10 with Operation

use of org.apache.flink.table.operations.Operation in project flink by apache.

the class SqlToOperationConverterTest method testUseOneModule.

@Test
public void testUseOneModule() {
    final String sql = "USE MODULES dummy";
    final List<String> expectedModuleNames = Collections.singletonList("dummy");
    Operation operation = parse(sql, SqlDialect.DEFAULT);
    assertThat(operation).isInstanceOf(UseModulesOperation.class);
    final UseModulesOperation useModulesOperation = (UseModulesOperation) operation;
    assertThat(useModulesOperation.getModuleNames()).isEqualTo(expectedModuleNames);
    assertThat(useModulesOperation.asSummaryString()).isEqualTo("USE MODULES: [dummy]");
}
Also used : UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) 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) Test(org.junit.Test)

Aggregations

Operation (org.apache.flink.table.operations.Operation)58 QueryOperation (org.apache.flink.table.operations.QueryOperation)54 ExplainOperation (org.apache.flink.table.operations.ExplainOperation)51 ShowFunctionsOperation (org.apache.flink.table.operations.ShowFunctionsOperation)51 UseDatabaseOperation (org.apache.flink.table.operations.UseDatabaseOperation)51 AlterDatabaseOperation (org.apache.flink.table.operations.ddl.AlterDatabaseOperation)51 CreateDatabaseOperation (org.apache.flink.table.operations.ddl.CreateDatabaseOperation)51 CreateViewOperation (org.apache.flink.table.operations.ddl.CreateViewOperation)51 DropDatabaseOperation (org.apache.flink.table.operations.ddl.DropDatabaseOperation)51 UseCatalogOperation (org.apache.flink.table.operations.UseCatalogOperation)49 AlterTableOptionsOperation (org.apache.flink.table.operations.ddl.AlterTableOptionsOperation)48 AlterTableRenameOperation (org.apache.flink.table.operations.ddl.AlterTableRenameOperation)48 CreateTableOperation (org.apache.flink.table.operations.ddl.CreateTableOperation)48 LoadModuleOperation (org.apache.flink.table.operations.LoadModuleOperation)47 SinkModifyOperation (org.apache.flink.table.operations.SinkModifyOperation)47 StatementSetOperation (org.apache.flink.table.operations.StatementSetOperation)47 UnloadModuleOperation (org.apache.flink.table.operations.UnloadModuleOperation)47 ShowModulesOperation (org.apache.flink.table.operations.ShowModulesOperation)46 SourceQueryOperation (org.apache.flink.table.operations.SourceQueryOperation)46 UseModulesOperation (org.apache.flink.table.operations.UseModulesOperation)46