morningman commented on code in PR #28188:
URL: https://github.com/apache/doris/pull/28188#discussion_r1421965549


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/HMSExternalCatalog.java:
##########
@@ -144,32 +145,45 @@ protected List<String> listDatabaseNames() {
 
     @Override
     protected void initLocalObjectsImpl() {
-        HiveConf hiveConf = new HiveConf();
-        for (Map.Entry<String, String> kv : 
catalogProperty.getHadoopProperties().entrySet()) {
-            hiveConf.set(kv.getKey(), kv.getValue());
-        }
-        hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT.name(),
-                String.valueOf(Config.hive_metastore_client_timeout_second));
-        String authentication = catalogProperty.getOrDefault(
-                HdfsResource.HADOOP_SECURITY_AUTHENTICATION, "");
-        if (AuthType.KERBEROS.getDesc().equals(authentication)) {
-            hiveConf.set(HdfsResource.HADOOP_SECURITY_AUTHENTICATION, 
authentication);
-            UserGroupInformation.setConfiguration(hiveConf);
-            try {
-                /**
-                 * Because metastore client is created by using
-                 * {@link 
org.apache.hadoop.hive.metastore.RetryingMetaStoreClient#getProxy}
-                 * it will relogin when TGT is expired, so we don't need to 
relogin manually.
-                 */
-                UserGroupInformation.loginUserFromKeytab(
-                        
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_PRINCIPAL, ""),
-                        
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_KEYTAB, ""));
-            } catch (IOException e) {
-                throw new HMSClientException("login with kerberos auth failed 
for catalog %s", e, this.getName());
+        HiveConf hiveConf = null;
+        JdbcClientConfig jdbcClientConfig = null;
+        String hiveMetastoreType = 
catalogProperty.getOrDefault(HMSProperties.HIVE_META_TYPE, "hms");
+        if (hiveMetastoreType.equalsIgnoreCase("hms")) {
+            hiveConf = new HiveConf();
+            for (Map.Entry<String, String> kv : 
catalogProperty.getHadoopProperties().entrySet()) {
+                hiveConf.set(kv.getKey(), kv.getValue());
+            }
+            
hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT.name(),
+                    
String.valueOf(Config.hive_metastore_client_timeout_second));
+            String authentication = catalogProperty.getOrDefault(
+                    HdfsResource.HADOOP_SECURITY_AUTHENTICATION, "");
+            if (AuthType.KERBEROS.getDesc().equals(authentication)) {
+                hiveConf.set(HdfsResource.HADOOP_SECURITY_AUTHENTICATION, 
authentication);
+                UserGroupInformation.setConfiguration(hiveConf);
+                try {
+                    /**
+                     * Because metastore client is created by using
+                     * {@link 
org.apache.hadoop.hive.metastore.RetryingMetaStoreClient#getProxy}
+                     * it will relogin when TGT is expired, so we don't need 
to relogin manually.
+                     */
+                    UserGroupInformation.loginUserFromKeytab(
+                            
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_PRINCIPAL, ""),
+                            
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_KEYTAB, ""));
+                } catch (IOException e) {
+                    throw new HMSClientException("login with kerberos auth 
failed for catalog %s", e, this.getName());
+                }
             }
+        } else if (hiveMetastoreType.equalsIgnoreCase("jdbc")) {
+            jdbcClientConfig = new JdbcClientConfig();
+            jdbcClientConfig.setUser(catalogProperty.getOrDefault("user", ""));
+            
jdbcClientConfig.setPassword(catalogProperty.getOrDefault("password", ""));
+            
jdbcClientConfig.setJdbcUrl(catalogProperty.getOrDefault("jdbc_url", ""));
+            
jdbcClientConfig.setDriverUrl(catalogProperty.getOrDefault("driver_url", ""));
+            
jdbcClientConfig.setDriverClass(catalogProperty.getOrDefault("driver_class", 
""));
+        } else {
+            LOG.error("Do not support hive_meta_type = " + hiveMetastoreType);

Review Comment:
   Throw HMSClientException



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/HMSExternalCatalog.java:
##########
@@ -144,32 +145,45 @@ protected List<String> listDatabaseNames() {
 
     @Override
     protected void initLocalObjectsImpl() {
-        HiveConf hiveConf = new HiveConf();
-        for (Map.Entry<String, String> kv : 
catalogProperty.getHadoopProperties().entrySet()) {
-            hiveConf.set(kv.getKey(), kv.getValue());
-        }
-        hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT.name(),
-                String.valueOf(Config.hive_metastore_client_timeout_second));
-        String authentication = catalogProperty.getOrDefault(
-                HdfsResource.HADOOP_SECURITY_AUTHENTICATION, "");
-        if (AuthType.KERBEROS.getDesc().equals(authentication)) {
-            hiveConf.set(HdfsResource.HADOOP_SECURITY_AUTHENTICATION, 
authentication);
-            UserGroupInformation.setConfiguration(hiveConf);
-            try {
-                /**
-                 * Because metastore client is created by using
-                 * {@link 
org.apache.hadoop.hive.metastore.RetryingMetaStoreClient#getProxy}
-                 * it will relogin when TGT is expired, so we don't need to 
relogin manually.
-                 */
-                UserGroupInformation.loginUserFromKeytab(
-                        
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_PRINCIPAL, ""),
-                        
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_KEYTAB, ""));
-            } catch (IOException e) {
-                throw new HMSClientException("login with kerberos auth failed 
for catalog %s", e, this.getName());
+        HiveConf hiveConf = null;
+        JdbcClientConfig jdbcClientConfig = null;
+        String hiveMetastoreType = 
catalogProperty.getOrDefault(HMSProperties.HIVE_META_TYPE, "hms");
+        if (hiveMetastoreType.equalsIgnoreCase("hms")) {
+            hiveConf = new HiveConf();
+            for (Map.Entry<String, String> kv : 
catalogProperty.getHadoopProperties().entrySet()) {
+                hiveConf.set(kv.getKey(), kv.getValue());
+            }
+            
hiveConf.set(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT.name(),
+                    
String.valueOf(Config.hive_metastore_client_timeout_second));
+            String authentication = catalogProperty.getOrDefault(
+                    HdfsResource.HADOOP_SECURITY_AUTHENTICATION, "");
+            if (AuthType.KERBEROS.getDesc().equals(authentication)) {
+                hiveConf.set(HdfsResource.HADOOP_SECURITY_AUTHENTICATION, 
authentication);
+                UserGroupInformation.setConfiguration(hiveConf);
+                try {
+                    /**
+                     * Because metastore client is created by using
+                     * {@link 
org.apache.hadoop.hive.metastore.RetryingMetaStoreClient#getProxy}
+                     * it will relogin when TGT is expired, so we don't need 
to relogin manually.
+                     */
+                    UserGroupInformation.loginUserFromKeytab(
+                            
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_PRINCIPAL, ""),
+                            
catalogProperty.getOrDefault(HdfsResource.HADOOP_KERBEROS_KEYTAB, ""));
+                } catch (IOException e) {
+                    throw new HMSClientException("login with kerberos auth 
failed for catalog %s", e, this.getName());
+                }
             }
+        } else if (hiveMetastoreType.equalsIgnoreCase("jdbc")) {
+            jdbcClientConfig = new JdbcClientConfig();
+            jdbcClientConfig.setUser(catalogProperty.getOrDefault("user", ""));
+            
jdbcClientConfig.setPassword(catalogProperty.getOrDefault("password", ""));
+            
jdbcClientConfig.setJdbcUrl(catalogProperty.getOrDefault("jdbc_url", ""));
+            
jdbcClientConfig.setDriverUrl(catalogProperty.getOrDefault("driver_url", ""));
+            
jdbcClientConfig.setDriverClass(catalogProperty.getOrDefault("driver_class", 
""));
+        } else {
+            LOG.error("Do not support hive_meta_type = " + hiveMetastoreType);

Review Comment:
   ```suggestion
               LOG.warn("Do not support hive_meta_type = " + hiveMetastoreType);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/CachedClientFactory.java:
##########
@@ -0,0 +1,42 @@
+// 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.datasource.hive;
+
+import org.apache.doris.catalog.JdbcResource;
+import org.apache.doris.datasource.jdbc.client.JdbcClient;
+import org.apache.doris.datasource.jdbc.client.JdbcClientConfig;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hive.conf.HiveConf;
+
+public class CachedClientFactory {

Review Comment:
   ```suggestion
   public class HMSCachedClientFactory {
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/CachedClientFactory.java:
##########
@@ -0,0 +1,42 @@
+// 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.datasource.hive;
+
+import org.apache.doris.catalog.JdbcResource;
+import org.apache.doris.datasource.jdbc.client.JdbcClient;
+import org.apache.doris.datasource.jdbc.client.JdbcClientConfig;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hive.conf.HiveConf;
+
+public class CachedClientFactory {
+    public static CachedClient createCachedClient(PooledHiveMetaStoreClient 
pooledHiveMetaStoreClient,
+            HiveConf hiveConf, JdbcClientConfig jdbcClientConfig) throws 
Exception {
+        if (hiveConf != null) {
+            return new IMetaStoreClientCachedClient(hiveConf, 
pooledHiveMetaStoreClient);

Review Comment:
   ```suggestion
               return new 
IMetaStoreClientCachedClient(pooledHiveMetaStoreClient, hiveConf);
   ```
   Same order as `HivePostgreSQLCachedClient`



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/CachedClient.java:
##########
@@ -0,0 +1,85 @@
+// 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.datasource.hive;
+
+import org.apache.hadoop.hive.common.ValidTxnList;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
+import org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.LockRequest;
+import org.apache.hadoop.hive.metastore.api.LockResponse;
+import org.apache.hadoop.hive.metastore.api.NotificationEventResponse;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.api.TableValidWriteIds;
+
+import java.util.List;
+import java.util.Map;
+
+public interface CachedClient extends AutoCloseable {

Review Comment:
   ```suggestion
   public interface HMSCachedClient extends AutoCloseable {
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/IMetaStoreClientCachedClient.java:
##########
@@ -0,0 +1,195 @@
+// 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.datasource.hive;
+
+import org.apache.doris.common.Config;
+import org.apache.doris.datasource.property.constants.HMSProperties;
+
+import com.aliyun.datalake.metastore.hive2.ProxyMetaStoreClient;
+import com.amazonaws.glue.catalog.metastore.AWSCatalogMetastoreClient;
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hive.common.ValidTxnList;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaHookLoader;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient.NotificationFilter;
+import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
+import org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.LockRequest;
+import org.apache.hadoop.hive.metastore.api.LockResponse;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NotificationEventResponse;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.api.TableValidWriteIds;
+
+import java.util.List;
+import java.util.Map;
+
+public class IMetaStoreClientCachedClient implements CachedClient {

Review Comment:
   ```suggestion
   public class ThriftHMSCachedClient implements CachedClient {
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/CachedClient.java:
##########
@@ -0,0 +1,85 @@
+// 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.datasource.hive;
+
+import org.apache.hadoop.hive.common.ValidTxnList;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
+import org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.LockRequest;
+import org.apache.hadoop.hive.metastore.api.LockResponse;
+import org.apache.hadoop.hive.metastore.api.NotificationEventResponse;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.api.TableValidWriteIds;
+
+import java.util.List;
+import java.util.Map;
+
+public interface CachedClient extends AutoCloseable {

Review Comment:
   Add comment for this class



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/property/constants/HMSProperties.java:
##########
@@ -27,6 +27,7 @@ public class HMSProperties {
     public static final String HIVE_VERSION = "hive.version";
     // required
     public static final String HIVE_METASTORE_URIS = "hive.metastore.uris";
+    public static final String HIVE_META_TYPE = "hive_meta_type";

Review Comment:
   ```suggestion
       public static final String HIVE_META_TYPE = "hive.meta_type";
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveJdbcCachedClient.java:
##########
@@ -0,0 +1,57 @@
+// 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.datasource.hive;
+
+import org.apache.doris.datasource.jdbc.client.JdbcClient;
+import org.apache.doris.datasource.jdbc.client.JdbcClientConfig;
+
+import com.google.common.base.Preconditions;
+
+public abstract class HiveJdbcCachedClient extends JdbcClient implements 
CachedClient {

Review Comment:
   ```suggestion
   public abstract class JdbcHMSCachedClient extends JdbcClient implements 
CachedClient {
   ```



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

Reply via email to