JingsongLi commented on code in PR #1212:
URL: https://github.com/apache/incubator-paimon/pull/1212#discussion_r1202402902
##########
paimon-core/src/main/java/org/apache/paimon/catalog/Identifier.java:
##########
@@ -109,4 +109,8 @@ public int hashCode() {
public String toString() {
return "Identifier{" + "database='" + database + '\'' + ", table='" +
table + '\'' + '}';
}
+
+ public String getTableName() {
Review Comment:
Put this together with `getObjectName`.
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/cdc/CdcRecordStoreMultiWriteOperator.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.paimon.flink.sink.cdc;
+
+import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.flink.sink.Committable;
+import org.apache.paimon.flink.sink.MultiTableCommittable;
+import org.apache.paimon.flink.sink.PrepareCommitOperator;
+import org.apache.paimon.flink.sink.StateUtils;
+import org.apache.paimon.flink.sink.StoreSinkWrite;
+import org.apache.paimon.flink.sink.StoreSinkWriteState;
+import org.apache.paimon.table.FileStoreTable;
+
+import org.apache.flink.runtime.state.StateInitializationContext;
+import org.apache.flink.runtime.state.StateSnapshotContext;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static
org.apache.paimon.flink.sink.cdc.CdcRecordStoreWriteOperator.RETRY_SLEEP_TIME;
+
+/**
+ * A {@link PrepareCommitOperator} to write {@link CdcRecord}. Record schema
may change. If current
+ * known schema does not fit record schema, this operator will wait for schema
changes.
+ */
+public class CdcRecordStoreMultiWriteOperator extends
PrepareCommitOperator<MultiplexCdcRecord> {
+
+ private static final long serialVersionUID = 1L;
+ private final Catalog catalog;
Review Comment:
It is better to create a `CatalogLoader` instead of making `Catalog`
serializable.
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/MultiTableCommittable.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.paimon.flink.sink;
+
+import org.apache.paimon.catalog.Identifier;
+
+/**
+ * MultiTableCommittable produced by {@link PrepareCommitOperator}. This type
of Committable will
+ * only be produced by multiplexed operators that handles data from multiple
tables. Thus, the
+ * database, table, and commit user of each table is included in the
committable.
+ */
+public class MultiTableCommittable extends Committable {
+
+ private final String database;
+ private final String table;
+ private final String commitUser;
+
+ public MultiTableCommittable(
+ String database,
+ String table,
+ String commitUser,
Review Comment:
Do we need this one? We can set same UUID user
`StreamWriteBuilder.withCommitUser` to writer and committer.
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/cdc/MultiplexCdcRecord.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.flink.sink.cdc;
+
+import org.apache.paimon.types.RowKind;
+
+import java.util.Map;
+
+/**
+ * A data change message from the CDC source. Compared to {@link CdcRecord},
MultiplexCdcRecord
+ * contains database and table information.
+ */
+public class MultiplexCdcRecord extends CdcRecord {
Review Comment:
Can we use just create a field `CdcRecord ` instead of extending?
Extending will make the caller think it can be used as a CdcRecord.
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/MultiTableCommittable.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.paimon.flink.sink;
+
+import org.apache.paimon.catalog.Identifier;
+
+/**
+ * MultiTableCommittable produced by {@link PrepareCommitOperator}. This type
of Committable will
+ * only be produced by multiplexed operators that handles data from multiple
tables. Thus, the
+ * database, table, and commit user of each table is included in the
committable.
+ */
+public class MultiTableCommittable extends Committable {
Review Comment:
Can we use just create a field `Committable` instead of extending?
Extending will make the caller think it can be used as a Committable.
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/cdc/CdcRecordStoreMultiWriteOperator.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.paimon.flink.sink.cdc;
+
+import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.flink.sink.Committable;
+import org.apache.paimon.flink.sink.MultiTableCommittable;
+import org.apache.paimon.flink.sink.PrepareCommitOperator;
+import org.apache.paimon.flink.sink.StateUtils;
+import org.apache.paimon.flink.sink.StoreSinkWrite;
+import org.apache.paimon.flink.sink.StoreSinkWriteState;
+import org.apache.paimon.table.FileStoreTable;
+
+import org.apache.flink.runtime.state.StateInitializationContext;
+import org.apache.flink.runtime.state.StateSnapshotContext;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static
org.apache.paimon.flink.sink.cdc.CdcRecordStoreWriteOperator.RETRY_SLEEP_TIME;
+
+/**
+ * A {@link PrepareCommitOperator} to write {@link CdcRecord}. Record schema
may change. If current
+ * known schema does not fit record schema, this operator will wait for schema
changes.
+ */
+public class CdcRecordStoreMultiWriteOperator extends
PrepareCommitOperator<MultiplexCdcRecord> {
+
+ private static final long serialVersionUID = 1L;
+ private final Catalog catalog;
+ private final StoreSinkWrite.Provider storeSinkWriteProvider;
+ private final String initialCommitUser;
+ private FileStoreTable table;
+ private Map<Identifier, FileStoreTable> tables;
+ private StoreSinkWriteState state;
+ private StoreSinkWrite write;
+ private Map<Identifier, StoreSinkWrite> writes;
+ private String commitUser;
+
+ public CdcRecordStoreMultiWriteOperator(
+ Catalog catalog,
+ StoreSinkWrite.Provider storeSinkWriteProvider,
+ String initialCommitUser) {
+ this.catalog = catalog;
+ this.storeSinkWriteProvider = storeSinkWriteProvider;
+ this.initialCommitUser = initialCommitUser;
+ }
+
+ @Override
+ public void initializeState(StateInitializationContext context) throws
Exception {
+ super.initializeState(context);
+
+ // Each job can only have one user name and this name must be
consistent across restarts.
+ // We cannot use job id as commit user name here because user may
change job id by creating
+ // a savepoint, stop the job and then resume from savepoint.
+ commitUser =
+ StateUtils.getSingleValueFromState(
+ context, "commit_user_state", String.class,
initialCommitUser);
+
+ state = new StoreSinkWriteState(context, (tableName, partition,
bucket) -> true);
+ this.tables = new HashMap<>();
+ this.writes = new HashMap<>();
+ }
+
+ @Override
+ public void processElement(StreamRecord<MultiplexCdcRecord> element)
throws Exception {
+ MultiplexCdcRecord record = element.getValue();
+
+ String databaseName = record.getDatabaseName();
+ String tableName = record.getTableName();
+ Identifier key = Identifier.create(databaseName, tableName);
+ table =
+ tables.computeIfAbsent(
+ key,
+ id -> {
+ try {
+ return (FileStoreTable) catalog.getTable(id);
+ } catch (Catalog.TableNotExistException e) {
+ return null;
+ }
+ });
+
+ if (table == null) {
Review Comment:
here should be a `while (true) {...}` to wait table creation by
`UpdatedDataFieldsProcessFunction`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]