You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2025/06/09 07:50:43 UTC

(shardingsphere) branch master updated: Add E2E null date value assertions (#35649)

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

duanzhengqiang 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 34e62de263a Add E2E null date value assertions (#35649)
34e62de263a is described below

commit 34e62de263a90d8dc7daea03a93f0117462888aa
Author: ZhangCheng <ch...@apache.org>
AuthorDate: Mon Jun 9 15:50:37 2025 +0800

    Add E2E null date value assertions (#35649)
    
    * Add E2E null date value assertions
    
    * Add E2E null date value assertions
---
 .../test/e2e/it/sql/dml/BaseDMLE2EIT.java          | 31 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/it/sql/dml/BaseDMLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/it/sql/dml/BaseDMLE2EIT.java
index 847f81385a5..1f16bfdb64a 100644
--- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/it/sql/dml/BaseDMLE2EIT.java
+++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/it/sql/dml/BaseDMLE2EIT.java
@@ -73,6 +73,7 @@ import java.util.stream.Collectors;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
 public abstract class BaseDMLE2EIT implements SQLE2EIT {
     
@@ -266,14 +267,18 @@ public abstract class BaseDMLE2EIT implements SQLE2EIT {
             return;
         }
         if (Types.DATE == actual.getMetaData().getColumnType(columnIndex)) {
-            assertThat(DateTimeFormatterFactory.getDateFormatter().format(actual.getDate(columnIndex).toLocalDate()), is(expected));
+            assertDateTypeValue(actual, columnIndex, expected);
         } else if (Arrays.asList(Types.TIME, Types.TIME_WITH_TIMEZONE).contains(actual.getMetaData().getColumnType(columnIndex))) {
+            if (isNullValue(expected)) {
+                assertNull(actual.getTime(columnIndex));
+                return;
+            }
             assertThat(DateTimeFormatterFactory.getTimeFormatter().format(actual.getTime(columnIndex).toLocalTime()), is(expected));
         } else if (Arrays.asList(Types.TIMESTAMP, Types.TIMESTAMP_WITH_TIMEZONE).contains(actual.getMetaData().getColumnType(columnIndex))) {
             if ("Oracle".equals(databaseType.getType()) && "DATE".equalsIgnoreCase(actual.getMetaData().getColumnTypeName(columnIndex)) || "openGauss".equals(databaseType.getType())) {
-                assertThat(DateTimeFormatterFactory.getDateFormatter().format(actual.getDate(columnIndex).toLocalDate()), is(expected));
+                assertDateTypeValue(actual, columnIndex, expected);
             } else {
-                assertThat(DateTimeFormatterFactory.getShortMillisFormatter().format(actual.getTimestamp(columnIndex).toLocalDateTime()), is(expected));
+                assertTimestampTypeValue(actual, columnIndex, expected);
             }
         } else if (Types.CHAR == actual.getMetaData().getColumnType(columnIndex)
                 && ("PostgreSQL".equals(databaseType.getType()) || "openGauss".equals(databaseType.getType())
@@ -290,6 +295,26 @@ public abstract class BaseDMLE2EIT implements SQLE2EIT {
         }
     }
     
+    private void assertDateTypeValue(final ResultSet actual, final int columnIndex, final String expected) throws SQLException {
+        if (isNullValue(expected)) {
+            assertNull(actual.getDate(columnIndex));
+            return;
+        }
+        assertThat(DateTimeFormatterFactory.getDateFormatter().format(actual.getDate(columnIndex).toLocalDate()), is(expected));
+    }
+    
+    private void assertTimestampTypeValue(final ResultSet actual, final int columnIndex, final String expected) throws SQLException {
+        if (isNullValue(expected)) {
+            assertNull(actual.getTimestamp(columnIndex));
+            return;
+        }
+        assertThat(DateTimeFormatterFactory.getShortMillisFormatter().format(actual.getTimestamp(columnIndex).toLocalDateTime()), is(expected));
+    }
+    
+    private boolean isNullValue(final String value) {
+        return null == value || "NULL".equalsIgnoreCase(value);
+    }
+    
     private boolean isPostgreSQLOrOpenGaussMoney(final String columnTypeName, final DatabaseType databaseType) {
         return "money".equalsIgnoreCase(columnTypeName) && ("PostgreSQL".equals(databaseType.getType()) || "openGauss".equals(databaseType.getType()));
     }