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



##########
File path: 
hplsql/src/main/java/org/apache/hive/hplsql/packages/HmsPackageRegistry.java
##########
@@ -0,0 +1,103 @@
+/*
+ *  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.commons.lang3.StringUtils;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.AddPackageRequest;
+import org.apache.hadoop.hive.metastore.api.DropPackageRequest;
+import org.apache.hadoop.hive.metastore.api.GetPackageRequest;
+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> getPackage(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 createPackageHeader(String name, String header, boolean replace) 
{
+    try {
+      Package existing = msc.findPackage(request(name));
+      if (existing != null && !replace)
+        throw new RuntimeException("Package " + name + " already exists");
+      msc.addPackage(makePackage(name, header, ""));
+    } catch (TException e) {
+      throw new RuntimeException(e.getCause());
+    }
+  }
+
+  @Override
+  public void createPackageBody(String name, String body, boolean replace) {
+    try {
+      Package existing = msc.findPackage(request(name));
+      if (existing != null && StringUtils.isNotEmpty(existing.getBody()) && 
!replace)
+        throw new RuntimeException("Package body " + name + " already exists");
+      if (existing == null) {
+        msc.addPackage(makePackage(name, "", body));

Review comment:
       Is a package body without header valid? I believe this should throw an 
error.
   
https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/packages.htm#LNPLS00901 
says "A package always has a specification"

##########
File path: hplsql/src/main/java/org/apache/hive/hplsql/Exec.java
##########
@@ -328,16 +334,16 @@ public String callStackPop() {
    */
   public Var findVariable(String name) {
     Var var;
-    String name1 = name;
+    String name1 = name.toUpperCase();
     String name1a = null;
     String name2 = null;
     Scope cur = exec.currentScope;
     Package pack;
     Package packCallContext = exec.getPackageCallContext();
     ArrayList<String> qualified = exec.meta.splitIdentifier(name);
     if (qualified != null) {
-      name1 = qualified.get(0);
-      name2 = qualified.get(1);
+      name1 = qualified.get(0).toUpperCase();

Review comment:
       can use `qualified = exec.meta.splitIdentifier(name1)` above so you wont 
need toUpperCase here.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to