You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/01/26 02:02:18 UTC

[GitHub] [hive] mustafaiman commented on a change in pull request #1733: HIVE-24346. Store HPL/SQL packages into HMS (amagyar)

mustafaiman commented on a change in pull request #1733:
URL: https://github.com/apache/hive/pull/1733#discussion_r564132231



##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/packages/HmsPackageRegistry.java
##########
@@ -0,0 +1,87 @@
+/*
+ *  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.hive.hplsql.packages;
+
+import java.util.Optional;
+
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.PackageRequest;
+import org.apache.hadoop.hive.metastore.api.Package;
+import org.apache.hive.hplsql.HplSqlSessionState;
+import org.apache.thrift.TException;
+
+public class HmsPackageRegistry implements PackageRegistry {
+  private final IMetaStoreClient msc;
+  private final HplSqlSessionState hplSqlSession;
+
+  public HmsPackageRegistry(IMetaStoreClient msc, HplSqlSessionState hplSqlSession) {
+    this.msc = msc;
+    this.hplSqlSession = hplSqlSession;
+  }
+
+  @Override
+  public Optional<String> findPackage(String name) {
+    try {
+      Package pkg = msc.findPackage(request(name));
+      return pkg == null
+              ? Optional.empty()
+              : Optional.of(pkg.getHeader() + ";\n" + pkg.getBody());
+    } catch (TException e) {
+      throw new RuntimeException(e.getCause());
+    }
+  }
+
+  @Override
+  public void createPackage(String name, String header) {
+    try {
+      msc.addPackage(makePackage(name, header, ""));
+    } catch (TException e) {
+      throw new RuntimeException(e.getCause());
+    }
+  }
+
+  @Override
+  public void createPackageBody(String name, String body) {
+    try {
+      Package existing = msc.findPackage(request(name));
+      if (existing == null) {
+        msc.addPackage(makePackage(name, "", body));
+      } else {
+        existing.setBody(body);
+        msc.addPackage(existing);
+      }
+    } catch (TException e) {
+      throw new RuntimeException(e.getCause());
+    }
+  }
+
+  private PackageRequest request(String name) {
+    return new PackageRequest(hplSqlSession.currentCatalog(), hplSqlSession.currentDatabase(), name.toUpperCase());
+  }
+
+  protected Package makePackage(String name, String header, String body) {

Review comment:
       could be `private`

##########
File path: standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
##########
@@ -2856,6 +2876,11 @@ PartitionsResponse get_partitions_req(1:PartitionsRequest req)
   StoredProcedure get_stored_procedure(1: StoredProcedureRequest request) throws (1:MetaException o1, 2:NoSuchObjectException o2)
   void drop_stored_procedure(1: StoredProcedureRequest request) throws (1:MetaException o1, 2:NoSuchObjectException o2)
   list<string> get_all_stored_procedures(1: ListStoredProcedureRequest request) throws (1:MetaException o1)
+
+  Package find_package(1: PackageRequest request) throws (1:MetaException o1)

Review comment:
       PackageRequest is a struct with 3 required string fields. I think it is clearer if we pass the strings directly instead of creating `PackageRequest`

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/packages/PackageRegistry.java
##########
@@ -0,0 +1,27 @@
+/*
+ *  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.hive.hplsql.packages;
+
+import java.util.Optional;
+
+public interface PackageRegistry {
+  Optional<String> findPackage(String name);

Review comment:
       Does this `Optional` provide any value? You create the Optional in `findPackage` in both cases. Then, when you use that Optional in Exec.java, you return a null when Optional is not present. Could be null all the way




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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org