ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jai...@apache.org
Subject ambari git commit: AMBARI-13806. Multi statement queries with errors after the first statement cause orphaned AMs. (DIPAYAN BHOWMICK via Jaimin)
Date Tue, 17 Nov 2015 17:01:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk bb371da60 -> 69db84a68


AMBARI-13806. Multi statement queries with errors after the first statement cause orphaned
AMs. (DIPAYAN BHOWMICK via Jaimin)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/69db84a6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/69db84a6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/69db84a6

Branch: refs/heads/trunk
Commit: 69db84a6848f7d1c75b3cc0d90f61cd1c352aa19
Parents: bb371da
Author: Jaimin Jetly <jaimin@hortonworks.com>
Authored: Tue Nov 17 08:59:10 2015 -0800
Committer: Jaimin Jetly <jaimin@hortonworks.com>
Committed: Tue Nov 17 09:01:14 2015 -0800

----------------------------------------------------------------------
 .../ambari/view/hive/client/Connection.java     |  2 +-
 .../apache/ambari/view/hive/client/Utils.java   | 14 ++++++++
 .../ambari/view/hive/client/UtilsTest.java      | 35 ++++++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/69db84a6/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
index d8210ba..451f2aa 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
@@ -577,7 +577,7 @@ public class Connection {
   public TOperationHandle execute(final TSessionHandle session, final String cmd, final boolean
async) throws HiveClientException {
     TOperationHandle handle = null;
 
-    String[] commands = cmd.split(";");
+    String[] commands = Utils.removeEmptyStrings(cmd.split(";"));
     for(int i=0; i<commands.length; i++) {
       final String oneCmd = commands[i];
       final boolean lastCommand = i == commands.length-1;

http://git-wip-us.apache.org/repos/asf/ambari/blob/69db84a6/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
index f9efc1c..5b42b1f 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
@@ -23,6 +23,7 @@ import org.apache.hive.service.cli.thrift.TStatusCode;
 import org.apache.http.client.CookieStore;
 import org.apache.http.cookie.Cookie;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class Utils {
@@ -60,6 +61,19 @@ public class Utils {
     return true;
   }
 
+  /**
+   * Removes the empty strings and returns back only the strings with content
+   */
+  static String[] removeEmptyStrings(String[] strs) {
+    List<String> nonEmptyStrings = new ArrayList<>();
+    for(String str : strs) {
+      if (!(str == null || str.trim().isEmpty())) {
+        nonEmptyStrings.add(str);
+      }
+    }
+    return nonEmptyStrings.toArray(new String[] {});
+  }
+
   public static class HiveAuthenticationParams {
     public static final String AUTH_TYPE = "auth";
     // We're deprecating this variable's name.

http://git-wip-us.apache.org/repos/asf/ambari/blob/69db84a6/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java
b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java
new file mode 100644
index 0000000..de66bef
--- /dev/null
+++ b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/client/UtilsTest.java
@@ -0,0 +1,35 @@
+/**
+ * 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.ambari.view.hive.client;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class UtilsTest {
+
+  @Test
+  public void testRemoveEmptyStrings() throws Exception {
+    String[] arrayWithSomeEmptyStrings = new String[] { "", null, "string1", null, "", "string2",
"" };
+    String[] expectedStrings = Utils.removeEmptyStrings(arrayWithSomeEmptyStrings);
+
+    assertEquals(2, expectedStrings.length);
+    assertEquals("string1", expectedStrings[0]);
+    assertEquals("string2", expectedStrings[1]);
+  }
+}
\ No newline at end of file


Mime
View raw message