You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ja...@apache.org on 2023/03/17 07:05:04 UTC
[flink] branch ExecutableOperation created (now 768c09c5183)
This is an automated email from the ASF dual-hosted git repository.
jark pushed a change to branch ExecutableOperation
in repository https://gitbox.apache.org/repos/asf/flink.git
at 768c09c5183 [FLINK-31450][table] Move execution logic of UseOperations out from TableEnvironmentImpl
This branch includes the following new commits:
new d95f69bb459 [FLINK-31450][table] Introduce ExecutableOperation for operations to execute
new 768c09c5183 [FLINK-31450][table] Move execution logic of UseOperations out from TableEnvironmentImpl
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[flink] 02/02: [FLINK-31450][table] Move execution logic of UseOperations out from TableEnvironmentImpl
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jark pushed a commit to branch ExecutableOperation
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 768c09c5183c47692bd4af6968fd0381b7a0a006
Author: Jark Wu <ja...@apache.org>
AuthorDate: Tue Mar 14 17:55:53 2023 +0800
[FLINK-31450][table] Move execution logic of UseOperations out from TableEnvironmentImpl
This closes #22175
---
.../table/api/internal/TableEnvironmentImpl.java | 13 -------------
.../flink/table/operations/UseCatalogOperation.java | 11 ++++++++++-
.../flink/table/operations/UseDatabaseOperation.java | 10 ++++++++++
.../flink/table/operations/UseModulesOperation.java | 20 ++++++++++++++++++--
.../apache/flink/table/operations/UseOperation.java | 2 +-
5 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
index 90c1cd24701..f5871f08dc3 100644
--- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
@@ -115,8 +115,6 @@ import org.apache.flink.table.operations.SourceQueryOperation;
import org.apache.flink.table.operations.StatementSetOperation;
import org.apache.flink.table.operations.TableSourceQueryOperation;
import org.apache.flink.table.operations.UnloadModuleOperation;
-import org.apache.flink.table.operations.UseCatalogOperation;
-import org.apache.flink.table.operations.UseDatabaseOperation;
import org.apache.flink.table.operations.UseModulesOperation;
import org.apache.flink.table.operations.command.AddJarOperation;
import org.apache.flink.table.operations.command.ExecutePlanOperation;
@@ -1233,17 +1231,6 @@ public class TableEnvironmentImpl implements TableEnvironmentInternal {
return loadModule((LoadModuleOperation) operation);
} else if (operation instanceof UnloadModuleOperation) {
return unloadModule((UnloadModuleOperation) operation);
- } else if (operation instanceof UseModulesOperation) {
- return useModules((UseModulesOperation) operation);
- } else if (operation instanceof UseCatalogOperation) {
- UseCatalogOperation useCatalogOperation = (UseCatalogOperation) operation;
- catalogManager.setCurrentCatalog(useCatalogOperation.getCatalogName());
- return TableResultImpl.TABLE_RESULT_OK;
- } else if (operation instanceof UseDatabaseOperation) {
- UseDatabaseOperation useDatabaseOperation = (UseDatabaseOperation) operation;
- catalogManager.setCurrentCatalog(useDatabaseOperation.getCatalogName());
- catalogManager.setCurrentDatabase(useDatabaseOperation.getDatabaseName());
- return TableResultImpl.TABLE_RESULT_OK;
} else if (operation instanceof ShowCatalogsOperation) {
return buildShowResult("catalog name", listCatalogs());
} else if (operation instanceof ShowCreateTableOperation) {
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseCatalogOperation.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseCatalogOperation.java
index c442fc5daba..c77e589ce65 100644
--- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseCatalogOperation.java
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseCatalogOperation.java
@@ -18,10 +18,13 @@
package org.apache.flink.table.operations;
+import org.apache.flink.table.api.internal.TableResultImpl;
+import org.apache.flink.table.api.internal.TableResultInternal;
+
/** Operation to describe a USE CATALOG statement. */
public class UseCatalogOperation implements UseOperation {
- private String catalogName;
+ private final String catalogName;
public UseCatalogOperation(String catalogName) {
this.catalogName = catalogName;
@@ -35,4 +38,10 @@ public class UseCatalogOperation implements UseOperation {
public String asSummaryString() {
return String.format("USE CATALOG %s", catalogName);
}
+
+ @Override
+ public TableResultInternal execute(Context ctx) {
+ ctx.getCatalogManager().setCurrentCatalog(catalogName);
+ return TableResultImpl.TABLE_RESULT_OK;
+ }
}
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseDatabaseOperation.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseDatabaseOperation.java
index f0b96424062..190e32d8160 100644
--- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseDatabaseOperation.java
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseDatabaseOperation.java
@@ -18,6 +18,9 @@
package org.apache.flink.table.operations;
+import org.apache.flink.table.api.internal.TableResultImpl;
+import org.apache.flink.table.api.internal.TableResultInternal;
+
/** Operation to describe a USE [catalogName.]dataBaseName statement. */
public class UseDatabaseOperation implements UseOperation {
@@ -41,4 +44,11 @@ public class UseDatabaseOperation implements UseOperation {
public String asSummaryString() {
return String.format("USE %s.%s", catalogName, databaseName);
}
+
+ @Override
+ public TableResultInternal execute(Context ctx) {
+ ctx.getCatalogManager().setCurrentCatalog(catalogName);
+ ctx.getCatalogManager().setCurrentDatabase(databaseName);
+ return TableResultImpl.TABLE_RESULT_OK;
+ }
}
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseModulesOperation.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseModulesOperation.java
index decdd770d66..6f540584430 100644
--- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseModulesOperation.java
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseModulesOperation.java
@@ -18,6 +18,10 @@
package org.apache.flink.table.operations;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.TableResultImpl;
+import org.apache.flink.table.api.internal.TableResultInternal;
+
import java.util.Collections;
import java.util.List;
@@ -26,15 +30,27 @@ public class UseModulesOperation implements UseOperation {
private final List<String> moduleNames;
public UseModulesOperation(List<String> moduleNames) {
- this.moduleNames = moduleNames;
+ this.moduleNames = Collections.unmodifiableList(moduleNames);
}
public List<String> getModuleNames() {
- return Collections.unmodifiableList(moduleNames);
+ return moduleNames;
}
@Override
public String asSummaryString() {
return String.format("USE MODULES: %s", moduleNames);
}
+
+ @Override
+ public TableResultInternal execute(Context ctx) {
+ try {
+ ctx.getModuleManager().useModules(moduleNames.toArray(new String[0]));
+ return TableResultImpl.TABLE_RESULT_OK;
+ } catch (ValidationException e) {
+ throw new ValidationException(
+ String.format("Could not execute %s. %s", asSummaryString(), e.getMessage()),
+ e);
+ }
+ }
}
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseOperation.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseOperation.java
index efc6a899fdd..e99b2a51ed9 100644
--- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseOperation.java
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/UseOperation.java
@@ -29,4 +29,4 @@ import org.apache.flink.annotation.Internal;
* switching current database.
*/
@Internal
-public interface UseOperation extends Operation {}
+public interface UseOperation extends Operation, ExecutableOperation {}
[flink] 01/02: [FLINK-31450][table] Introduce ExecutableOperation for operations to execute
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jark pushed a commit to branch ExecutableOperation
in repository https://gitbox.apache.org/repos/asf/flink.git
commit d95f69bb459b5efb44c7cd468485d85cd08aef50
Author: Jark Wu <ja...@apache.org>
AuthorDate: Tue Mar 14 17:54:48 2023 +0800
[FLINK-31450][table] Introduce ExecutableOperation for operations to execute
This closes #22175
---
.../internal/ExecutableOperationContextImpl.java | 46 +++++++++++++++++
.../table/api/internal/TableEnvironmentImpl.java | 9 ++++
.../table/operations/ExecutableOperation.java | 58 ++++++++++++++++++++++
3 files changed, 113 insertions(+)
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/ExecutableOperationContextImpl.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/ExecutableOperationContextImpl.java
new file mode 100644
index 00000000000..6cc41d7843c
--- /dev/null
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/ExecutableOperationContextImpl.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.api.internal;
+
+import org.apache.flink.table.catalog.CatalogManager;
+import org.apache.flink.table.module.ModuleManager;
+import org.apache.flink.table.operations.ExecutableOperation;
+
+/** A simple implementation of {@link ExecutableOperation.Context}. */
+public class ExecutableOperationContextImpl implements ExecutableOperation.Context {
+
+ private final CatalogManager catalogManager;
+ private final ModuleManager moduleManager;
+
+ public ExecutableOperationContextImpl(
+ CatalogManager catalogManager, ModuleManager moduleManager) {
+ this.catalogManager = catalogManager;
+ this.moduleManager = moduleManager;
+ }
+
+ @Override
+ public CatalogManager getCatalogManager() {
+ return catalogManager;
+ }
+
+ @Override
+ public ModuleManager getModuleManager() {
+ return moduleManager;
+ }
+}
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
index b43123a0072..90c1cd24701 100644
--- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
@@ -91,6 +91,7 @@ import org.apache.flink.table.operations.CompileAndExecutePlanOperation;
import org.apache.flink.table.operations.CreateTableASOperation;
import org.apache.flink.table.operations.DeleteFromFilterOperation;
import org.apache.flink.table.operations.DescribeTableOperation;
+import org.apache.flink.table.operations.ExecutableOperation;
import org.apache.flink.table.operations.ExplainOperation;
import org.apache.flink.table.operations.LoadModuleOperation;
import org.apache.flink.table.operations.ModifyOperation;
@@ -203,6 +204,7 @@ public class TableEnvironmentImpl implements TableEnvironmentInternal {
protected final FunctionCatalog functionCatalog;
protected final Planner planner;
private final boolean isStreamingMode;
+ private final ExecutableOperation.Context operationCtx;
private static final String UNSUPPORTED_QUERY_IN_EXECUTE_SQL_MSG =
"Unsupported SQL query! executeSql() only accepts a single SQL statement of type "
@@ -262,6 +264,7 @@ public class TableEnvironmentImpl implements TableEnvironmentInternal {
isStreamingMode);
catalogManager.initSchemaResolver(
isStreamingMode, operationTreeBuilder.getResolverBuilder());
+ this.operationCtx = new ExecutableOperationContextImpl(catalogManager, moduleManager);
}
public static TableEnvironmentImpl create(Configuration configuration) {
@@ -984,6 +987,12 @@ public class TableEnvironmentImpl implements TableEnvironmentInternal {
if (tableResult.isPresent()) {
return tableResult.get();
}
+
+ // delegate execution to Operation if it implements ExecutableOperation
+ if (operation instanceof ExecutableOperation) {
+ return ((ExecutableOperation) operation).execute(operationCtx);
+ }
+
// otherwise, fall back to internal implementation
if (operation instanceof ModifyOperation) {
return executeInternal(Collections.singletonList((ModifyOperation) operation));
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ExecutableOperation.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ExecutableOperation.java
new file mode 100644
index 00000000000..ae542de7ad4
--- /dev/null
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ExecutableOperation.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.operations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogManager;
+import org.apache.flink.table.module.ModuleManager;
+
+/**
+ * An {@link ExecutableOperation} represents an operation that is executed for its side effects.
+ *
+ * <p>This internal interface is proposed to reduce the maintenance of bloated {@link
+ * TableEnvironmentImpl#executeInternal(Operation)} and improve code readability as execution logic
+ * is co-located with the operation definition. Besides, this interface can be used to extend
+ * user-defined operation with customized execution logic once this interface is stable and public
+ * in the future.
+ */
+@Internal
+public interface ExecutableOperation extends Operation {
+
+ /**
+ * Executes the given operation and return the execution result.
+ *
+ * @param ctx the context to execute the operation.
+ * @return the content of the execution result.
+ * @see org.apache.flink.table.api.internal.TableEnvironmentInternal#executeInternal(Operation)
+ */
+ TableResultInternal execute(Context ctx);
+
+ /**
+ * The context to execute the operation. Operation may make side effect to the context, e.g.
+ * catalog manager, configuration.
+ */
+ interface Context {
+
+ CatalogManager getCatalogManager();
+
+ ModuleManager getModuleManager();
+ }
+}