wolfboys commented on code in PR #20109: URL: https://github.com/apache/doris/pull/20109#discussion_r1211313763
########## fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcMySQLClient.java: ########## @@ -0,0 +1,177 @@ +// 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.doris.external.jdbc; + +import org.apache.doris.catalog.PrimitiveType; +import org.apache.doris.catalog.ScalarType; +import org.apache.doris.catalog.Type; + +import avro.shaded.com.google.common.collect.Lists; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.function.Consumer; + +public class JdbcMySQLClient extends JdbcClient { + protected JdbcMySQLClient(JdbcClientConfig jdbcClientConfig) { + super(jdbcClientConfig); + } + + @Override + protected String getDatabaseQuery() { + return "SHOW DATABASES"; + } + + @Override + protected List<String> getSpecifiedDatabase(Connection conn) { + List<String> databaseNames = Lists.newArrayList(); + try { + databaseNames.add(conn.getCatalog()); + } catch (SQLException e) { + throw new JdbcClientException("failed to get specified database name from jdbc", e); + } finally { + close(conn); + } + return databaseNames; + } + + @Override + protected void processTable(String dbName, String tableName, String[] tableTypes, + Consumer<ResultSet> resultSetConsumer) { + Connection conn = getConnection(); + ResultSet rs = null; + try { + DatabaseMetaData databaseMetaData = conn.getMetaData(); + rs = databaseMetaData.getTables(dbName, null, tableName, tableTypes); + resultSetConsumer.accept(rs); + } catch (SQLException e) { + throw new JdbcClientException("Failed to process table", e); + } finally { + close(rs, conn); + } + } + + @Override + protected ResultSet getColumns(DatabaseMetaData databaseMetaData, String catalogName, String schemaName, + String tableName) throws SQLException { + return databaseMetaData.getColumns(schemaName, null, tableName, null); + } + + @Override + protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { + // For mysql type: "INT UNSIGNED": + // fieldSchema.getDataTypeName().split(" ")[0] == "INT" + // fieldSchema.getDataTypeName().split(" ")[1] == "UNSIGNED" + String[] typeFields = fieldSchema.getDataTypeName().split(" "); Review Comment: We can improve the code: `fieldSchema.getDataTypeName().split("\\s+")` ########## fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcOceanBaseClient.java: ########## @@ -0,0 +1,70 @@ +// 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.doris.external.jdbc; + +import org.apache.doris.catalog.JdbcResource; +import org.apache.doris.catalog.Type; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +public class JdbcOceanBaseClient extends JdbcClient { + private JdbcClient currentClient; + + public JdbcOceanBaseClient(JdbcClientConfig jdbcClientConfig) { + super(jdbcClientConfig); + + Connection conn = super.getConnection(); + + try { + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SHOW VARIABLES LIKE 'ob_compatibility_mode'"); + if (rs.next()) { + String compatibilityMode = rs.getString(2); + if ("MYSQL".equalsIgnoreCase(compatibilityMode)) { + currentClient = new JdbcMySQLClient(jdbcClientConfig); + } else if ("ORACLE".equalsIgnoreCase(compatibilityMode)) { + currentClient = new JdbcOracleClient(jdbcClientConfig); + setOracleMode(); + } else { + throw new JdbcClientException("Unsupported compatibility mode: " + compatibilityMode); + } + } + } catch (SQLException e) { + throw new JdbcClientException("Failed to determine OceanBase compatibility mode", e); + } finally { + close(conn); Review Comment: close(rs, stmt, conn); -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org