ayushtkn commented on code in PR #4720: URL: https://github.com/apache/hive/pull/4720#discussion_r1329594335
########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/HiveJDBCConnectorProvider.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.hadoop.hive.metastore.dataconnector.jdbc; + +import org.apache.hadoop.hive.metastore.ColumnType; +import org.apache.hadoop.hive.metastore.api.DataConnector; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class HiveJDBCConnectorProvider extends AbstractJDBCConnectorProvider { + private static Logger LOG = LoggerFactory.getLogger(HiveJDBCConnectorProvider.class); Review Comment: this can be final ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/HiveJDBCConnectorProvider.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.hadoop.hive.metastore.dataconnector.jdbc; + +import org.apache.hadoop.hive.metastore.ColumnType; +import org.apache.hadoop.hive.metastore.api.DataConnector; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class HiveJDBCConnectorProvider extends AbstractJDBCConnectorProvider { + private static Logger LOG = LoggerFactory.getLogger(HiveJDBCConnectorProvider.class); + + private static final String DRIVER_CLASS = "org.apache.hive.jdbc.HiveDriver".intern(); Review Comment: I don't think intern is required for compile time constant? https://stackoverflow.com/questions/23720381/when-is-interning-during-done-during-compile-time-or-run-time-the-reason-for-su ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/HiveJDBCConnectorProvider.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.hadoop.hive.metastore.dataconnector.jdbc; + +import org.apache.hadoop.hive.metastore.ColumnType; +import org.apache.hadoop.hive.metastore.api.DataConnector; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class HiveJDBCConnectorProvider extends AbstractJDBCConnectorProvider { + private static Logger LOG = LoggerFactory.getLogger(HiveJDBCConnectorProvider.class); + + private static final String DRIVER_CLASS = "org.apache.hive.jdbc.HiveDriver".intern(); + + public HiveJDBCConnectorProvider(String dbName, DataConnector dataConn) { + super(dbName, dataConn, DRIVER_CLASS); + } + + /** + * Returns a list of all table names from the remote database. + * @return List A collection of all the table names, null if there are no tables. + * @throws MetaException To indicate any failures with executing this API + */ + @Override protected ResultSet fetchTableNames() throws MetaException { + ResultSet rs = null; + try { + rs = getConnection().getMetaData().getTables(scoped_db, null, null, new String[] { "TABLE" }); + } catch (SQLException sqle) { + LOG.warn("Could not retrieve table names from remote datasource, cause:" + sqle.getMessage()); + throw new MetaException("Could not retrieve table names from remote datasource, cause:" + sqle); + } + return rs; + } + + /** + * Fetch a single table with the given name, returns a Hive Table object from the remote database + * @return Table A Table object for the matching table, null otherwise. + * @throws MetaException To indicate any failures with executing this API + * @param tableName + */ + @Override public ResultSet fetchTableMetadata(String tableName) throws MetaException { + ResultSet rs = null; + try { + rs = getConnection().getMetaData().getColumns(null, scoped_db, tableName, null); + } catch (Exception ex) { + LOG.warn("Could not retrieve table names from remote datasource, cause:" + ex.getMessage()); + throw new MetaException("Could not retrieve table names from remote datasource, cause:" + ex); + } + return rs; +} + + @Override protected String getCatalogName() { + return null; + } + + @Override protected String getDatabaseName() { + return scoped_db; + } + + protected String getDataType(String dbDataType, int size) { + String mappedType = super.getDataType(dbDataType, size); + if (!mappedType.equalsIgnoreCase(ColumnType.VOID_TYPE_NAME)) { + return mappedType; + } + + // map any db specific types here. + switch (dbDataType.toLowerCase()) + { + case "string": + mappedType = ColumnType.STRING_TYPE_NAME; + break; + default: + mappedType = ColumnType.VOID_TYPE_NAME; + break; + } Review Comment: there are only 2 cases? we could have used if-else ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/HiveJDBCConnectorProvider.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.hadoop.hive.metastore.dataconnector.jdbc; + +import org.apache.hadoop.hive.metastore.ColumnType; +import org.apache.hadoop.hive.metastore.api.DataConnector; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class HiveJDBCConnectorProvider extends AbstractJDBCConnectorProvider { + private static Logger LOG = LoggerFactory.getLogger(HiveJDBCConnectorProvider.class); + + private static final String DRIVER_CLASS = "org.apache.hive.jdbc.HiveDriver".intern(); + + public HiveJDBCConnectorProvider(String dbName, DataConnector dataConn) { + super(dbName, dataConn, DRIVER_CLASS); + } + + /** + * Returns a list of all table names from the remote database. + * @return List A collection of all the table names, null if there are no tables. + * @throws MetaException To indicate any failures with executing this API + */ + @Override protected ResultSet fetchTableNames() throws MetaException { + ResultSet rs = null; + try { + rs = getConnection().getMetaData().getTables(scoped_db, null, null, new String[] { "TABLE" }); + } catch (SQLException sqle) { + LOG.warn("Could not retrieve table names from remote datasource, cause:" + sqle.getMessage()); + throw new MetaException("Could not retrieve table names from remote datasource, cause:" + sqle); + } + return rs; + } + + /** + * Fetch a single table with the given name, returns a Hive Table object from the remote database + * @return Table A Table object for the matching table, null otherwise. + * @throws MetaException To indicate any failures with executing this API + * @param tableName + */ + @Override public ResultSet fetchTableMetadata(String tableName) throws MetaException { + ResultSet rs = null; + try { + rs = getConnection().getMetaData().getColumns(null, scoped_db, tableName, null); + } catch (Exception ex) { + LOG.warn("Could not retrieve table names from remote datasource, cause:" + ex.getMessage()); + throw new MetaException("Could not retrieve table names from remote datasource, cause:" + ex); + } + return rs; +} + + @Override protected String getCatalogName() { + return null; + } + + @Override protected String getDatabaseName() { + return scoped_db; + } + + protected String getDataType(String dbDataType, int size) { Review Comment: missing ``Override`` annotation ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/HiveJDBCConnectorProvider.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.hadoop.hive.metastore.dataconnector.jdbc; + +import org.apache.hadoop.hive.metastore.ColumnType; +import org.apache.hadoop.hive.metastore.api.DataConnector; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class HiveJDBCConnectorProvider extends AbstractJDBCConnectorProvider { + private static Logger LOG = LoggerFactory.getLogger(HiveJDBCConnectorProvider.class); + + private static final String DRIVER_CLASS = "org.apache.hive.jdbc.HiveDriver".intern(); + + public HiveJDBCConnectorProvider(String dbName, DataConnector dataConn) { + super(dbName, dataConn, DRIVER_CLASS); + } + + /** + * Returns a list of all table names from the remote database. + * @return List A collection of all the table names, null if there are no tables. + * @throws MetaException To indicate any failures with executing this API + */ + @Override protected ResultSet fetchTableNames() throws MetaException { + ResultSet rs = null; + try { + rs = getConnection().getMetaData().getTables(scoped_db, null, null, new String[] { "TABLE" }); + } catch (SQLException sqle) { + LOG.warn("Could not retrieve table names from remote datasource, cause:" + sqle.getMessage()); + throw new MetaException("Could not retrieve table names from remote datasource, cause:" + sqle); + } + return rs; + } + + /** + * Fetch a single table with the given name, returns a Hive Table object from the remote database + * @return Table A Table object for the matching table, null otherwise. + * @throws MetaException To indicate any failures with executing this API + * @param tableName + */ + @Override public ResultSet fetchTableMetadata(String tableName) throws MetaException { Review Comment: this method is also dupe in 3 places: MSSQLConnectorProvider, OracleConnectorProvider & here. maybe now or later we should consider a refactor into a common place and use ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/HiveJDBCConnectorProvider.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.hadoop.hive.metastore.dataconnector.jdbc; + +import org.apache.hadoop.hive.metastore.ColumnType; +import org.apache.hadoop.hive.metastore.api.DataConnector; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class HiveJDBCConnectorProvider extends AbstractJDBCConnectorProvider { + private static Logger LOG = LoggerFactory.getLogger(HiveJDBCConnectorProvider.class); + + private static final String DRIVER_CLASS = "org.apache.hive.jdbc.HiveDriver".intern(); + + public HiveJDBCConnectorProvider(String dbName, DataConnector dataConn) { + super(dbName, dataConn, DRIVER_CLASS); + } + + /** + * Returns a list of all table names from the remote database. + * @return List A collection of all the table names, null if there are no tables. + * @throws MetaException To indicate any failures with executing this API + */ + @Override protected ResultSet fetchTableNames() throws MetaException { + ResultSet rs = null; + try { + rs = getConnection().getMetaData().getTables(scoped_db, null, null, new String[] { "TABLE" }); + } catch (SQLException sqle) { + LOG.warn("Could not retrieve table names from remote datasource, cause:" + sqle.getMessage()); + throw new MetaException("Could not retrieve table names from remote datasource, cause:" + sqle); + } + return rs; + } + + /** + * Fetch a single table with the given name, returns a Hive Table object from the remote database + * @return Table A Table object for the matching table, null otherwise. + * @throws MetaException To indicate any failures with executing this API + * @param tableName + */ + @Override public ResultSet fetchTableMetadata(String tableName) throws MetaException { + ResultSet rs = null; + try { + rs = getConnection().getMetaData().getColumns(null, scoped_db, tableName, null); + } catch (Exception ex) { + LOG.warn("Could not retrieve table names from remote datasource, cause:" + ex.getMessage()); Review Comment: should use logger format ``` LOG.warn("Could not retrieve table names from remote datasource, cause: {}", ex.getMessage()); ``` ########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/HiveJDBCConnectorProvider.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.hadoop.hive.metastore.dataconnector.jdbc; + +import org.apache.hadoop.hive.metastore.ColumnType; +import org.apache.hadoop.hive.metastore.api.DataConnector; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class HiveJDBCConnectorProvider extends AbstractJDBCConnectorProvider { + private static Logger LOG = LoggerFactory.getLogger(HiveJDBCConnectorProvider.class); + + private static final String DRIVER_CLASS = "org.apache.hive.jdbc.HiveDriver".intern(); + + public HiveJDBCConnectorProvider(String dbName, DataConnector dataConn) { + super(dbName, dataConn, DRIVER_CLASS); + } + + /** + * Returns a list of all table names from the remote database. + * @return List A collection of all the table names, null if there are no tables. + * @throws MetaException To indicate any failures with executing this API + */ + @Override protected ResultSet fetchTableNames() throws MetaException { + ResultSet rs = null; Review Comment: this is dupe in 3 classes: here, DerbySQLConnectorProvider.java, MySQLConnectorProvider.java may be we should consider a refactor? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
