[ 
https://issues.apache.org/jira/browse/HIVE-24346?focusedWorklogId=554833&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-554833
 ]

ASF GitHub Bot logged work on HIVE-24346:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Feb/21 17:25
            Start Date: 19/Feb/21 17:25
    Worklog Time Spent: 10m 
      Work Description: mustafaiman commented on a change in pull request #1733:
URL: https://github.com/apache/hive/pull/1733#discussion_r579350072



##########
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:
       But our design does not allow creating a body than creating a header for 
it. `createPackageHeader` queries HMS with the package name. If it finds the 
package, it always overrides the body. 




----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 554833)
    Time Spent: 6h 20m  (was: 6h 10m)

> Store HPL/SQL packages into HMS
> -------------------------------
>
>                 Key: HIVE-24346
>                 URL: https://issues.apache.org/jira/browse/HIVE-24346
>             Project: Hive
>          Issue Type: Sub-task
>          Components: hpl/sql, Metastore
>            Reporter: Attila Magyar
>            Assignee: Attila Magyar
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 6h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to