eskabetxe commented on code in PR #109:
URL: 
https://github.com/apache/flink-connector-jdbc/pull/109#discussion_r1605664750


##########
flink-connector-jdbc/src/test/java/org/apache/flink/connector/jdbc/databases/oceanbase/catalog/OceanBaseOracleCatalogITCase.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.connector.jdbc.databases.oceanbase.catalog;
+
+import 
org.apache.flink.connector.jdbc.databases.oceanbase.OceanBaseOracleTestBase;
+import org.apache.flink.connector.jdbc.testutils.TableManaged;
+import org.apache.flink.connector.jdbc.testutils.tables.TableRow;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.types.Row;
+
+import org.junit.jupiter.api.Disabled;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.Arrays;
+import java.util.List;
+
+import static 
org.apache.flink.connector.jdbc.databases.oceanbase.OceanBaseOracleTestBase.tableRow;
+import static 
org.apache.flink.connector.jdbc.testutils.tables.TableBuilder.dbType;
+import static 
org.apache.flink.connector.jdbc.testutils.tables.TableBuilder.field;
+import static 
org.apache.flink.connector.jdbc.testutils.tables.TableBuilder.pkField;
+
+/** E2E test for {@link OceanBaseCatalog} with OceanBase Oracle mode. */
+@Disabled

Review Comment:
   is this disable by some reason?
   if yes, could we add some comment why..



