@@ -48,6 +48,13 @@ public double asFloat() {
4848 throw new UnsupportedOperationException (this .toString ());
4949 }
5050
51+ protected Timestamp truncateTimestamp (long val ) {
52+ // Databend supports `date` and `timestamp` type where the year cannot exceed `9999`,
53+ // the value is truncated to ensure generate legitimate `date` and `timestamp` value.
54+ long t = val % 253380000000000L ;
55+ return new Timestamp (t );
56+ }
57+
5158 public abstract DatabendConstant isEquals (DatabendConstant rightVal );
5259
5360 public abstract DatabendConstant isLessThan (DatabendConstant rightVal );
@@ -322,10 +329,7 @@ public static class DatabendDateConstant extends DatabendConstant {
322329 public String textRepr ;
323330
324331 public DatabendDateConstant (long val ) {
325- // Databend supports `date` type where the year cannot exceed `9999`,
326- // the value is truncated to ensure generate legitimate `date` value.
327- long t = val % 253380000000000L ;
328- Timestamp timestamp = new Timestamp (t );
332+ Timestamp timestamp = truncateTimestamp (val );
329333 SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
330334 textRepr = dateFormat .format (timestamp );
331335 }
@@ -360,10 +364,7 @@ public static class DatabendTimestampConstant extends DatabendConstant {
360364 public String textRepr ;
361365
362366 public DatabendTimestampConstant (long val ) {
363- // Databend supports `timestamp` type where the year cannot exceed `9999`,
364- // the value is truncated to ensure generate legitimate `timestamp` value.
365- long t = val % 253380000000000L ;
366- Timestamp timestamp = new Timestamp (t );
367+ Timestamp timestamp = truncateTimestamp (val );
367368 SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
368369 textRepr = dateFormat .format (timestamp );
369370 }
0 commit comments