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

zykkk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c54cc314d3 [improvement](jdbc catalog) Change JdbcExecutor's error 
reporting from UDF to JDBC (#35692)
0c54cc314d3 is described below

commit 0c54cc314d3c01f1a645dd7de2adcbafab79cb26
Author: zy-kkk <[email protected]>
AuthorDate: Thu Jul 11 09:58:51 2024 +0800

    [improvement](jdbc catalog) Change JdbcExecutor's error reporting from UDF 
to JDBC (#35692)
    
    In the initial version, JdbcExecutor directly used UdfRuntimeException,
    which could lead to misunderstanding of the exception. Therefore, I
    created a separate Exception for JdbcExecutor to help us view the
    exception more clearly.
---
 .../org/apache/doris/jdbc/BaseJdbcExecutor.java    | 46 +++++++++++-----------
 .../java/org/apache/doris/jdbc/JdbcExecutor.java   | 18 ++++-----
 ...dbcExecutor.java => JdbcExecutorException.java} | 30 ++++----------
 3 files changed, 39 insertions(+), 55 deletions(-)

diff --git 
a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/BaseJdbcExecutor.java
 
b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/BaseJdbcExecutor.java
index 1f6a227a37a..9e731f051a7 100644
--- 
a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/BaseJdbcExecutor.java
+++ 
b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/BaseJdbcExecutor.java
@@ -19,7 +19,6 @@ package org.apache.doris.jdbc;
 
 import org.apache.doris.cloud.security.SecurityChecker;
 import org.apache.doris.common.exception.InternalException;
-import org.apache.doris.common.exception.UdfRuntimeException;
 import org.apache.doris.common.jni.utils.UdfUtils;
 import org.apache.doris.common.jni.vec.ColumnType;
 import org.apache.doris.common.jni.vec.ColumnValueConverter;
@@ -155,19 +154,19 @@ public abstract class BaseJdbcExecutor implements 
JdbcExecutor {
         }
     }
 
