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



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/model/MPackage.java
##########
@@ -0,0 +1,100 @@
+/*
+ *  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.hadoop.hive.metastore.model;
+
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.Package;
+import org.apache.hadoop.hive.metastore.api.AddPackageRequest;
+
+public class MPackage {
+  private String name;
+  private MDatabase database;
+  private String owner;
+  private String header;
+  private String body;
+  private int createTime = (int)(System.currentTimeMillis() / 1000);
+  public static final int MAX_SOURCE_SIZE = 1073741823;
+
+  public MPackage() {}
+
+  public static MPackage populate(MPackage result, MDatabase mDatabase, 
AddPackageRequest pkg) throws MetaException {
+    result.setName(pkg.getPackageName());
+    result.setOwner(pkg.getOwnerName());
+    result.setHeader(pkg.getHeader());
+    result.setBody(pkg.getBody());
+    result.setDatabase(mDatabase);
+    return result;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public MDatabase getDatabase() {
+    return database;
+  }
+
+  public void setDatabase(MDatabase database) {
+    this.database = database;
+  }
+
+  public String getOwner() {
+    return owner;
+  }
+
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+
+  public String getHeader() {
+    return header;
+  }
+
+  public void setHeader(String header) throws MetaException {
+    if (header.length() > MAX_SOURCE_SIZE) {
+      throw new MetaException("Source code is too long: " + header.length() + 
" max size: " + MAX_SOURCE_SIZE);

Review comment:
       This should be "Header is too long"

##########
File path: 
hplsql/src/main/java/org/apache/hive/hplsql/packages/InMemoryPackageRegistry.java
##########
@@ -0,0 +1,67 @@
+/*
+ *  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.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class InMemoryPackageRegistry implements PackageRegistry {
+  private Map<String, Source> registry = new HashMap<>();
+
+  @Override
+  public Optional<String> getPackage(String name) {
+    Source src = registry.get(name.toUpperCase());
+    return src == null
+            ? Optional.empty()
+            : Optional.of(src.header + ";\n" + src.body);
+  }
+
+  @Override
+  public void createPackageHeader(String name, String header, boolean replace) 
{
+    if (registry.containsKey(name) && !replace)
+      throw new RuntimeException("Package " + name + " already exits");
+    registry.put(name, new Source(header, ""));
+  }
+
+  @Override
+  public void createPackageBody(String name, String body, boolean replace) {
+    Source existing = registry.get(name);
+    if (existing != null && StringUtils.isNotEmpty(existing.body) && !replace)

Review comment:
       Since we do not allow package body without header in HmsPackageRegistry, 
we should not allow it in InMemoryPackageRegistry either.

##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/model/MPackage.java
##########
@@ -0,0 +1,79 @@
+/*
+ *  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.hadoop.hive.metastore.model;
+
+import org.apache.hadoop.hive.metastore.api.MetaException;
+
+public class MPackage {
+  private String name;
+  private MDatabase database;
+  private String owner;
+  private String header;
+  private String body;
+  private int createTime = (int)(System.currentTimeMillis() / 1000);
+  public static final int MAX_SOURCE_SIZE = 1073741823;
+
+  public MPackage() {}
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public MDatabase getDatabase() {
+    return database;
+  }
+
+  public void setDatabase(MDatabase database) {
+    this.database = database;
+  }
+
+  public String getOwner() {
+    return owner;
+  }
+
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+
+  public String getHeader() {
+    return header;
+  }
+
+  public void setHeader(String header) throws MetaException {
+    if (header.length() > MAX_SOURCE_SIZE) {

Review comment:
       If MAX_SOURCE_SIZE applies to both individually, please name the 
constant to indicate that. Alternatively introduce another constant 
MAX_HEADER_SIZE = MAX_SOURCE_SIZE

##########
File path: 
hplsql/src/main/java/org/apache/hive/hplsql/packages/HmsPackageRegistry.java
##########
@@ -0,0 +1,101 @@
+/*
+ *  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.isEmpty(existing.getHeader()))
+        throw new RuntimeException("Package header does not exists " + name);
+      if (StringUtils.isNotEmpty(existing.getBody()) && !replace)
+        throw new RuntimeException("Package body " + name + " already exists");
+      msc.addPackage(makePackage(name, existing.getHeader(), body));
+    } catch (TException e) {
+      throw new RuntimeException(e.getCause());

Review comment:
       It would be better if you wrap the whole exception `e` rather than 
`e.getCause()`. There is no reason to swallow potential debug information. The 
same applies to other methods in this class




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