This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new ebc8174  [ZEPPELIN-5141]. Solve the incompatibility issue of hive 
below 2.3
ebc8174 is described below

commit ebc817473295aabe80101fc4824aaa0d0d3e4dbf
Author: zhengsl <[email protected]>
AuthorDate: Thu Nov 26 18:59:09 2020 +0800

    [ZEPPELIN-5141]. Solve the incompatibility issue of hive below 2.3
    
    ### What is this PR for?
    The current hive interpreter (jdbc) cannot work with hive below 2.3.  The 
code "hiveStmt.setInPlaceUpdateStream(InPlaceUpdateStream stream)" in HiveUtils 
uses InPlaceUpdateStream class which is only available in version 2.3 or above, 
which leads to runtime NoClassDefFoundError.  Move the code into ProgressBar to 
delay NoClassDefFoundError of InPlaceUpdateStream until ProgressBar instanced. 
When hive < 2.3, ProgressBar will not be instanced, so it works well.
    
    ### What type of PR is it?
    [Bug Fix | Improvement ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5141
    
    ### How should this be tested?
    * Test the hive interpreter(jdbc) with version both above 2.3 and below 2.3 
to check whether it can work well.
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: zhengsl <[email protected]>
    
    Closes #3983 from zhengslei/master and squashes the following commits:
    
    5b25a4854 [zhengsl] [ZEPPELIN-5141]. Solve the incompatibility issue of 
hive below 2.3
    
    (cherry picked from commit fd780d46ce853666aea4bead04b125fc491783c9)
    Signed-off-by: Jeff Zhang <[email protected]>
---
 .../java/org/apache/zeppelin/jdbc/hive/HiveUtils.java   | 17 ++++++++++++++++-
 .../java/org/apache/zeppelin/jdbc/hive/ProgressBar.java |  5 +++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java 
b/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java
index ad253f0..c7d47b9 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java
@@ -24,6 +24,7 @@ import org.apache.zeppelin.jdbc.JDBCInterpreter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.HashMap;
 import java.util.List;
@@ -118,6 +119,17 @@ public class HiveUtils {
           Thread.sleep(DEFAULT_QUERY_PROGRESS_INTERVAL);
         } catch (Exception e) {
           LOGGER.warn("Fail to write output", e);
+        } finally {
+          try {
+            // Sometimes, maybe hiveStmt was closed unnormally, 
hiveStmt.hasMoreLogs() will be true,
+            // this loop cannot jump out, and exceptions thrown.
+            // Add the below codes in case.
+            if(hiveStmt.isClosed()){
+              break;
+            }
+          } catch (SQLException e) {
+            LOGGER.warn("hiveStmt closed unnormally", e);
+          }
         }
       }
       LOGGER.info("HiveMonitor-Thread is finished");
@@ -128,7 +140,10 @@ public class HiveUtils {
     LOGGER.info("Start HiveMonitor-Thread for sql: " + hiveStmt);
 
     if (progressBar != null) {
-      
hiveStmt.setInPlaceUpdateStream(progressBar.getInPlaceUpdateStream(context.out));
+      // old: 
hiveStmt.setInPlaceUpdateStream(progressBar.getInPlaceUpdateStream(context.out));
+      // Move codes into ProgressBar to delay NoClassDefFoundError of 
InPlaceUpdateStream until ProgressBar instanced.
+      // When hive < 2.3, ProgressBar will not be instanced, so it works well.
+      progressBar.setInPlaceUpdateStream(hiveStmt, context.out);
     }
   }
 
diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/ProgressBar.java 
b/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/ProgressBar.java
index 0cd28be..577a1f1 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/ProgressBar.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/ProgressBar.java
@@ -16,6 +16,7 @@
 
 package org.apache.zeppelin.jdbc.hive;
 
+import org.apache.hive.jdbc.HiveStatement;
 import org.apache.hive.jdbc.logs.InPlaceUpdateStream;
 
 import java.io.OutputStream;
@@ -41,4 +42,8 @@ public class ProgressBar {
             eventNotifier
     );
   }
+
+  public void setInPlaceUpdateStream(HiveStatement hiveStmt, OutputStream out){
+    hiveStmt.setInPlaceUpdateStream(this.getInPlaceUpdateStream(out));
+  }
 }

Reply via email to