You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "FangYongs (via GitHub)" <gi...@apache.org> on 2023/11/06 08:18:08 UTC

[PR] [lineage] Introduce jdbc lineage meta implementations [incubator-paimon]

FangYongs opened a new pull request, #2267:
URL: https://github.com/apache/incubator-paimon/pull/2267

   ### Purpose
   
   Linked issue: close #1480 
   
   This PR aims to introduce jdbc lineage meta with following capabilities:
   1. Configure jdbc relevant options such as url, user and password
   2. Create source/sink lineage tables if `jdbc.auto-ddl` is true
   
   ### Tests
   
   1. Added test `JdbcLineageMetaTest` to validate auto ddl for source/sink lineage tables.
   
   ### API and Format
   
   no
   
   ### Documentation
   
   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@paimon.apache.org

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


Re: [PR] [lineage] Introduce jdbc lineage meta implementations [incubator-paimon]

Posted by "liming30 (via GitHub)" <gi...@apache.org>.
liming30 commented on code in PR #2267:
URL: https://github.com/apache/incubator-paimon/pull/2267#discussion_r1383242590


##########
paimon-common/src/main/java/org/apache/paimon/options/CatalogOptions.java:
##########
@@ -97,4 +97,31 @@ public class CatalogOptions {
                                             TextElement.text(
                                                     "\"custom\": You can implement LineageMetaFactory and LineageMeta to store lineage information in customized storage."))
                                     .build());
+
+    public static final ConfigOption<String> JDBC_URL =
+            key("jdbc.url")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Jdbc url for Paimon to store some information such as lineage and meta.");
+
+    public static final ConfigOption<String> JDBC_USER =
+            key("jdbc.user")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Jdbc user name for Paimon to store some information such as lineage and meta.");
+
+    public static final ConfigOption<String> JDBC_PASSWORD =
+            key("jdbc.password")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Jdbc password for Paimon to store some information such as lineage and meta.");
+
+    public static final ConfigOption<Boolean> JDBC_AUTO_DDL =
+            key("jdbc.auto-ddl")

Review Comment:
   How about replacing it with `jdbc.auto-create`?



##########
paimon-common/src/main/java/org/apache/paimon/lineage/JdbcLineageMeta.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.lineage;
+
+import org.apache.paimon.annotation.VisibleForTesting;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.predicate.Predicate;
+import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.EncodingUtils;
+import org.apache.paimon.utils.StringUtils;
+
+import javax.annotation.Nullable;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.apache.paimon.lineage.LineageMetaUtils.SINK_TABLE_LINEAGE;
+import static org.apache.paimon.lineage.LineageMetaUtils.SOURCE_TABLE_LINEAGE;
+import static org.apache.paimon.lineage.LineageMetaUtils.tableLineagePrimaryKeys;
+import static org.apache.paimon.lineage.LineageMetaUtils.tableLineageRowType;
+import static org.apache.paimon.options.CatalogOptions.JDBC_AUTO_DDL;
+import static org.apache.paimon.options.CatalogOptions.JDBC_PASSWORD;
+import static org.apache.paimon.options.CatalogOptions.JDBC_URL;
+import static org.apache.paimon.options.CatalogOptions.JDBC_USER;
+
+/** Use jdbc to Paimon meta inforation such as table and data lineage. */
+public class JdbcLineageMeta implements LineageMeta {
+    private final Connection connection;
+    private final Statement statement;
+
+    public JdbcLineageMeta(Options options) throws Exception {
+        String url = options.get(JDBC_URL);
+        String user = options.getOptional(JDBC_USER).orElse(null);
+        String password = options.getOptional(JDBC_PASSWORD).orElse(null);
+
+        this.connection =
+                user != null && password != null
+                        ? DriverManager.getConnection(url, user, password)
+                        : DriverManager.getConnection(url);
+        this.statement = connection.createStatement();
+
+        if (options.get(JDBC_AUTO_DDL)) {
+            initializeTables();
+        }
+    }
+
+    private void initializeTables() throws Exception {
+        String sourceTableLineageSql =
+                buildDDL(SOURCE_TABLE_LINEAGE, tableLineageRowType(), tableLineagePrimaryKeys());
+        statement.execute(sourceTableLineageSql);
+
+        String sinkTableLineageSql =
+                buildDDL(SINK_TABLE_LINEAGE, tableLineageRowType(), tableLineagePrimaryKeys());
+        statement.execute(sinkTableLineageSql);
+    }
+
+    private String buildDDL(String tableName, RowType rowType, List<String> primaryKeys) {
+        List<String> fieldSqlList = new ArrayList<>();
+        for (DataField dataField : rowType.getFields()) {
+            fieldSqlList.add(
+                    dataField
+                            .asSQLString()
+                            .replace(
+                                    EncodingUtils.escapeIdentifier(dataField.name()),
+                                    dataField.name())

Review Comment:
   Why does it need to be replaced?



##########
paimon-common/src/main/java/org/apache/paimon/options/CatalogOptions.java:
##########
@@ -97,4 +97,31 @@ public class CatalogOptions {
                                             TextElement.text(
                                                     "\"custom\": You can implement LineageMetaFactory and LineageMeta to store lineage information in customized storage."))
                                     .build());
+
+    public static final ConfigOption<String> JDBC_URL =
+            key("jdbc.url")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Jdbc url for Paimon to store some information such as lineage and meta.");
+
+    public static final ConfigOption<String> JDBC_USER =
+            key("jdbc.user")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Jdbc user name for Paimon to store some information such as lineage and meta.");
+
+    public static final ConfigOption<String> JDBC_PASSWORD =
+            key("jdbc.password")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Jdbc password for Paimon to store some information such as lineage and meta.");
+
+    public static final ConfigOption<Boolean> JDBC_AUTO_DDL =

Review Comment:
   If these options are only provided to lineage for use, I prefer to add some prefixes in front, and considering other implementations in the future, the prefix can be `lineage.kind.${identifier}.xxx`.



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

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