leesf commented on a change in pull request #868: HUDI-180 : Adding support for 
hive registration using metastore along with JDBC
URL: https://github.com/apache/incubator-hudi/pull/868#discussion_r319738890
 
 

 ##########
 File path: hudi-hive/src/main/java/org/apache/hudi/hive/HoodieHiveClient.java
 ##########
 @@ -458,19 +507,69 @@ public boolean doesTableExist() {
    * @param s SQL to execute
    */
   public void updateHiveSQL(String s) {
-    Statement stmt = null;
+    if (syncConfig.useJdbc) {
+      Statement stmt = null;
+      try {
+        stmt = connection.createStatement();
+        LOG.info("Executing SQL " + s);
+        stmt.execute(s);
+      } catch (SQLException e) {
+        throw new HoodieHiveSyncException("Failed in executing SQL " + s, e);
+      } finally {
+        closeQuietly(null, stmt);
+      }
+    } else {
+      updateHiveSQLUsingHiveDriver(s);
+    }
+  }
+
+  /**
+   * Execute a update in hive using Hive Driver
+   *
+   * @param sql SQL statement to execute
+   */
+  public CommandProcessorResponse updateHiveSQLUsingHiveDriver(String sql) 
throws HoodieHiveSyncException {
+    List<CommandProcessorResponse> responses = 
updateHiveSQLs(Arrays.asList(sql));
+    return responses.get(responses.size() - 1);
+  }
+
+  private List<CommandProcessorResponse> updateHiveSQLs(List<String> sqls) 
throws HoodieHiveSyncException {
+    SessionState ss = null;
+    org.apache.hadoop.hive.ql.Driver hiveDriver = null;
+    List<CommandProcessorResponse> responses = new ArrayList<>();
     try {
-      stmt = connection.createStatement();
-      LOG.info("Executing SQL " + s);
-      stmt.execute(s);
-    } catch (SQLException e) {
-      throw new HoodieHiveSyncException("Failed in executing SQL " + s, e);
+      final long startTime = System.currentTimeMillis();
+      ss = SessionState.start(configuration);
+      hiveDriver = new org.apache.hadoop.hive.ql.Driver(configuration);
+      final long endTime = System.currentTimeMillis();
+      LOG.info("Time taken to start SessionState and create Driver: {} ms", 
(endTime - startTime));
+      for (String sql : sqls) {
+        final long start = System.currentTimeMillis();
+        responses.add(hiveDriver.run(sql));
+        final long end = System.currentTimeMillis();
+        LOG.info("Time taken to execute [{}]: {} ms", sql, (end - start));
+      }
+    } catch (Exception e) {
+      throw new HoodieHiveSyncException("Failed in executing SQL", e);
     } finally {
-      closeQuietly(null, stmt);
+      if (ss != null) {
+        try {
+          ss.close();
+        } catch (IOException ie) {
+          LOG.error("Error while closing SessionState: {}", ie);
 
 Review comment:
   May be LOG.error("Error while closing SessionState.", ie); ?

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


With regards,
Apache Git Services

Reply via email to