This is an automated email from the ASF dual-hosted git repository. zykkk pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new 2e61d1603a5 [branch-2.0][improvement](jdbc catalog) Change JdbcExecutor's error reporting from UDF to JDBC (#35699) 2e61d1603a5 is described below commit 2e61d1603a55f1cbf693276e21d3c43e37914016 Author: zy-kkk <zhongy...@gmail.com> AuthorDate: Thu Jul 11 15:12:10 2024 +0800 [branch-2.0][improvement](jdbc catalog) Change JdbcExecutor's error reporting from UDF to JDBC (#35699) pick #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. --- .../java/org/apache/doris/jdbc/JdbcExecutor.java | 54 +++++++++++----------- .../apache/doris/jdbc/JdbcExecutorException.java | 28 +++++++++++ 2 files changed, 55 insertions(+), 27 deletions(-) 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 a2ef1936e8f..17576c5b2cf 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 @@ -18,7 +18,6 @@ package org.apache.doris.jdbc; import org.apache.doris.common.exception.InternalException; -import org.apache.doris.common.exception.UdfRuntimeException; import org.apache.doris.common.jni.utils.JNINativeMethod; import org.apache.doris.common.jni.utils.UdfUtils; import org.apache.doris.common.jni.vec.ColumnType; @@ -192,19 +191,19 @@ public class 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(); @@ -223,19 +222,19 @@ public class JdbcExecutor { } return columnCount; } catch (SQLException e) { - throw new UdfRuntimeException("JDBC executor sql has error: ", e); + throw new JdbcExecutorException("JDBC executor sql has error: ", e); } } - public int write(String sql) throws UdfRuntimeException { + public int write(String sql) throws JdbcExecutorException { try { return stmt.executeUpdate(sql); } catch (SQLException e) { - throw new UdfRuntimeException("JDBC executor sql has error: ", e); + throw new JdbcExecutorException("JDBC executor sql has error: ", e); } } - public int write(Map<String, String> params) throws UdfRuntimeException { + public int write(Map<String, String> params) throws JdbcExecutorException { String[] requiredFields = params.get("required_fields").split(","); String[] types = params.get("columns_types").split("#"); long metaAddress = Long.parseLong(params.get("meta_address")); @@ -250,7 +249,7 @@ public class JdbcExecutor { 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(); } @@ -375,37 +374,37 @@ public class JdbcExecutor { return resultColumnTypeNames; } - 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); } } - public List<Object[]> getBlock(int batchSize, Object colsArray) throws UdfRuntimeException { + public List<Object[]> getBlock(int batchSize, Object colsArray) throws JdbcExecutorException { try { ArrayList<Integer> colsTypes = (ArrayList<Integer>) colsArray; Integer[] colArray = new Integer[colsTypes.size()]; @@ -425,12 +424,12 @@ public class JdbcExecutor { curBlockRows++; } while (curBlockRows < batchSize && resultSet.next()); } catch (SQLException e) { - throw new UdfRuntimeException("get next block failed: ", e); + throw new JdbcExecutorException("get next block failed: ", e); } return block; } - public List<Object[]> getBlock(int batchSize) throws UdfRuntimeException { + public List<Object[]> getBlock(int batchSize) throws JdbcExecutorException { try { int columnCount = resultSetMetaData.getColumnCount(); curBlockRows = 0; @@ -451,7 +450,7 @@ public class JdbcExecutor { } while (curBlockRows < batchSize && resultSet.next()); } } catch (SQLException e) { - throw new UdfRuntimeException("get next block failed: ", e); + throw new JdbcExecutorException("get next block failed: ", e); } return block; } @@ -460,18 +459,18 @@ public class 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 { @@ -540,13 +539,14 @@ public class JdbcExecutor { } } } 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/JdbcExecutorException.java b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutorException.java new file mode 100644 index 00000000000..7486ee54001 --- /dev/null +++ b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutorException.java @@ -0,0 +1,28 @@ +// 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.doris.jdbc; + +public class JdbcExecutorException extends Exception { + public JdbcExecutorException(String msg, Throwable cause) { + super(msg, cause); + } + + public JdbcExecutorException(String msg) { + super(msg); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org