GOODBOY008 commented on code in PR #3360:
URL: https://github.com/apache/flink-cdc/pull/3360#discussion_r1639708043


##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oceanbase/src/main/java/org/apache/flink/cdc/connectors/oceanbase/factory/OceanBaseDataSinkFactory.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.cdc.connectors.oceanbase.factory;
+
+import org.apache.flink.cdc.common.annotation.Internal;
+import org.apache.flink.cdc.common.configuration.ConfigOption;
+import org.apache.flink.cdc.common.configuration.Configuration;
+import org.apache.flink.cdc.common.factories.DataSinkFactory;
+import org.apache.flink.cdc.common.sink.DataSink;
+import org.apache.flink.cdc.connectors.oceanbase.sink.OceanBaseDataSink;
+import org.apache.flink.cdc.connectors.oceanbase.sink.OceanBaseDataSinkOptions;
+
+import com.oceanbase.connector.flink.OceanBaseConnectorOptions;
+
+import java.time.ZoneId;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static 
org.apache.flink.cdc.common.pipeline.PipelineOptions.PIPELINE_LOCAL_TIME_ZONE;
+
+/** A {@link DataSinkFactory} to create {@link OceanBaseDataSink}. */
+@Internal
+public class OceanBaseDataSinkFactory implements DataSinkFactory {
+
+    @Override
+    public DataSink createDataSink(Context context) {
+        Configuration config = context.getFactoryConfiguration();
+        OceanBaseConnectorOptions connectorOptions =
+                new OceanBaseConnectorOptions(buildOceanBaseOptions(config));
+        String zoneStr = 
context.getFactoryConfiguration().get(PIPELINE_LOCAL_TIME_ZONE);
+        ZoneId zoneId =
+                PIPELINE_LOCAL_TIME_ZONE.defaultValue().equals(zoneStr)
+                        ? ZoneId.systemDefault()

Review Comment:
   add `OptionUtils.printOptions(IDENTIFIER, config.toMap());` for usr to know 
the config info.



##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oceanbase/src/main/java/org/apache/flink/cdc/connectors/oceanbase/sink/OceanBaseEventSerializationSchema.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.cdc.connectors.oceanbase.sink;
+
+import org.apache.flink.cdc.common.data.RecordData;
+import org.apache.flink.cdc.common.event.CreateTableEvent;
+import org.apache.flink.cdc.common.event.DataChangeEvent;
+import org.apache.flink.cdc.common.event.Event;
+import org.apache.flink.cdc.common.event.OperationType;
+import org.apache.flink.cdc.common.event.SchemaChangeEvent;
+import org.apache.flink.cdc.common.event.TableId;
+import org.apache.flink.cdc.common.schema.Column;
+import org.apache.flink.cdc.common.schema.Schema;
+import org.apache.flink.cdc.common.utils.Preconditions;
+import org.apache.flink.cdc.common.utils.SchemaUtils;
+
+import org.apache.flink.shaded.guava31.com.google.common.collect.Lists;
+
+import com.oceanbase.connector.flink.table.DataChangeRecord;
+import com.oceanbase.connector.flink.table.Record;
+import com.oceanbase.connector.flink.table.RecordSerializationSchema;
+import com.oceanbase.connector.flink.table.TableInfo;
+
+import java.time.ZoneId;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/** A serializer for Event to Record. */
+public class OceanBaseEventSerializationSchema implements 
RecordSerializationSchema<Event> {
+
+    private final Map<TableId, Schema> schemaMaps = new HashMap<>();
+
+    /** ZoneId from pipeline config to support timestamp with local time zone. 
*/
+    public final ZoneId pipelineZoneId;
+
+    public OceanBaseEventSerializationSchema(ZoneId zoneId) {
+        pipelineZoneId = zoneId;
+    }
+
+    @Override
+    public Record serialize(Event event) {
+        if (event instanceof DataChangeEvent) {
+            return applyDataChangeEvent((DataChangeEvent) event);
+        } else if (event instanceof SchemaChangeEvent) {
+            SchemaChangeEvent schemaChangeEvent = (SchemaChangeEvent) event;
+            TableId tableId = schemaChangeEvent.tableId();
+            if (event instanceof CreateTableEvent) {
+                schemaMaps.put(tableId, ((CreateTableEvent) 
event).getSchema());
+            } else {
+                if (!schemaMaps.containsKey(tableId)) {
+                    throw new RuntimeException("schema of " + tableId + " is 
not existed.");
+                }
+                schemaMaps.put(
+                        tableId,
+                        SchemaUtils.applySchemaChangeEvent(
+                                schemaMaps.get(tableId), schemaChangeEvent));
+            }
+        }
+        return null;
+    }
+
+    private Record applyDataChangeEvent(DataChangeEvent event) {
+        TableId tableId = event.tableId();
+        Schema schema = schemaMaps.get(tableId);
+        Preconditions.checkNotNull(schema, event.tableId() + " is not 
existed");
+        Object[] values;
+        OperationType op = event.op();
+        boolean isDelete = false;
+        switch (op) {
+            case INSERT:
+            case UPDATE:
+            case REPLACE:
+                values = serializerRecord(event.after(), schema);
+                break;
+            case DELETE:
+                values = serializerRecord(event.before(), schema);
+                isDelete = true;
+                break;
+            default:
+                throw new UnsupportedOperationException("Unsupport Operation " 
+ op);

Review Comment:
   ```suggestion
                   throw new UnsupportedOperationException("Unsupported 
Operation " + op);
   ```



##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oceanbase/src/main/java/org/apache/flink/cdc/connectors/oceanbase/sink/OceanBaseMetadataApplier.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.cdc.connectors.oceanbase.sink;
+
+import org.apache.flink.cdc.common.configuration.Configuration;
+import org.apache.flink.cdc.common.event.AddColumnEvent;
+import org.apache.flink.cdc.common.event.AlterColumnTypeEvent;
+import org.apache.flink.cdc.common.event.CreateTableEvent;
+import org.apache.flink.cdc.common.event.DropColumnEvent;
+import org.apache.flink.cdc.common.event.RenameColumnEvent;
+import org.apache.flink.cdc.common.event.SchemaChangeEvent;
+import org.apache.flink.cdc.common.event.TableId;
+import org.apache.flink.cdc.common.schema.Column;
+import org.apache.flink.cdc.common.schema.Schema;
+import org.apache.flink.cdc.common.sink.MetadataApplier;
+import org.apache.flink.cdc.common.utils.Preconditions;
+import org.apache.flink.cdc.connectors.oceanbase.catalog.OceanBaseCatalog;
+import 
org.apache.flink.cdc.connectors.oceanbase.catalog.OceanBaseCatalogException;
+import 
org.apache.flink.cdc.connectors.oceanbase.catalog.OceanBaseCatalogFactory;
+import org.apache.flink.cdc.connectors.oceanbase.catalog.OceanBaseColumn;
+import org.apache.flink.cdc.connectors.oceanbase.catalog.OceanBaseTable;
+
+import com.oceanbase.connector.flink.OceanBaseConnectorOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/** Supports {@link OceanBaseDataSink} to schema evolution. */
+public class OceanBaseMetadataApplier implements MetadataApplier {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(OceanBaseMetadataApplier.class);
+
+    private final OceanBaseCatalog catalog;
+
+    public OceanBaseMetadataApplier(
+            OceanBaseConnectorOptions connectorOptions, Configuration config) 
throws Exception {
+        this.catalog = 
OceanBaseCatalogFactory.createOceanBaseCatalog(connectorOptions);

Review Comment:
   Unused `Configuration config`.



##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oceanbase/src/main/java/org/apache/flink/cdc/connectors/oceanbase/sink/OceanBaseEventSerializationSchema.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.cdc.connectors.oceanbase.sink;
+
+import org.apache.flink.cdc.common.data.RecordData;
+import org.apache.flink.cdc.common.event.CreateTableEvent;
+import org.apache.flink.cdc.common.event.DataChangeEvent;
+import org.apache.flink.cdc.common.event.Event;
+import org.apache.flink.cdc.common.event.OperationType;
+import org.apache.flink.cdc.common.event.SchemaChangeEvent;
+import org.apache.flink.cdc.common.event.TableId;
+import org.apache.flink.cdc.common.schema.Column;
+import org.apache.flink.cdc.common.schema.Schema;
+import org.apache.flink.cdc.common.utils.Preconditions;
+import org.apache.flink.cdc.common.utils.SchemaUtils;
+
+import org.apache.flink.shaded.guava31.com.google.common.collect.Lists;
+
+import com.oceanbase.connector.flink.table.DataChangeRecord;
+import com.oceanbase.connector.flink.table.Record;
+import com.oceanbase.connector.flink.table.RecordSerializationSchema;
+import com.oceanbase.connector.flink.table.TableInfo;
+
+import java.time.ZoneId;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/** A serializer for Event to Record. */
+public class OceanBaseEventSerializationSchema implements 
RecordSerializationSchema<Event> {
+
+    private final Map<TableId, Schema> schemaMaps = new HashMap<>();
+
+    /** ZoneId from pipeline config to support timestamp with local time zone. 
*/
+    public final ZoneId pipelineZoneId;
+
+    public OceanBaseEventSerializationSchema(ZoneId zoneId) {
+        pipelineZoneId = zoneId;
+    }
+
+    @Override
+    public Record serialize(Event event) {
+        if (event instanceof DataChangeEvent) {
+            return applyDataChangeEvent((DataChangeEvent) event);
+        } else if (event instanceof SchemaChangeEvent) {
+            SchemaChangeEvent schemaChangeEvent = (SchemaChangeEvent) event;
+            TableId tableId = schemaChangeEvent.tableId();
+            if (event instanceof CreateTableEvent) {
+                schemaMaps.put(tableId, ((CreateTableEvent) 
event).getSchema());
+            } else {
+                if (!schemaMaps.containsKey(tableId)) {
+                    throw new RuntimeException("schema of " + tableId + " is 
not existed.");
+                }
+                schemaMaps.put(
+                        tableId,
+                        SchemaUtils.applySchemaChangeEvent(
+                                schemaMaps.get(tableId), schemaChangeEvent));
+            }
+        }
+        return null;
+    }
+
+    private Record applyDataChangeEvent(DataChangeEvent event) {
+        TableId tableId = event.tableId();
+        Schema schema = schemaMaps.get(tableId);
+        Preconditions.checkNotNull(schema, event.tableId() + " is not 
existed");
+        Object[] values;
+        OperationType op = event.op();
+        boolean isDelete = false;
+        switch (op) {
+            case INSERT:
+            case UPDATE:
+            case REPLACE:
+                values = serializerRecord(event.after(), schema);
+                break;
+            case DELETE:
+                values = serializerRecord(event.before(), schema);
+                isDelete = true;
+                break;
+            default:
+                throw new UnsupportedOperationException("Unsupport Operation " 
+ op);
+        }
+        return buildDataChangeRecord(tableId, schema, values, isDelete);
+    }
+
+    private DataChangeRecord buildDataChangeRecord(
+            TableId tableId, Schema schema, Object[] values, boolean isDelete) 
{
+        Preconditions.checkState(
+                Objects.nonNull(tableId.getSchemaName()), "schema name cannot 
be null or empty.");

Review Comment:
   ```suggestion
                   Objects.nonNull(tableId.getSchemaName()), "Schema name 
cannot be null or empty.");
   ```



##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oceanbase/src/main/java/org/apache/flink/cdc/connectors/oceanbase/factory/OceanBaseDataSinkFactory.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.cdc.connectors.oceanbase.factory;
+
+import org.apache.flink.cdc.common.annotation.Internal;
+import org.apache.flink.cdc.common.configuration.ConfigOption;
+import org.apache.flink.cdc.common.configuration.Configuration;
+import org.apache.flink.cdc.common.factories.DataSinkFactory;
+import org.apache.flink.cdc.common.sink.DataSink;
+import org.apache.flink.cdc.connectors.oceanbase.sink.OceanBaseDataSink;
+import org.apache.flink.cdc.connectors.oceanbase.sink.OceanBaseDataSinkOptions;
+
+import com.oceanbase.connector.flink.OceanBaseConnectorOptions;
+
+import java.time.ZoneId;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static 
org.apache.flink.cdc.common.pipeline.PipelineOptions.PIPELINE_LOCAL_TIME_ZONE;
+
+/** A {@link DataSinkFactory} to create {@link OceanBaseDataSink}. */
+@Internal
+public class OceanBaseDataSinkFactory implements DataSinkFactory {
+
+    @Override
+    public DataSink createDataSink(Context context) {
+        Configuration config = context.getFactoryConfiguration();
+        OceanBaseConnectorOptions connectorOptions =
+                new OceanBaseConnectorOptions(buildOceanBaseOptions(config));
+        String zoneStr = 
context.getFactoryConfiguration().get(PIPELINE_LOCAL_TIME_ZONE);
+        ZoneId zoneId =
+                PIPELINE_LOCAL_TIME_ZONE.defaultValue().equals(zoneStr)
+                        ? ZoneId.systemDefault()
+                        : ZoneId.of(zoneStr);
+        return new OceanBaseDataSink(connectorOptions, config, zoneId);
+    }
+
+    public Map<String, String> buildOceanBaseOptions(Configuration config) {
+        Optional<String> optional = 
config.getOptional(OceanBaseDataSinkOptions.PASSWORD);
+        config.remove(OceanBaseDataSinkOptions.PASSWORD);
+        Map<String, String> map = config.toMap();
+        map.put(OceanBaseDataSinkOptions.PASSWORD.key(), optional.orElse(""));

Review Comment:
   I do not know why do this?



##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oceanbase/src/main/java/org/apache/flink/cdc/connectors/oceanbase/catalog/OceanBaseCatalogFactory.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.cdc.connectors.oceanbase.catalog;
+
+import com.oceanbase.connector.flink.OceanBaseConnectorOptions;
+import com.oceanbase.connector.flink.connection.OceanBaseConnectionProvider;
+import com.oceanbase.connector.flink.dialect.OceanBaseDialect;
+import com.oceanbase.connector.flink.dialect.OceanBaseMySQLDialect;
+import com.oceanbase.connector.flink.dialect.OceanBaseOracleDialect;
+
+/** A {@link OceanBaseCatalogFactory} to create {@link OceanBaseCatalog}. */
+public class OceanBaseCatalogFactory {
+
+    public static OceanBaseCatalog createOceanBaseCatalog(
+            OceanBaseConnectorOptions connectorOptions) throws Exception {
+        try (OceanBaseConnectionProvider connectionProvider =
+                new OceanBaseConnectionProvider(connectorOptions)) {
+            OceanBaseDialect dialect = connectionProvider.getDialect();
+            if (dialect instanceof OceanBaseMySQLDialect) {
+                return new OceanBaseMySQLCatalog(connectorOptions);
+            } else if (dialect instanceof OceanBaseOracleDialect) {
+                return new OceanBaseOracleCatalog(connectorOptions);
+            } else {
+                throw new OceanBaseCatalogException("This tenant is not 
supported currently");

Review Comment:
   I think we can throw exception msg with direct means.



-- 
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-unsubscr...@flink.apache.org

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

Reply via email to