You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ja...@apache.org on 2015/11/17 18:00:42 UTC

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

Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 982101392 -> baaf1bd37


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/baaf1bd3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/baaf1bd3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/baaf1bd3

Branch: refs/heads/branch-2.1
Commit: baaf1bd37bc787a1c2b3fe044aa5b14ba9b3677c
Parents: 9821013
Author: Jaimin Jetly <ja...@hortonworks.com>
Authored: Tue Nov 17 08:59:10 2015 -0800
Committer: Jaimin Jetly <ja...@hortonworks.com>
Committed: Tue Nov 17 08:59:42 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/baaf1bd3/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/baaf1bd3/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/baaf1bd3/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