##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/databases/oceanbase/catalog/OceanBaseCatalog.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.connector.jdbc.databases.oceanbase.catalog;
+
+import org.apache.flink.connector.jdbc.catalog.AbstractJdbcCatalog;
+import org.apache.flink.connector.jdbc.dialect.JdbcDialectTypeMapper;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.UniqueConstraint;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+
+import static 
org.apache.flink.connector.jdbc.table.JdbcConnectorOptions.COMPATIBLE_MODE;
+
+/** Catalog for OceanBase. */
+public class OceanBaseCatalog extends AbstractJdbcCatalog {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(OceanBaseCatalog.class);
+
+    private static final Set<String> builtinDatabases =
+            new HashSet<String>() {
+                {
+                    add("__public");
+                    add("information_schema");
+                    add("mysql");
+                    add("oceanbase");
+                    add("LBACSYS");
+                    add("ORAAUDITOR");
+                }
+            };
+
+    private final String compatibleMode;
+    private final JdbcDialectTypeMapper dialectTypeMapper;
+
+    public OceanBaseCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String compatibleMode,
+            String defaultDatabase,
+            String baseUrl,
+            Properties connectionProperties) {
+        super(userClassLoader, catalogName, defaultDatabase, baseUrl, 
connectionProperties);
+        this.compatibleMode = compatibleMode;
+        this.dialectTypeMapper = new OceanBaseTypeMapper(compatibleMode);
+    }
+
+    private boolean isMySQLMode() {
+        return "mysql".equalsIgnoreCase(compatibleMode);
+    }
+
+    private String getConnUrl() {
+        return isMySQLMode() ? baseUrl : defaultUrl;
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        if (isMySQLMode()) {
+            return extractColumnValuesBySQL(
+                    getConnUrl(),
+                    "SELECT `SCHEMA_NAME` FROM 
`INFORMATION_SCHEMA`.`SCHEMATA`",
+                    1,
+                    dbName -> !builtinDatabases.contains(dbName));
+        }
+        return extractColumnValuesBySQL(
+                getConnUrl(),
+                "SELECT USERNAME FROM ALL_USERS",
+                1,
+                schema -> !builtinDatabases.contains(schema));
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        Preconditions.checkState(
+                StringUtils.isNotBlank(databaseName), "Database name must not 
be blank.");
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        String sql =
+                isMySQLMode()
+                        ? "SELECT TABLE_NAME FROM information_schema.`TABLES` 
WHERE TABLE_SCHEMA = ?"
+                        : "SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = ?";
+        return extractColumnValuesBySQL(getConnUrl(), sql, 1, null, 
databaseName);
+    }
+
+    @Override
+    public boolean tableExists(ObjectPath tablePath) throws CatalogException {
+        return isMySQLMode()
+                ? !extractColumnValuesBySQL(
+                                getConnUrl(),
+                                "SELECT TABLE_NAME FROM 
information_schema.`TABLES` "
+                                        + "WHERE TABLE_SCHEMA = ? and 
TABLE_NAME = ?",
+                                1,
+                                null,
+                                tablePath.getDatabaseName(),
+                                tablePath.getObjectName())
+                        .isEmpty()
+                : !extractColumnValuesBySQL(
+                                getConnUrl(),
+                                "SELECT TABLE_NAME FROM ALL_TABLES "
+                                        + "WHERE OWNER = ? and TABLE_NAME = ?",
+                                1,
+                                null,
+                                tablePath.getDatabaseName(),
+                                tablePath.getObjectName())
+                        .isEmpty();

Review Comment:
   ```
   String query = isMySQLMode()
           ? "SELECT TABLE_NAME FROM information_schema.`TABLES` "
                           + "WHERE TABLE_SCHEMA = ? and TABLE_NAME = ?"
           : "SELECT TABLE_NAME FROM ALL_TABLES "
                           + "WHERE OWNER = ? and TABLE_NAME = ?";
   
   return !extractColumnValuesBySQL(
                   getConnUrl(),
                   query,
                   1,
                   null,
                   tablePath.getDatabaseName(),
                   tablePath.getObjectName())
           .isEmpty();
   ```



##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/databases/oceanbase/catalog/OceanBaseCatalog.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.connector.jdbc.databases.oceanbase.catalog;
+
+import org.apache.flink.connector.jdbc.catalog.AbstractJdbcCatalog;
+import org.apache.flink.connector.jdbc.dialect.JdbcDialectTypeMapper;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.UniqueConstraint;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+
+import static 
org.apache.flink.connector.jdbc.table.JdbcConnectorOptions.COMPATIBLE_MODE;
+
+/** Catalog for OceanBase. */
+public class OceanBaseCatalog extends AbstractJdbcCatalog {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(OceanBaseCatalog.class);
+
+    private static final Set<String> builtinDatabases =
+            new HashSet<String>() {
+                {
+                    add("__public");
+                    add("information_schema");
+                    add("mysql");
+                    add("oceanbase");
+                    add("LBACSYS");
+                    add("ORAAUDITOR");
+                }
+            };
+
+    private final String compatibleMode;
+    private final JdbcDialectTypeMapper dialectTypeMapper;
+
+    public OceanBaseCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String compatibleMode,
+            String defaultDatabase,
+            String baseUrl,
+            Properties connectionProperties) {
+        super(userClassLoader, catalogName, defaultDatabase, baseUrl, 
connectionProperties);
+        this.compatibleMode = compatibleMode;
+        this.dialectTypeMapper = new OceanBaseTypeMapper(compatibleMode);
+    }
+
+    private boolean isMySQLMode() {
+        return "mysql".equalsIgnoreCase(compatibleMode);
+    }
+
+    private String getConnUrl() {
+        return isMySQLMode() ? baseUrl : defaultUrl;
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        if (isMySQLMode()) {
+            return extractColumnValuesBySQL(
+                    getConnUrl(),
+                    "SELECT `SCHEMA_NAME` FROM 
`INFORMATION_SCHEMA`.`SCHEMATA`",
+                    1,
+                    dbName -> !builtinDatabases.contains(dbName));
+        }
+        return extractColumnValuesBySQL(
+                getConnUrl(),
+                "SELECT USERNAME FROM ALL_USERS",
+                1,
+                schema -> !builtinDatabases.contains(schema));

Review Comment:
   ```
   String query = isMySQLMode()
           ? "SELECT `SCHEMA_NAME` FROM `INFORMATION_SCHEMA`.`SCHEMATA`"
           : "SELECT USERNAME FROM ALL_USERS";
   
   return extractColumnValuesBySQL(
           getConnUrl(),
           "SELECT USERNAME FROM ALL_USERS",
           1,
           dbName -> !builtinDatabases.contains(dbName));
   ```



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