You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/02/08 10:13:08 UTC

[GitHub] [iceberg] zhangjun0x01 commented on a change in pull request #1978: Flink: Add unit test to write CDC events by SQL.

zhangjun0x01 commented on a change in pull request #1978:
URL: https://github.com/apache/iceberg/pull/1978#discussion_r571924074



##########
File path: flink/src/test/java/org/apache/iceberg/flink/TestFlinkTableSinkV2.java
##########
@@ -0,0 +1,333 @@
+/*
+ * 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.iceberg.flink;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.streaming.api.TimeCharacteristic;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.DataFormatConverters;
+import org.apache.flink.table.runtime.typeutils.RowDataTypeInfo;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.Row;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.flink.source.BoundedTestSource;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.util.StructLikeSet;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestFlinkTableSinkV2 extends FlinkCatalogTestBase {
+  private static final String TABLE_NAME_V2 = "test_table_v2";
+  private static final int ROW_ID_POS = 0;
+  private static final int ROW_DATA_POS = 1;
+
+  private final boolean partitioned;
+
+  private final StreamExecutionEnvironment env;
+
+  private StreamTableEnvironment tEnv;
+  private Map<String, String> tableProps;
+
+  @Parameterized.Parameters(name = "CatalogName={0}, Format={1}, Partitioned={2}")
+  public static Iterable<Object[]> parameters() {
+    return ImmutableList.of(
+        new Object[] {"testhive", "avro", true},
+        new Object[] {"testhive", "avro", false},
+        new Object[] {"testhive", "parquet", true},
+        new Object[] {"testhive", "parquet", false},
+        new Object[] {"testhadoop", "avro", true},
+        new Object[] {"testhadoop", "avro", false},
+        new Object[] {"testhadoop", "parquet", true},
+        new Object[] {"testhadoop", "parquet", false}
+    );
+  }
+
+  public TestFlinkTableSinkV2(String catalogName, String format, Boolean partitioned) {
+    super(catalogName, new String[0]);
+    this.partitioned = partitioned;
+
+    this.env = StreamExecutionEnvironment.getExecutionEnvironment().enableCheckpointing(400);
+    env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
+
+    this.tableProps = ImmutableMap.of(TableProperties.DEFAULT_FILE_FORMAT, format, TableProperties.FORMAT_VERSION, "2");
+  }
+
+  @Override
+  protected TableEnvironment getTableEnv() {
+    if (tEnv == null) {
+      synchronized (this) {
+        if (tEnv == null) {
+          tEnv = StreamTableEnvironment.create(env, EnvironmentSettings
+              .newInstance()
+              .useBlinkPlanner()
+              .inStreamingMode()
+              .build());
+        }
+      }
+    }
+    return tEnv;
+  }
+
+  @Before
+  public void before() {
+    super.before();
+    sql("CREATE DATABASE %s", flinkDatabase);
+    sql("USE CATALOG %s", catalogName);
+    sql("USE %s", DATABASE);
+  }
+
+  @After
+  public void clean() {
+    sql("DROP TABLE IF EXISTS %s.%s", flinkDatabase, TABLE_NAME_V2);
+    sql("DROP DATABASE IF EXISTS %s", flinkDatabase);
+    super.clean();
+  }
+
+  @Test
+  public void testSqlChangeLogOnIdKey() throws Exception {

Review comment:
       I checked the source code of the flink cdc test class and found that it used docker to start a mysql service to get the cdc data. It seems that there really is no good way to get the cdc data in flink.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org