-    public void testConnection() throws UdfRuntimeException {
+    public void testConnection() throws JdbcExecutorException {
         try {
             resultSet = ((PreparedStatement) stmt).executeQuery();
             if (!resultSet.next()) {
-                throw new UdfRuntimeException(
+                throw new JdbcExecutorException(
                         "Failed to test connection in BE: query executed but 
returned no results.");
             }
         } catch (SQLException e) {
-            throw new UdfRuntimeException("Failed to test connection in BE: ", 
e);
+            throw new JdbcExecutorException("Failed to test connection in BE: 
", e);
         }
     }
 
-    public int read() throws UdfRuntimeException {
+    public int read() throws JdbcExecutorException {
         try {
             resultSet = ((PreparedStatement) stmt).executeQuery();
             resultSetMetaData = resultSet.getMetaData();
@@ -175,11 +174,11 @@ public abstract class BaseJdbcExecutor implements 
JdbcExecutor {
             block = new ArrayList<>(columnCount);
             return columnCount;
         } catch (SQLException e) {
-            throw new UdfRuntimeException("JDBC executor sql has error: ", e);
+            throw new JdbcExecutorException("JDBC executor sql has error: ", 
e);
         }
     }
 
-    public long getBlockAddress(int batchSize, Map<String, String> 
outputParams) throws UdfRuntimeException {
+    public long getBlockAddress(int batchSize, Map<String, String> 
outputParams) throws JdbcExecutorException {
         try {
             if (outputTable != null) {
                 outputTable.close();
@@ -221,7 +220,7 @@ public abstract class BaseJdbcExecutor implements 
JdbcExecutor {
             }
         } catch (Exception e) {
             LOG.warn("jdbc get block address exception: ", e);
-            throw new UdfRuntimeException("jdbc get block address: ", e);
+            throw new JdbcExecutorException("jdbc get block address: ", e);
         } finally {
             block.clear();
         }
@@ -235,44 +234,44 @@ public abstract class BaseJdbcExecutor implements 
JdbcExecutor {
         }
     }
 
-    public int write(Map<String, String> params) throws UdfRuntimeException {
+    public int write(Map<String, String> params) throws JdbcExecutorException {
         VectorTable batchTable = VectorTable.createReadableTable(params);
         // Can't release or close batchTable, it's released by c++
         try {
             insert(batchTable);
         } catch (SQLException e) {
-            throw new UdfRuntimeException("JDBC executor sql has error: ", e);
+            throw new JdbcExecutorException("JDBC executor sql has error: ", 
e);
         }
         return batchTable.getNumRows();
     }
 
-    public void openTrans() throws UdfRuntimeException {
+    public void openTrans() throws JdbcExecutorException {
         try {
             if (conn != null) {
                 conn.setAutoCommit(false);
             }
         } catch (SQLException e) {
-            throw new UdfRuntimeException("JDBC executor open transaction has 
error: ", e);
+            throw new JdbcExecutorException("JDBC executor open transaction 
has error: ", e);
         }
     }
 
-    public void commitTrans() throws UdfRuntimeException {
+    public void commitTrans() throws JdbcExecutorException {
         try {
             if (conn != null) {
                 conn.commit();
             }
         } catch (SQLException e) {
-            throw new UdfRuntimeException("JDBC executor commit transaction 
has error: ", e);
+            throw new JdbcExecutorException("JDBC executor commit transaction 
has error: ", e);
         }
     }
 
-    public void rollbackTrans() throws UdfRuntimeException {
+    public void rollbackTrans() throws JdbcExecutorException {
         try {
             if (conn != null) {
                 conn.rollback();
             }
         } catch (SQLException e) {
-            throw new UdfRuntimeException("JDBC executor rollback transaction 
has error: ", e);
+            throw new JdbcExecutorException("JDBC executor rollback 
transaction has error: ", e);
         }
     }
 
@@ -280,18 +279,18 @@ public abstract class BaseJdbcExecutor implements 
JdbcExecutor {
         return curBlockRows;
     }
 
-    public boolean hasNext() throws UdfRuntimeException {
+    public boolean hasNext() throws JdbcExecutorException {
         try {
             if (resultSet == null) {
                 return false;
             }
             return resultSet.next();
         } catch (SQLException e) {
-            throw new UdfRuntimeException("resultSet to get next error: ", e);
+            throw new JdbcExecutorException("resultSet to get next error: ", 
e);
         }
     }
 
-    private void init(JdbcDataSourceConfig config, String sql) throws 
UdfRuntimeException {
+    private void init(JdbcDataSourceConfig config, String sql) throws 
JdbcExecutorException {
         ClassLoader oldClassLoader = 
Thread.currentThread().getContextClassLoader();
         String hikariDataSourceKey = config.createCacheKey();
         try {
@@ -341,13 +340,14 @@ public abstract class BaseJdbcExecutor implements 
JdbcExecutor {
             initializeStatement(conn, config, sql);
 
         } catch (MalformedURLException e) {
-            throw new UdfRuntimeException("MalformedURLException to load class 
about " + config.getJdbcDriverUrl(), e);
+            throw new JdbcExecutorException("MalformedURLException to load 
class about "
+                    + config.getJdbcDriverUrl(), e);
         } catch (SQLException e) {
-            throw new UdfRuntimeException("Initialize datasource failed: ", e);
+            throw new JdbcExecutorException("Initialize datasource failed: ", 
e);
         } catch (FileNotFoundException e) {
-            throw new UdfRuntimeException("FileNotFoundException failed: ", e);
+            throw new JdbcExecutorException("FileNotFoundException failed: ", 
e);
         } catch (Exception e) {
-            throw new UdfRuntimeException("Initialize datasource failed: ", e);
+            throw new JdbcExecutorException("Initialize datasource failed: ", 
e);
         } finally {
             Thread.currentThread().setContextClassLoader(oldClassLoader);
         }
diff --git 
a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java
 
b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java
index 85c40e21d16..65c8c7c7920 100644
--- 
a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java
+++ 
b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java
@@ -17,26 +17,24 @@
 
 package org.apache.doris.jdbc;
 
-import org.apache.doris.common.exception.UdfRuntimeException;
-
 import java.util.Map;
 
 public interface JdbcExecutor {
-    int read() throws UdfRuntimeException;
+    int read() throws JdbcExecutorException;
 
-    int write(Map<String, String> params) throws UdfRuntimeException;
+    int write(Map<String, String> params) throws JdbcExecutorException;
 
-    long getBlockAddress(int batchSize, Map<String, String> outputParams) 
throws UdfRuntimeException;
+    long getBlockAddress(int batchSize, Map<String, String> outputParams) 
throws JdbcExecutorException;
 
-    void close() throws UdfRuntimeException, Exception;
+    void close() throws JdbcExecutorException, Exception;
 
-    void openTrans() throws UdfRuntimeException;
+    void openTrans() throws JdbcExecutorException;
 
-    void commitTrans() throws UdfRuntimeException;
+    void commitTrans() throws JdbcExecutorException;
 
-    void rollbackTrans() throws UdfRuntimeException;
+    void rollbackTrans() throws JdbcExecutorException;
 
     int getCurBlockRows();
 
-    boolean hasNext() throws UdfRuntimeException;
+    boolean hasNext() throws JdbcExecutorException;
 }
diff --git 
a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java
 
b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutorException.java
similarity index 57%
copy from 
fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java
copy to 
fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutorException.java
index 85c40e21d16..7486ee54001 100644
--- 
a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java
+++ 
b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutorException.java
@@ -17,26 +17,12 @@
 
 package org.apache.doris.jdbc;
 
-import org.apache.doris.common.exception.UdfRuntimeException;
-
-import java.util.Map;
-
-public interface JdbcExecutor {
-    int read() throws UdfRuntimeException;
-
-    int write(Map<String, String> params) throws UdfRuntimeException;
-
-    long getBlockAddress(int batchSize, Map<String, String> outputParams) 
throws UdfRuntimeException;
-
-    void close() throws UdfRuntimeException, Exception;
-
-    void openTrans() throws UdfRuntimeException;
-
-    void commitTrans() throws UdfRuntimeException;
-
-    void rollbackTrans() throws UdfRuntimeException;
-
-    int getCurBlockRows();
-
-    boolean hasNext() throws UdfRuntimeException;
+public class JdbcExecutorException extends Exception {
+    public JdbcExecutorException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+    public JdbcExecutorException(String msg) {
+        super(msg);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to