You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "reswqa (via GitHub)" <gi...@apache.org> on 2023/02/20 17:56:17 UTC
[GitHub] [flink] reswqa opened a new pull request, #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
reswqa opened a new pull request, #21977:
URL: https://github.com/apache/flink/pull/21977
## What is the purpose of the change
*If the parallelism of compact operator was not set, it should use the sink parallelism and disable parallelism inference when using adaptive batch scheduler to avoid take much time to finish compaction.*
## Brief change log
- *Expose StreamNode#isParallelismConfigured for testing.*
- *Let hive compact operator without setting parallelism subject to sink operator's configured parallelism.*
## Verifying this change
This change added test `HiveTableCompactSinkTest`.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112641083
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkITCase.java:
##########
@@ -42,17 +44,18 @@
import static org.assertj.core.api.Assertions.assertThat;
/** IT case for Hive table compaction in batch mode. */
-public class HiveTableCompactSinkITCase {
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkITCase {
@RegisterExtension
- private static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
+ public static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
Review Comment:
TBH, The reason I changed it is only to follow the usage in the `MiniClusterExtension` class [javadoc](https://github.com/apache/flink/blob/bacdc326b58749924acbd8921d63eda06663a225/flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/junit5/MiniClusterExtension.java#L70).
At the same time, in the `architecture check` of IT case, we can see similar [requirement](https://github.com/apache/flink/blob/bacdc326b58749924acbd8921d63eda06663a225/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/rules/ITCaseRules.java#L67). Unfortunately, I looked at the actual check logic and didn't seem to require it to be public, which really confused me.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112512579
##########
flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/batch/BatchSink.java:
##########
@@ -52,6 +52,11 @@
/** Helper for creating batch file sink. */
@Internal
public class BatchSink {
+
+ public static final String COORDINATOR_OP_NAME = "coordinator";
Review Comment:
```suggestion
public static final String COORDINATOR_OP_NAME = "compact-coordinator";
```
##########
flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/batch/BatchSink.java:
##########
@@ -52,6 +52,11 @@
/** Helper for creating batch file sink. */
@Internal
public class BatchSink {
+
+ public static final String COORDINATOR_OP_NAME = "coordinator";
+
+ public static final String COMPACT_OP_NAME = "compact";
Review Comment:
```suggestion
public static final String COMPACT_OP_NAME = "compact-operator";
```
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkITCase.java:
##########
@@ -42,17 +44,18 @@
import static org.assertj.core.api.Assertions.assertThat;
/** IT case for Hive table compaction in batch mode. */
-public class HiveTableCompactSinkITCase {
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkITCase {
@RegisterExtension
- private static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
+ public static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
Review Comment:
Must it be public?
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSinkITCase.java:
##########
@@ -398,39 +399,38 @@ public void testStreamingSinkWithTimestampLtzWatermark() throws Exception {
}
@Test
- public void testStreamingSinkWithoutCommitPolicy() throws Exception {
+ void testStreamingSinkWithoutCommitPolicy() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnv = HiveTestUtils.createTableEnvInStreamingMode(env);
tableEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
tableEnv.useCatalog(hiveCatalog.getName());
tableEnv.executeSql("create database db1");
- try {
- tableEnv.useDatabase("db1");
- tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
- tableEnv.executeSql("create table dest(x int) partitioned by (p string)");
-
- tableEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
- tableEnv.executeSql(
- "create table src (i int, p string) with ("
- + "'connector'='datagen',"
- + "'number-of-rows'='5')");
- tableEnv.executeSql("insert into dest select * from src").await();
- fail("Streaming write partitioned table without commit policy should fail");
- } catch (FlinkHiveException e) {
- // expected
- assertThat(e.getMessage())
- .contains(
- String.format(
- "Streaming write to partitioned hive table `%s`.`%s`.`%s` without providing a commit policy",
- hiveCatalog.getName(), "db1", "dest"));
- } finally {
- tableEnv.executeSql("drop database db1 cascade");
- }
+
+ tableEnv.useDatabase("db1");
+ tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
+ tableEnv.executeSql("create table dest(x int) partitioned by (p string)");
+
+ tableEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
+ tableEnv.executeSql(
+ "create table src (i int, p string) with ("
+ + "'connector'='datagen',"
+ + "'number-of-rows'='5')");
+
+ assertThatThrownBy(
+ () -> tableEnv.executeSql("insert into dest select * from src").await(),
+ "Streaming write partitioned table without commit policy should fail")
+ .isInstanceOf(FlinkHiveException.class)
+ .hasMessageContaining(
+ String.format(
+ "Streaming write to partitioned hive table `%s`.`%s`.`%s` without providing a commit policy",
+ hiveCatalog.getName(), "db1", "dest"));
+
+ tableEnv.executeSql("drop database db1 cascade");
Review Comment:
If the assert statement `assertThatThrownBy` fail, we should also drop database db1.
##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveTableSink.java:
##########
@@ -123,6 +123,8 @@ public class HiveTableSink implements DynamicTableSink, SupportsPartitioning, Su
private static final Logger LOG = LoggerFactory.getLogger(HiveTableSink.class);
+ public static final String BATCH_COMPACT_WRITER_OP_NAME = "batch_compact_writer";
Review Comment:
Maybe better to change to `batch_writer` since stream mode is `stream_writer`
```suggestion
public static final String BATCH_COMPACT_WRITER_OP_NAME = "batch_writer";
```
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.CatalogTest;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.factories.DynamicTableSinkFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+
+ private static HiveCatalog catalog;
+
+ private Configuration tableConf;
+
+ @BeforeAll
+ static void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ }
+
+ @AfterAll
+ static void after() {
+ catalog.close();
+ }
+
+ @BeforeEach
+ void resetTableConf() {
+ tableConf = new Configuration();
+ tableConf.set(FactoryUtil.CONNECTOR, SqlCreateHiveTable.IDENTIFIER);
+ tableConf.set(FileSystemConnectorOptions.AUTO_COMPACTION, true);
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() throws Exception {
+ final int sinkParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() throws Exception {
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(tableConf, false, true, -1, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() throws Exception {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() throws Exception {
+ assertSinkAndCompactOperatorParallelism(tableConf, false, false, -1, -1);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ Configuration tableConf,
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism)
+ throws Exception {
+ StreamGraph streamGraph = createAndGetStreamGraphContainsSink(tableConf.toMap());
+ assertThat(streamGraph.getStreamNodes()).hasSize(6);
+ StreamNode hiveSinkNode =
+ getFirstStreamNodeByName(streamGraph, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ StreamNode compactNode = getFirstStreamNodeByName(streamGraph, BatchSink.COMPACT_OP_NAME);
+ assertThat(hiveSinkNode.isParallelismConfigured()).isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactNode.isParallelismConfigured()).isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
+ assertThat(hiveSinkNode.getParallelism()).isEqualTo(expectedSinkParallelism);
+ }
+ if (isCompactParallelismConfigured) {
+ assertThat(compactNode.getParallelism()).isEqualTo(expectedCompactParallelism);
+ }
+ }
+
+ private StreamGraph createAndGetStreamGraphContainsSink(Map<String, String> options)
Review Comment:
IIUC, this method is to construct a stream graph, but it looks hard to understand and complex to me. Is it possible to follow what we done like method `HiveTableSourceITCase#testParallelismSetting`.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112733682
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.CatalogTest;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.factories.DynamicTableSinkFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+
+ private static HiveCatalog catalog;
+
+ private Configuration tableConf;
+
+ @BeforeAll
+ static void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ }
+
+ @AfterAll
+ static void after() {
+ catalog.close();
+ }
+
+ @BeforeEach
+ void resetTableConf() {
+ tableConf = new Configuration();
+ tableConf.set(FactoryUtil.CONNECTOR, SqlCreateHiveTable.IDENTIFIER);
+ tableConf.set(FileSystemConnectorOptions.AUTO_COMPACTION, true);
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() throws Exception {
+ final int sinkParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() throws Exception {
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(tableConf, false, true, -1, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() throws Exception {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() throws Exception {
+ assertSinkAndCompactOperatorParallelism(tableConf, false, false, -1, -1);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ Configuration tableConf,
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism)
+ throws Exception {
+ StreamGraph streamGraph = createAndGetStreamGraphContainsSink(tableConf.toMap());
+ assertThat(streamGraph.getStreamNodes()).hasSize(6);
+ StreamNode hiveSinkNode =
+ getFirstStreamNodeByName(streamGraph, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ StreamNode compactNode = getFirstStreamNodeByName(streamGraph, BatchSink.COMPACT_OP_NAME);
+ assertThat(hiveSinkNode.isParallelismConfigured()).isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactNode.isParallelismConfigured()).isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
+ assertThat(hiveSinkNode.getParallelism()).isEqualTo(expectedSinkParallelism);
+ }
+ if (isCompactParallelismConfigured) {
+ assertThat(compactNode.getParallelism()).isEqualTo(expectedCompactParallelism);
+ }
+ }
+
+ private StreamGraph createAndGetStreamGraphContainsSink(Map<String, String> options)
Review Comment:
I modify the test logical refer to `ParallelismSettingTest#generateTransformation`.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on PR #21977:
URL: https://github.com/apache/flink/pull/21977#issuecomment-1438069932
Thanks @luoyuxia and @JunRuiLee for the review, I have updated this pr in two fixup commits, PTAL agian~
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1113000998
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -18,178 +18,174 @@
package org.apache.flink.connectors.hive;
-import org.apache.flink.api.common.RuntimeExecutionMode;
-import org.apache.flink.configuration.Configuration;
-import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.api.dag.Transformation;
import org.apache.flink.connector.file.table.batch.BatchSink;
-import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
-import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
-import org.apache.flink.streaming.api.graph.StreamGraph;
-import org.apache.flink.streaming.api.graph.StreamNode;
-import org.apache.flink.table.api.DataTypes;
-import org.apache.flink.table.api.TableSchema;
-import org.apache.flink.table.catalog.CatalogDatabaseImpl;
-import org.apache.flink.table.catalog.CatalogTable;
-import org.apache.flink.table.catalog.CatalogTableImpl;
-import org.apache.flink.table.catalog.CatalogTest;
-import org.apache.flink.table.catalog.Column;
-import org.apache.flink.table.catalog.ObjectIdentifier;
-import org.apache.flink.table.catalog.ObjectPath;
-import org.apache.flink.table.catalog.ResolvedCatalogTable;
-import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
import org.apache.flink.table.catalog.hive.HiveCatalog;
import org.apache.flink.table.catalog.hive.HiveTestUtils;
-import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
-import org.apache.flink.table.connector.sink.DynamicTableSink;
-import org.apache.flink.table.data.binary.BinaryRowData;
-import org.apache.flink.table.factories.DynamicTableSinkFactory;
-import org.apache.flink.table.factories.FactoryUtil;
-import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
import org.apache.flink.util.TestLoggerExtension;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
+import java.util.List;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link HiveTableSink} enable auto-compaction. */
@ExtendWith(TestLoggerExtension.class)
class HiveTableCompactSinkTest {
Review Comment:
updated.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112847462
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+ /**
+ * Represents the parallelism need not check, it should follow the setting of planer or auto
+ * inference.
+ */
+ public static final int NEED_NOT_CHECK_PARALLELISM = -1;
+
+ private HiveCatalog catalog;
+
+ private TableEnvironment tableEnv;
+
+ @BeforeEach
+ void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ tableEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.HIVE);
+ tableEnv.registerCatalog(catalog.getName(), catalog);
+ tableEnv.useCatalog(catalog.getName());
+ }
+
+ @AfterEach
+ void after() {
+ if (catalog != null) {
+ catalog.close();
+ }
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() {
+ final int sinkParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(), sinkParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() {
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ COMPACTION_PARALLELISM.key(), compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(
+ false, true, NEED_NOT_CHECK_PARALLELISM, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(),
+ sinkParallelism,
+ COMPACTION_PARALLELISM.key(),
+ compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() {
+ tableEnv.executeSql(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true' )");
+ assertSinkAndCompactOperatorParallelism(
+ false, false, NEED_NOT_CHECK_PARALLELISM, NEED_NOT_CHECK_PARALLELISM);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism) {
+ String statement = "insert into src values ('k1', 'v1'), ('k2', 'v2');";
+ PlannerBase planner = (PlannerBase) ((TableEnvironmentImpl) tableEnv).getPlanner();
+ planner.getExecEnv().setParallelism(10);
+ List<Operation> operations = planner.getParser().parse(statement);
+ List<Transformation<?>> transformations =
+ planner.translate(Collections.singletonList((ModifyOperation) (operations.get(0))));
+ assertThat(transformations).hasSize(1);
+ Transformation<?> rootTransformation = transformations.get(0);
+ Transformation<?> compactTransformation =
+ findTransformationByName(rootTransformation, BatchSink.COMPACT_OP_NAME);
+ Transformation<?> hiveSinkTransformation =
+ findTransformationByName(
+ rootTransformation, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ assertThat(hiveSinkTransformation.isParallelismConfigured())
+ .isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactTransformation.isParallelismConfigured())
+ .isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
Review Comment:
At first, I just want to regard it as a placeholder. After reading your comment, I think it seems more reasonable to use it to make conditional judgments.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on PR #21977:
URL: https://github.com/apache/flink/pull/21977#issuecomment-1438428604
I have updated this according to you comments, @luoyuxia would you mind taking a look again?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112798182
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -18,178 +18,174 @@
package org.apache.flink.connectors.hive;
-import org.apache.flink.api.common.RuntimeExecutionMode;
-import org.apache.flink.configuration.Configuration;
-import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.api.dag.Transformation;
import org.apache.flink.connector.file.table.batch.BatchSink;
-import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
-import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
-import org.apache.flink.streaming.api.graph.StreamGraph;
-import org.apache.flink.streaming.api.graph.StreamNode;
-import org.apache.flink.table.api.DataTypes;
-import org.apache.flink.table.api.TableSchema;
-import org.apache.flink.table.catalog.CatalogDatabaseImpl;
-import org.apache.flink.table.catalog.CatalogTable;
-import org.apache.flink.table.catalog.CatalogTableImpl;
-import org.apache.flink.table.catalog.CatalogTest;
-import org.apache.flink.table.catalog.Column;
-import org.apache.flink.table.catalog.ObjectIdentifier;
-import org.apache.flink.table.catalog.ObjectPath;
-import org.apache.flink.table.catalog.ResolvedCatalogTable;
-import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
import org.apache.flink.table.catalog.hive.HiveCatalog;
import org.apache.flink.table.catalog.hive.HiveTestUtils;
-import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
-import org.apache.flink.table.connector.sink.DynamicTableSink;
-import org.apache.flink.table.data.binary.BinaryRowData;
-import org.apache.flink.table.factories.DynamicTableSinkFactory;
-import org.apache.flink.table.factories.FactoryUtil;
-import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
import org.apache.flink.util.TestLoggerExtension;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
+import java.util.List;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link HiveTableSink} enable auto-compaction. */
@ExtendWith(TestLoggerExtension.class)
class HiveTableCompactSinkTest {
Review Comment:
Since it's mainly for test parallelism, how about rename it to `HiveTableCompactSinkParallelismTest`?
Also the java doc for this class should update.
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -18,178 +18,174 @@
package org.apache.flink.connectors.hive;
-import org.apache.flink.api.common.RuntimeExecutionMode;
-import org.apache.flink.configuration.Configuration;
-import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.api.dag.Transformation;
import org.apache.flink.connector.file.table.batch.BatchSink;
-import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
-import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
-import org.apache.flink.streaming.api.graph.StreamGraph;
-import org.apache.flink.streaming.api.graph.StreamNode;
-import org.apache.flink.table.api.DataTypes;
-import org.apache.flink.table.api.TableSchema;
-import org.apache.flink.table.catalog.CatalogDatabaseImpl;
-import org.apache.flink.table.catalog.CatalogTable;
-import org.apache.flink.table.catalog.CatalogTableImpl;
-import org.apache.flink.table.catalog.CatalogTest;
-import org.apache.flink.table.catalog.Column;
-import org.apache.flink.table.catalog.ObjectIdentifier;
-import org.apache.flink.table.catalog.ObjectPath;
-import org.apache.flink.table.catalog.ResolvedCatalogTable;
-import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
import org.apache.flink.table.catalog.hive.HiveCatalog;
import org.apache.flink.table.catalog.hive.HiveTestUtils;
-import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
-import org.apache.flink.table.connector.sink.DynamicTableSink;
-import org.apache.flink.table.data.binary.BinaryRowData;
-import org.apache.flink.table.factories.DynamicTableSinkFactory;
-import org.apache.flink.table.factories.FactoryUtil;
-import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
import org.apache.flink.util.TestLoggerExtension;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
+import java.util.List;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link HiveTableSink} enable auto-compaction. */
@ExtendWith(TestLoggerExtension.class)
class HiveTableCompactSinkTest {
+ /**
+ * Represents the parallelism need not check, it should follow the setting of planer or auto
Review Comment:
nit:
```suggestion
* Represents the parallelism doesn't need to be checked, it should follow the setting of planer or auto
```
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+ /**
+ * Represents the parallelism need not check, it should follow the setting of planer or auto
+ * inference.
+ */
+ public static final int NEED_NOT_CHECK_PARALLELISM = -1;
+
+ private HiveCatalog catalog;
+
+ private TableEnvironment tableEnv;
+
+ @BeforeEach
+ void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ tableEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.HIVE);
+ tableEnv.registerCatalog(catalog.getName(), catalog);
+ tableEnv.useCatalog(catalog.getName());
+ }
+
+ @AfterEach
+ void after() {
+ if (catalog != null) {
+ catalog.close();
+ }
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() {
+ final int sinkParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(), sinkParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() {
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ COMPACTION_PARALLELISM.key(), compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(
+ false, true, NEED_NOT_CHECK_PARALLELISM, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(),
+ sinkParallelism,
+ COMPACTION_PARALLELISM.key(),
+ compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() {
+ tableEnv.executeSql(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true' )");
+ assertSinkAndCompactOperatorParallelism(
+ false, false, NEED_NOT_CHECK_PARALLELISM, NEED_NOT_CHECK_PARALLELISM);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism) {
+ String statement = "insert into src values ('k1', 'v1'), ('k2', 'v2');";
+ PlannerBase planner = (PlannerBase) ((TableEnvironmentImpl) tableEnv).getPlanner();
+ planner.getExecEnv().setParallelism(10);
+ List<Operation> operations = planner.getParser().parse(statement);
+ List<Transformation<?>> transformations =
+ planner.translate(Collections.singletonList((ModifyOperation) (operations.get(0))));
+ assertThat(transformations).hasSize(1);
+ Transformation<?> rootTransformation = transformations.get(0);
+ Transformation<?> compactTransformation =
+ findTransformationByName(rootTransformation, BatchSink.COMPACT_OP_NAME);
+ Transformation<?> hiveSinkTransformation =
+ findTransformationByName(
+ rootTransformation, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ assertThat(hiveSinkTransformation.isParallelismConfigured())
+ .isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactTransformation.isParallelismConfigured())
+ .isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
Review Comment:
Got little confused in here.
I guess `NEED_NOT_CHECK_PARALLELISM` means if the passed `expectedSinkParallelism` is equal to `NEED_NOT_CHECK_PARALLELISM` , we can ignore check whether they are same.
If that's the case, won't it be more clear with the following code?
```
if (expectedSinkParallelism != NEED_NOT_CHECK_PARALLELISM) {
// then we check the parallelism
}.
```
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+ /**
+ * Represents the parallelism need not check, it should follow the setting of planer or auto
+ * inference.
+ */
+ public static final int NEED_NOT_CHECK_PARALLELISM = -1;
+
+ private HiveCatalog catalog;
+
+ private TableEnvironment tableEnv;
+
+ @BeforeEach
+ void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ tableEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.HIVE);
+ tableEnv.registerCatalog(catalog.getName(), catalog);
+ tableEnv.useCatalog(catalog.getName());
+ }
+
+ @AfterEach
+ void after() {
+ if (catalog != null) {
+ catalog.close();
+ }
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() {
+ final int sinkParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(), sinkParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() {
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ COMPACTION_PARALLELISM.key(), compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(
+ false, true, NEED_NOT_CHECK_PARALLELISM, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(),
+ sinkParallelism,
+ COMPACTION_PARALLELISM.key(),
+ compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() {
+ tableEnv.executeSql(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true' )");
+ assertSinkAndCompactOperatorParallelism(
+ false, false, NEED_NOT_CHECK_PARALLELISM, NEED_NOT_CHECK_PARALLELISM);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism) {
+ String statement = "insert into src values ('k1', 'v1'), ('k2', 'v2');";
+ PlannerBase planner = (PlannerBase) ((TableEnvironmentImpl) tableEnv).getPlanner();
+ planner.getExecEnv().setParallelism(10);
+ List<Operation> operations = planner.getParser().parse(statement);
+ List<Transformation<?>> transformations =
+ planner.translate(Collections.singletonList((ModifyOperation) (operations.get(0))));
+ assertThat(transformations).hasSize(1);
+ Transformation<?> rootTransformation = transformations.get(0);
+ Transformation<?> compactTransformation =
+ findTransformationByName(rootTransformation, BatchSink.COMPACT_OP_NAME);
+ Transformation<?> hiveSinkTransformation =
+ findTransformationByName(
+ rootTransformation, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ assertThat(hiveSinkTransformation.isParallelismConfigured())
+ .isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactTransformation.isParallelismConfigured())
+ .isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
Review Comment:
If that's not what `NEED_NOT_CHECK_PARALLELISM` means , then I think it's just a place holder?
If so, seems it'll be better to update the name/comment of `NEED_NOT_CHECK_PARALLELISM` to make it more clear.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1113794294
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java:
##########
@@ -402,7 +402,7 @@ public Optional<OperatorCoordinator.Provider> getCoordinatorProvider(
}
}
- boolean isParallelismConfigured() {
+ public boolean isParallelismConfigured() {
Review Comment:
Never mind. It's also reasonable to remove it, I have dropped the commit about this change and rebased all fix-up commits.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112847462
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+ /**
+ * Represents the parallelism need not check, it should follow the setting of planer or auto
+ * inference.
+ */
+ public static final int NEED_NOT_CHECK_PARALLELISM = -1;
+
+ private HiveCatalog catalog;
+
+ private TableEnvironment tableEnv;
+
+ @BeforeEach
+ void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ tableEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.HIVE);
+ tableEnv.registerCatalog(catalog.getName(), catalog);
+ tableEnv.useCatalog(catalog.getName());
+ }
+
+ @AfterEach
+ void after() {
+ if (catalog != null) {
+ catalog.close();
+ }
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() {
+ final int sinkParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(), sinkParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() {
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s' )",
+ COMPACTION_PARALLELISM.key(), compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(
+ false, true, NEED_NOT_CHECK_PARALLELISM, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableEnv.executeSql(
+ String.format(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true', "
+ + " '%s' = '%s', "
+ + " '%s' = '%s' )",
+ SINK_PARALLELISM.key(),
+ sinkParallelism,
+ COMPACTION_PARALLELISM.key(),
+ compactParallelism));
+
+ assertSinkAndCompactOperatorParallelism(true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() {
+ tableEnv.executeSql(
+ "CREATE TABLE src ("
+ + " key string,"
+ + " value string"
+ + ") TBLPROPERTIES ("
+ + " 'auto-compaction' = 'true' )");
+ assertSinkAndCompactOperatorParallelism(
+ false, false, NEED_NOT_CHECK_PARALLELISM, NEED_NOT_CHECK_PARALLELISM);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism) {
+ String statement = "insert into src values ('k1', 'v1'), ('k2', 'v2');";
+ PlannerBase planner = (PlannerBase) ((TableEnvironmentImpl) tableEnv).getPlanner();
+ planner.getExecEnv().setParallelism(10);
+ List<Operation> operations = planner.getParser().parse(statement);
+ List<Transformation<?>> transformations =
+ planner.translate(Collections.singletonList((ModifyOperation) (operations.get(0))));
+ assertThat(transformations).hasSize(1);
+ Transformation<?> rootTransformation = transformations.get(0);
+ Transformation<?> compactTransformation =
+ findTransformationByName(rootTransformation, BatchSink.COMPACT_OP_NAME);
+ Transformation<?> hiveSinkTransformation =
+ findTransformationByName(
+ rootTransformation, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ assertThat(hiveSinkTransformation.isParallelismConfigured())
+ .isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactTransformation.isParallelismConfigured())
+ .isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
Review Comment:
Yes, it's just a placeholder.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1113785798
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java:
##########
@@ -402,7 +402,7 @@ public Optional<OperatorCoordinator.Provider> getCoordinatorProvider(
}
}
- boolean isParallelismConfigured() {
+ public boolean isParallelismConfigured() {
Review Comment:
Ah, At the beginning, I relied on it for the assertion of streamGraph's parallelism. Later, I changed the test logical, and really no longer needed it to be public now. The reason why not revert this is that I noticed that most of the other get methods on `StreamNode` are also public, and it will not change the internal state of the object. I prefer to keep this change for future convenience.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] JunRuiLee commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "JunRuiLee (via GitHub)" <gi...@apache.org>.
JunRuiLee commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1113777681
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java:
##########
@@ -402,7 +402,7 @@ public Optional<OperatorCoordinator.Provider> getCoordinatorProvider(
}
}
- boolean isParallelismConfigured() {
+ public boolean isParallelismConfigured() {
Review Comment:
Why we need this change?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112634137
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSinkITCase.java:
##########
@@ -398,39 +399,38 @@ public void testStreamingSinkWithTimestampLtzWatermark() throws Exception {
}
@Test
- public void testStreamingSinkWithoutCommitPolicy() throws Exception {
+ void testStreamingSinkWithoutCommitPolicy() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnv = HiveTestUtils.createTableEnvInStreamingMode(env);
tableEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
tableEnv.useCatalog(hiveCatalog.getName());
tableEnv.executeSql("create database db1");
- try {
- tableEnv.useDatabase("db1");
- tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
- tableEnv.executeSql("create table dest(x int) partitioned by (p string)");
-
- tableEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
- tableEnv.executeSql(
- "create table src (i int, p string) with ("
- + "'connector'='datagen',"
- + "'number-of-rows'='5')");
- tableEnv.executeSql("insert into dest select * from src").await();
- fail("Streaming write partitioned table without commit policy should fail");
- } catch (FlinkHiveException e) {
- // expected
- assertThat(e.getMessage())
- .contains(
- String.format(
- "Streaming write to partitioned hive table `%s`.`%s`.`%s` without providing a commit policy",
- hiveCatalog.getName(), "db1", "dest"));
- } finally {
- tableEnv.executeSql("drop database db1 cascade");
- }
+
+ tableEnv.useDatabase("db1");
+ tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
+ tableEnv.executeSql("create table dest(x int) partitioned by (p string)");
+
+ tableEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
+ tableEnv.executeSql(
+ "create table src (i int, p string) with ("
+ + "'connector'='datagen',"
+ + "'number-of-rows'='5')");
+
+ assertThatThrownBy(
+ () -> tableEnv.executeSql("insert into dest select * from src").await(),
+ "Streaming write partitioned table without commit policy should fail")
+ .isInstanceOf(FlinkHiveException.class)
+ .hasMessageContaining(
+ String.format(
+ "Streaming write to partitioned hive table `%s`.`%s`.`%s` without providing a commit policy",
+ hiveCatalog.getName(), "db1", "dest"));
+
+ tableEnv.executeSql("drop database db1 cascade");
Review Comment:
good catch, fixed.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112739085
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.CatalogTest;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.factories.DynamicTableSinkFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+
+ private static HiveCatalog catalog;
+
+ private Configuration tableConf;
+
+ @BeforeAll
+ static void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ }
+
+ @AfterAll
+ static void after() {
+ catalog.close();
+ }
+
+ @BeforeEach
+ void resetTableConf() {
+ tableConf = new Configuration();
+ tableConf.set(FactoryUtil.CONNECTOR, SqlCreateHiveTable.IDENTIFIER);
+ tableConf.set(FileSystemConnectorOptions.AUTO_COMPACTION, true);
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() throws Exception {
+ final int sinkParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() throws Exception {
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(tableConf, false, true, -1, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() throws Exception {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() throws Exception {
+ assertSinkAndCompactOperatorParallelism(tableConf, false, false, -1, -1);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ Configuration tableConf,
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism)
+ throws Exception {
+ StreamGraph streamGraph = createAndGetStreamGraphContainsSink(tableConf.toMap());
+ assertThat(streamGraph.getStreamNodes()).hasSize(6);
+ StreamNode hiveSinkNode =
+ getFirstStreamNodeByName(streamGraph, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ StreamNode compactNode = getFirstStreamNodeByName(streamGraph, BatchSink.COMPACT_OP_NAME);
+ assertThat(hiveSinkNode.isParallelismConfigured()).isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactNode.isParallelismConfigured()).isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
+ assertThat(hiveSinkNode.getParallelism()).isEqualTo(expectedSinkParallelism);
Review Comment:
I have reworked this test logical to not dependent on `StreamGraph`, so I think control the default parallelism is a little difficult. BTW, I use a special static final field to indicate the parallelism check should be ignored.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] JunRuiLee commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "JunRuiLee (via GitHub)" <gi...@apache.org>.
JunRuiLee commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112577779
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.CatalogTest;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.factories.DynamicTableSinkFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+
+ private static HiveCatalog catalog;
+
+ private Configuration tableConf;
+
+ @BeforeAll
+ static void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ }
+
+ @AfterAll
+ static void after() {
+ catalog.close();
+ }
+
+ @BeforeEach
+ void resetTableConf() {
+ tableConf = new Configuration();
+ tableConf.set(FactoryUtil.CONNECTOR, SqlCreateHiveTable.IDENTIFIER);
+ tableConf.set(FileSystemConnectorOptions.AUTO_COMPACTION, true);
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() throws Exception {
+ final int sinkParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() throws Exception {
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(tableConf, false, true, -1, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() throws Exception {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() throws Exception {
+ assertSinkAndCompactOperatorParallelism(tableConf, false, false, -1, -1);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ Configuration tableConf,
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism)
+ throws Exception {
+ StreamGraph streamGraph = createAndGetStreamGraphContainsSink(tableConf.toMap());
+ assertThat(streamGraph.getStreamNodes()).hasSize(6);
+ StreamNode hiveSinkNode =
+ getFirstStreamNodeByName(streamGraph, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ StreamNode compactNode = getFirstStreamNodeByName(streamGraph, BatchSink.COMPACT_OP_NAME);
+ assertThat(hiveSinkNode.isParallelismConfigured()).isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactNode.isParallelismConfigured()).isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
+ assertThat(hiveSinkNode.getParallelism()).isEqualTo(expectedSinkParallelism);
Review Comment:
Can we consider introducing a field `private static final int DEFAULT_PARALLELISM`? When isXXXParallelismConfigured is false, the parallelism of the operator is equal to DEFAULT_PARALLELISM, which is also in line with the idea of table planner operator parallelism infection. If so, you may need to use fromSource because it is a parallel source.
What do you think?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #21977:
URL: https://github.com/apache/flink/pull/21977#issuecomment-1437384987
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "25a7914ac8b73322a7a9b6b7ec7dbbf840416f9a",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "25a7914ac8b73322a7a9b6b7ec7dbbf840416f9a",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 25a7914ac8b73322a7a9b6b7ec7dbbf840416f9a UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] luoyuxia commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112838547
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -18,178 +18,174 @@
package org.apache.flink.connectors.hive;
-import org.apache.flink.api.common.RuntimeExecutionMode;
-import org.apache.flink.configuration.Configuration;
-import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.api.dag.Transformation;
import org.apache.flink.connector.file.table.batch.BatchSink;
-import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
-import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
-import org.apache.flink.streaming.api.graph.StreamGraph;
-import org.apache.flink.streaming.api.graph.StreamNode;
-import org.apache.flink.table.api.DataTypes;
-import org.apache.flink.table.api.TableSchema;
-import org.apache.flink.table.catalog.CatalogDatabaseImpl;
-import org.apache.flink.table.catalog.CatalogTable;
-import org.apache.flink.table.catalog.CatalogTableImpl;
-import org.apache.flink.table.catalog.CatalogTest;
-import org.apache.flink.table.catalog.Column;
-import org.apache.flink.table.catalog.ObjectIdentifier;
-import org.apache.flink.table.catalog.ObjectPath;
-import org.apache.flink.table.catalog.ResolvedCatalogTable;
-import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.internal.TableEnvironmentImpl;
import org.apache.flink.table.catalog.hive.HiveCatalog;
import org.apache.flink.table.catalog.hive.HiveTestUtils;
-import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
-import org.apache.flink.table.connector.sink.DynamicTableSink;
-import org.apache.flink.table.data.binary.BinaryRowData;
-import org.apache.flink.table.factories.DynamicTableSinkFactory;
-import org.apache.flink.table.factories.FactoryUtil;
-import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.planner.delegation.PlannerBase;
import org.apache.flink.util.TestLoggerExtension;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
+import java.util.List;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.COMPACTION_PARALLELISM;
+import static org.apache.flink.connector.file.table.FileSystemConnectorOptions.SINK_PARALLELISM;
import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link HiveTableSink} enable auto-compaction. */
@ExtendWith(TestLoggerExtension.class)
class HiveTableCompactSinkTest {
+ /**
+ * Represents the parallelism need not check, it should follow the setting of planer or auto
Review Comment:
If my understand commented below is correct.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] JunRuiLee commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "JunRuiLee (via GitHub)" <gi...@apache.org>.
JunRuiLee commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1113790013
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java:
##########
@@ -402,7 +402,7 @@ public Optional<OperatorCoordinator.Provider> getCoordinatorProvider(
}
}
- boolean isParallelismConfigured() {
+ public boolean isParallelismConfigured() {
Review Comment:
It just looks confusing here because this change wasn't used in this pr, I tend to leave it alone, but it doesn't matter so it's up to you.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa closed pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa closed pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
URL: https://github.com/apache/flink/pull/21977
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112641083
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkITCase.java:
##########
@@ -42,17 +44,18 @@
import static org.assertj.core.api.Assertions.assertThat;
/** IT case for Hive table compaction in batch mode. */
-public class HiveTableCompactSinkITCase {
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkITCase {
@RegisterExtension
- private static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
+ public static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
Review Comment:
TBH, The reason I changed it is only to follow the usage approach in the `MiniClusterExtension` class [javadoc](https://github.com/apache/flink/blob/bacdc326b58749924acbd8921d63eda06663a225/flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/junit5/MiniClusterExtension.java#L70).
At the same time, in the `architecture check` of IT case, we can see similar [requirement](https://github.com/apache/flink/blob/bacdc326b58749924acbd8921d63eda06663a225/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/rules/ITCaseRules.java#L67). Unfortunately, I looked at the actual check logic and didn't seem to require it to be public, which really confused me.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1112739085
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableCompactSinkTest.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.file.table.FileSystemConnectorOptions;
+import org.apache.flink.connector.file.table.batch.BatchSink;
+import org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.CatalogTest;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.factories.DynamicTableSinkFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+import org.apache.flink.util.TestLoggerExtension;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link HiveTableSink} enable auto-compaction. */
+@ExtendWith(TestLoggerExtension.class)
+class HiveTableCompactSinkTest {
+
+ private static HiveCatalog catalog;
+
+ private Configuration tableConf;
+
+ @BeforeAll
+ static void before() {
+ catalog = HiveTestUtils.createHiveCatalog();
+ catalog.open();
+ }
+
+ @AfterAll
+ static void after() {
+ catalog.close();
+ }
+
+ @BeforeEach
+ void resetTableConf() {
+ tableConf = new Configuration();
+ tableConf.set(FactoryUtil.CONNECTOR, SqlCreateHiveTable.IDENTIFIER);
+ tableConf.set(FileSystemConnectorOptions.AUTO_COMPACTION, true);
+ }
+
+ /** If only sink parallelism is set, compact operator should follow this setting. */
+ @Test
+ void testOnlySetSinkParallelism() throws Exception {
+ final int sinkParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, sinkParallelism);
+ }
+
+ @Test
+ void testOnlySetCompactParallelism() throws Exception {
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(tableConf, false, true, -1, compactParallelism);
+ }
+
+ @Test
+ void testSetBothSinkAndCompactParallelism() throws Exception {
+ final int sinkParallelism = 8;
+ final int compactParallelism = 4;
+
+ tableConf.set(FileSystemConnectorOptions.SINK_PARALLELISM, sinkParallelism);
+ tableConf.set(FileSystemConnectorOptions.COMPACTION_PARALLELISM, compactParallelism);
+
+ assertSinkAndCompactOperatorParallelism(
+ tableConf, true, true, sinkParallelism, compactParallelism);
+ }
+
+ @Test
+ void testSinkAndCompactAllNotSetParallelism() throws Exception {
+ assertSinkAndCompactOperatorParallelism(tableConf, false, false, -1, -1);
+ }
+
+ private void assertSinkAndCompactOperatorParallelism(
+ Configuration tableConf,
+ boolean isSinkParallelismConfigured,
+ boolean isCompactParallelismConfigured,
+ int expectedSinkParallelism,
+ int expectedCompactParallelism)
+ throws Exception {
+ StreamGraph streamGraph = createAndGetStreamGraphContainsSink(tableConf.toMap());
+ assertThat(streamGraph.getStreamNodes()).hasSize(6);
+ StreamNode hiveSinkNode =
+ getFirstStreamNodeByName(streamGraph, HiveTableSink.BATCH_COMPACT_WRITER_OP_NAME);
+ StreamNode compactNode = getFirstStreamNodeByName(streamGraph, BatchSink.COMPACT_OP_NAME);
+ assertThat(hiveSinkNode.isParallelismConfigured()).isEqualTo(isSinkParallelismConfigured);
+ assertThat(compactNode.isParallelismConfigured()).isEqualTo(isCompactParallelismConfigured);
+ if (isSinkParallelismConfigured) {
+ assertThat(hiveSinkNode.getParallelism()).isEqualTo(expectedSinkParallelism);
Review Comment:
I have reworked this test logical to not dependent on `StreamGraph`, so I think control the default parallelism is a little difficult for the new approach. BTW, I use a special static final field to indicate the parallelism check should be ignored.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] reswqa commented on a diff in pull request #21977: [FLINK-31132] Compact without setting parallelism does not follow the configured sink parallelism for HiveTableSink
Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #21977:
URL: https://github.com/apache/flink/pull/21977#discussion_r1113785798
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java:
##########
@@ -402,7 +402,7 @@ public Optional<OperatorCoordinator.Provider> getCoordinatorProvider(
}
}
- boolean isParallelismConfigured() {
+ public boolean isParallelismConfigured() {
Review Comment:
Ah, At the beginning, I relied on it for the assertion of streamGraph's parallelism. Later, I changed the test logical, and really no longer needed it to be public now. The reason why not revert this is that I noticed that most of the other get methods on `StreamNode` are also public, and it will not change the internal state of the object. I prefer to keep this change for future convenience. WDYT?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org