twalthr commented on a change in pull request #17384:
URL: https://github.com/apache/flink/pull/17384#discussion_r719155446
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/FactoryUtil.java
##########
@@ -125,12 +125,14 @@
public static final String PLACEHOLDER_SYMBOL = "#";
/**
- * Creates a {@link DynamicTableSource} from a {@link CatalogTable}.
+ * Creates a {@link DynamicTableSource}.
Review comment:
I find this comment quite useful.
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
##########
@@ -52,5 +53,23 @@
return Optional.empty();
}
+ /**
+ * Returns a {@link DynamicTableSourceFactory} for creating source tables.
+ *
+ * <p>A factory is determined with the following precedence rule:
+ *
+ * <ul>
+ * <li>1. Factory provided by the catalog.
+ * <li>2. Factory provided by a module.
+ * <li>3. Factory discovery using Java SPI.
+ * </ul>
+ *
Review comment:
Add:
```
This method can be useful to disable Java SPI completely or influence how
temporary table sources should be created without a corresponding catalog.
```
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
##########
@@ -52,5 +53,23 @@
return Optional.empty();
}
+ /**
+ * Returns a {@link DynamicTableSourceFactory} for creating source tables.
+ *
+ * <p>A factory is determined with the following precedence rule:
+ *
+ * <ul>
+ * <li>1. Factory provided by the catalog.
Review comment:
nit: `Factory provided by the corresponding catalog of a persisted table`
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/FactoryUtil.java
##########
@@ -125,12 +125,14 @@
public static final String PLACEHOLDER_SYMBOL = "#";
/**
- * Creates a {@link DynamicTableSource} from a {@link CatalogTable}.
+ * Creates a {@link DynamicTableSource}.
*
- * <p>It considers {@link Catalog#getFactory()} if provided.
+ * <p>If {@param preferredFactory} is passed, the table source is created
from that factory.
+ * Otherwise, an attempt is made to discover a matching factory using Java
SPI (see {@link
+ * Factory} for details).
*/
- public static DynamicTableSource createTableSource(
- @Nullable Catalog catalog,
+ public static DynamicTableSource createSource(
Review comment:
Can we name it `createDynamicTableSource` instead? `Source` sounds like
the core `Source` abstraction.
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java
##########
@@ -52,5 +53,23 @@
return Optional.empty();
}
+ /**
+ * Returns a {@link DynamicTableSourceFactory} for creating source tables.
+ *
+ * <p>A factory is determined with the following precedence rule:
+ *
+ * <ul>
+ * <li>1. Factory provided by the catalog.
+ * <li>2. Factory provided by a module.
+ * <li>3. Factory discovery using Java SPI.
Review comment:
nit: `Factory discovered using Java SPI`
##########
File path:
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/common/CommonExecSink.java
##########
@@ -220,12 +224,14 @@ private int deriveSinkParallelism(
* messages.
*/
private Transformation<RowData> applyKeyBy(
+ PlannerBase planner,
Transformation<RowData> inputTransform,
int[] primaryKeys,
int sinkParallelism,
boolean upsertMaterialize) {
final int inputParallelism = inputTransform.getParallelism();
- if ((inputParallelism == sinkParallelism ||
changelogMode.containsOnly(RowKind.INSERT))
+ if ((inputParallelism == sinkParallelism
+ ||
getOutputChangelogMode(planner).containsOnly(RowKind.INSERT))
Review comment:
can't we just reuse the already discovered table sink in
`createSinkTransformation` and avoid discovery and creation multiple times?
##########
File path:
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/batch/BatchExecSink.java
##########
@@ -43,20 +43,25 @@ public BatchExecSink(
String description) {
super(
tableSinkSpec,
-
tableSinkSpec.getTableSink().getChangelogMode(ChangelogMode.insertOnly()),
true, // isBounded
getNewNodeId(),
Collections.singletonList(inputProperty),
outputType,
description);
}
+ @Override
+ protected ChangelogMode getOutputChangelogMode(PlannerBase planner) {
Review comment:
a sink does not have an output, but a `getConsumedChangelogMode`, do we
really need this method? see comment below.
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/module/ModuleITCase.java
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.planner.runtime.stream.module;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.connector.source.DynamicTableSource;
+import org.apache.flink.table.factories.DynamicTableSourceFactory;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.module.Module;
+import org.apache.flink.table.planner.factories.TableFactoryHarness;
+import org.apache.flink.table.planner.runtime.utils.StreamingTestBase;
+
+import org.junit.Test;
+
+import java.util.Optional;
+import java.util.Set;
+
+import static org.apache.flink.core.testutils.CommonTestUtils.assertThrows;
+
+/** Tests for modules. */
+public class ModuleITCase extends StreamingTestBase {
+
+ @Test
+ public void testTableSourceFactory() {
+ tEnv().createTemporaryTable(
+ "T",
+ TableFactoryHarness.newBuilder()
+ .schema(Schema.newBuilder().build())
+ .source(
+ new
TableFactoryHarness.ScanSourceBase() {
+ @Override
+ public ScanRuntimeProvider
getScanRuntimeProvider(
+ ScanContext
runtimeProviderContext) {
+ throw new
UnsupportedOperationException(
+ "Discovered factory
should not be used");
+ }
+ })
+ .build());
+
+ final Table table = tEnv().from("T");
+
+ // Sanity check: without our module loaded, the factory discovery
process is used.
+ assertThrows(
+ "Discovered factory should not be used",
+ UnsupportedOperationException.class,
+ () -> table.execute().collect());
Review comment:
can `explain` do the job for us? if yes, then this test must not be a
full ITCase with a minicluster
##########
File path: flink-core/src/main/java/org/apache/flink/util/OptionalUtils.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.util;
+
+import org.apache.flink.annotation.Internal;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+/** Utilities for working with {@link Optional}. */
+@Internal
+public class OptionalUtils {
Review comment:
put core changes in a separate hotfix commit
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/module/ModuleManager.java
##########
@@ -44,15 +45,16 @@
* Responsible for loading/unloading modules, managing their life cycles, and
resolving module
* objects.
*/
+@Internal
Review comment:
for the future, please also tag hotfix commits with a component:
`[hotfix][table-api-java] Mark ModuleManager as internal` in this case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]