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



##########
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:
       HPLSQL used to allow this in previous versions. Oracle also allows you 
to create the body without the spec but the package is not usable until you 
create the spec for it. Throwing an error at this point wouldn't be the same 
either. We might want to put a check when getting the package, but it would 
break the previous behaviour. I suspect the limitation in oracle is coming from 
the fact that it compiles these two together but since this language is fully 
interpreted we don't face this problem. An other option would be to print out a 
warning message. Or just leave it as it is since this is how it used to work. 
Which one do you think is better?




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