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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7b54b6e3c4c Add MySQL exception mapping for ColumnNotFoundException 
(#39126)
7b54b6e3c4c is described below

commit 7b54b6e3c4c1fba957c9f109467e8f4f090e805c
Author: Eunbin Son <[email protected]>
AuthorDate: Wed Jul 22 23:04:53 2026 +0900

    Add MySQL exception mapping for ColumnNotFoundException (#39126)
    
    * Add MySQL exception mapping for ColumnNotFoundException
    
    * Use MySQL field list context for unknown column error message
    
    Native MySQL reports ER_BAD_FIELD_ERROR for the INSERT column-list path
    as "Unknown column 'x' in 'field list'" via thd->where, not the table
    name. Pass the field list context, update the mapper test accordingly,
    and move the release note entry to Bug Fixes.
    
    ---------
    
    Co-authored-by: Liang Zhang <[email protected]>
---
 RELEASE-NOTES.md                                                 | 1 +
 .../exception/mysql/mapper/MySQLDialectExceptionMapper.java      | 4 ++++
 .../database/exception/mysql/vendor/MySQLVendorError.java        | 2 ++
 .../exception/mysql/mapper/MySQLDialectExceptionMapperTest.java  | 9 ++++++++-
 .../database/exception/mysql/vendor/MySQLVendorErrorTest.java    | 7 +++++++
 .../infra/exception/external/sql/sqlstate/XOpenSQLState.java     | 2 ++
 6 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 62001a23bde..851a44dd228 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -33,6 +33,7 @@
 1. Proxy: Fix incorrect generated key handling for explicit auto-increment 
values - [#38810](https://github.com/apache/shardingsphere/pull/38810)
 1. Proxy: Fix microseconds decoded as nanoseconds in MySQL binary TIME value - 
[#39138](https://github.com/apache/shardingsphere/pull/39138)
 1. Proxy: Fix MySQL BLOB data corruption when string-like prepared statement 
parameters target BLOB columns - 
[#39072](https://github.com/apache/shardingsphere/pull/39072)
+1. Proxy: Add MySQL exception mapping for ColumnNotFoundException - 
[#39126](https://github.com/apache/shardingsphere/pull/39126)
 1. Proxy: Fix MySQL prepared statement parameter signedness decoding - 
[#39204](https://github.com/apache/shardingsphere/pull/39204)
 1. JDBC & Proxy: Remove default MySQL prepared statement query properties when 
creating data sources - 
[#38593](https://github.com/apache/shardingsphere/pull/38593)
 1. Mode: Fix rule metadata not removed from memory after dropping rules in 
Etcd cluster mode - 
[#38561](https://github.com/apache/shardingsphere/pull/38561)
diff --git 
a/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapper.java
 
b/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapper.java
index a768080dbe1..7da2c3f705e 100644
--- 
a/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapper.java
+++ 
b/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapper.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.database.exception.core.exception.SQLDialectExc
 import 
org.apache.shardingsphere.database.exception.core.exception.connection.AccessDeniedException;
 import 
org.apache.shardingsphere.database.exception.core.exception.connection.TooManyConnectionsException;
 import 
org.apache.shardingsphere.database.exception.core.exception.data.InsertColumnsAndValuesMismatchedException;
+import 
org.apache.shardingsphere.database.exception.core.exception.syntax.column.ColumnNotFoundException;
 import 
org.apache.shardingsphere.database.exception.core.exception.syntax.database.DatabaseCreateExistsException;
 import 
org.apache.shardingsphere.database.exception.core.exception.syntax.database.DatabaseDropNotExistsException;
 import 
org.apache.shardingsphere.database.exception.core.exception.syntax.database.NoDatabaseSelectedException;
@@ -122,6 +123,9 @@ public final class MySQLDialectExceptionMapper implements 
SQLDialectExceptionMap
             IncorrectGlobalLocalVariableException ex = 
(IncorrectGlobalLocalVariableException) sqlDialectException;
             return 
toSQLException(MySQLVendorError.ER_INCORRECT_GLOBAL_LOCAL_VAR, 
ex.getVariableName(), ex.getScope());
         }
+        if (sqlDialectException instanceof ColumnNotFoundException) {
+            return toSQLException(MySQLVendorError.ER_BAD_FIELD_ERROR, 
((ColumnNotFoundException) sqlDialectException).getColumnName(), "field list");
+        }
         return new UnknownSQLException(sqlDialectException).toSQLException();
     }
     
diff --git 
a/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorError.java
 
b/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorError.java
index 2126b8250ad..515ce88952f 100644
--- 
a/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorError.java
+++ 
b/database/exception/dialect/mysql/src/main/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorError.java
@@ -50,6 +50,8 @@ public enum MySQLVendorError implements VendorError {
     
     ER_TABLE_EXISTS_ERROR(XOpenSQLState.DUPLICATE, 1050, "Table '%s' already 
exists"),
     
+    ER_BAD_FIELD_ERROR(XOpenSQLState.COLUMN_NOT_FOUND, 1054, "Unknown column 
'%s' in '%s'"),
+    
     ER_DUP_ENTRY(XOpenSQLState.INTEGRITY_CONSTRAINT_VIOLATION, 1062, 
"Duplicate entry '%s' for key %d"),
     
     ER_PARSE_ERROR(XOpenSQLState.SYNTAX_ERROR, 1064, "%s near '%s' at line 
%d"),
diff --git 
a/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
 
b/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
index c82eafab354..0a290b89b2d 100644
--- 
a/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
+++ 
b/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.database.exception.core.exception.SQLDialectExc
 import 
org.apache.shardingsphere.database.exception.core.exception.connection.AccessDeniedException;
 import 
org.apache.shardingsphere.database.exception.core.exception.connection.TooManyConnectionsException;
 import 
org.apache.shardingsphere.database.exception.core.exception.data.InsertColumnsAndValuesMismatchedException;
+import 
org.apache.shardingsphere.database.exception.core.exception.syntax.column.ColumnNotFoundException;
 import 
org.apache.shardingsphere.database.exception.core.exception.syntax.database.DatabaseCreateExistsException;
 import 
org.apache.shardingsphere.database.exception.core.exception.syntax.database.DatabaseDropNotExistsException;
 import 
org.apache.shardingsphere.database.exception.core.exception.syntax.database.NoDatabaseSelectedException;
@@ -85,6 +86,11 @@ class MySQLDialectExceptionMapperTest {
         assertSQLExceptionWithMessage(mapper.convert(new 
AccessDeniedException("root", "127.0.0.1", true)), 
MySQLVendorError.ER_ACCESS_DENIED_ERROR, "root", "127.0.0.1", "YES");
     }
     
+    @Test
+    void assertConvertWithColumnNotFound() {
+        assertSQLExceptionWithMessage(mapper.convert(new 
ColumnNotFoundException("t_order", "order_id")), 
MySQLVendorError.ER_BAD_FIELD_ERROR, "order_id", "field list");
+    }
+    
     private void assertSQLExceptionWithMessage(final SQLException actual, 
final VendorError vendorError, final Object... messageArgs) {
         assertSQLException(actual, vendorError);
         assertThat(actual.getMessage(), 
is(String.format(vendorError.getReason(), messageArgs)));
@@ -123,6 +129,7 @@ class MySQLDialectExceptionMapperTest {
                 Arguments.of("unknown_system_variable", 
UnknownSystemVariableException.class, 
MySQLVendorError.ER_UNKNOWN_SYSTEM_VARIABLE),
                 Arguments.of("error_local_variable", 
ErrorLocalVariableException.class, MySQLVendorError.ER_LOCAL_VARIABLE),
                 Arguments.of("error_global_variable", 
ErrorGlobalVariableException.class, MySQLVendorError.ER_GLOBAL_VARIABLE),
-                Arguments.of("incorrect_global_local_variable", 
IncorrectGlobalLocalVariableException.class, 
MySQLVendorError.ER_INCORRECT_GLOBAL_LOCAL_VAR));
+                Arguments.of("incorrect_global_local_variable", 
IncorrectGlobalLocalVariableException.class, 
MySQLVendorError.ER_INCORRECT_GLOBAL_LOCAL_VAR),
+                Arguments.of("column_not_found", 
ColumnNotFoundException.class, MySQLVendorError.ER_BAD_FIELD_ERROR));
     }
 }
diff --git 
a/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorErrorTest.java
 
b/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorErrorTest.java
index fc0220c588f..89a4e49133d 100644
--- 
a/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorErrorTest.java
+++ 
b/database/exception/dialect/mysql/src/test/java/org/apache/shardingsphere/database/exception/mysql/vendor/MySQLVendorErrorTest.java
@@ -38,6 +38,13 @@ class MySQLVendorErrorTest {
         assertThat(MySQLVendorError.ER_BAD_DB_ERROR.getReason(), is("Unknown 
database '%s'"));
     }
     
+    @Test
+    void assertBadFieldError() {
+        assertThat(MySQLVendorError.ER_BAD_FIELD_ERROR.getVendorCode(), 
is(1054));
+        
assertThat(MySQLVendorError.ER_BAD_FIELD_ERROR.getSqlState().getValue(), 
is("42S22"));
+        assertThat(MySQLVendorError.ER_BAD_FIELD_ERROR.getReason(), 
is("Unknown column '%s' in '%s'"));
+    }
+    
     @Test
     void assertErrorOnModifyingGtidExecutedTable() {
         
assertThat(MySQLVendorError.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getVendorCode(),
 is(3176));
diff --git 
a/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/sqlstate/XOpenSQLState.java
 
b/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/sqlstate/XOpenSQLState.java
index e67762648c7..266a8d230d0 100644
--- 
a/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/sqlstate/XOpenSQLState.java
+++ 
b/infra/exception/src/main/java/org/apache/shardingsphere/infra/exception/external/sql/sqlstate/XOpenSQLState.java
@@ -63,6 +63,8 @@ public enum XOpenSQLState implements SQLState {
     
     NOT_FOUND("42S02"),
     
+    COLUMN_NOT_FOUND("42S22"),
+    
     CHECK_OPTION_VIOLATION("44000"),
     
     INVALID_COLUMN_NUMBER("HV008"),

Reply via email to