github-actions[bot] commented on code in PR #70220:
URL: https://github.com/apache/doris/pull/70220#discussion_r4626717268


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -4279,7 +4279,8 @@ public ColumnDefinition visitColumnDef(ColumnDefContext 
ctx) {
                     defaultValue = Optional.of(new DefaultValue("-" + 
ctx.DECIMAL_VALUE().getText()));
                 }
             } else if (ctx.stringValue != null) {
-                defaultValue = Optional.of(new 
DefaultValue(toStringValue(ctx.stringValue.getText())));
+                defaultValue = Optional.of(new DefaultValue(
+                        
SqlLiteralUtils.parseStringLiteral(ctx.stringValue.getText())));

Review Comment:
   [P1] Escape decoded defaults before internal inserts reparse them
   
   This now decodes string defaults for OLAP DDL as well, but 
`Column.getDefaultValueSql()` still escapes only apostrophes before `BindSink` 
/ `InsertUtils.generateDefaultExpression` reparses the value. Under 
`sql_mode=''`, `DEFAULT 'a\\b'` (two source backslashes) is stored as the 
intended bytes `615C62`, then the generated SQL contains a single `\b` and 
`visitStringLiteral` decodes it again to `6108` (a backspace). Omitted-column 
INSERTs and explicit `DEFAULT` therefore silently write the wrong value; a 
trailing-backslash default can instead make the generated expression fail to 
parse. Please make the downstream SQL serialization preserve decoded 
backslashes, with OLAP insert/default coverage under both SQL modes, before 
applying this decoding globally.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java:
##########
@@ -564,12 +586,34 @@ private void validateInternal(boolean isOlap, Set<String> 
keysSet, Set<String> c
             try {
                 ColumnDef.validateDefaultValue(type.toCatalogDataType(),
                         defaultValue.get().getValue(), 
defaultValue.get().getDefaultValueExprDef());
-                if (!isOlap && type.isTimeStampNsType()
+                if (!isOlap && type.isDateLikeType()
                         && defaultValue.get().getDefaultValueExprDef() == 
null) {
-                    // Connectors receive civil SQL defaults, not numeric 
epoch carriers. Normalize
-                    // with the same parser as validation so compact dates 
cannot become epoch nanos.
+                    // Preserve SQL literal time-zone and rounding semantics 
for civil temporal defaults.
+                    String value = defaultValue.get().getValue();
+                    if (type.isDateTimeV2Type() || type.isTimeStampTzType()) {
+                        value = normalizeCompactDateTimeFraction(value);
+                    }
+                    Literal normalized;
+                    if (type.isTimeStampTzType()) {
+                        TimeStampTzType zonedType = (TimeStampTzType) type;
+                        // Retain civil precision until the connector binds 
the session zone.
+                        normalized = DateTimeChecker.hasTimeZone(value)
+                                ? new TimestampTzLiteral(zonedType, value)

Review Comment:
   [P2] Resolve explicit zones before applying default precision
   
   The explicit-zone branch constructs `TimestampTzLiteral` at the declared 
scale, and `DateTimeLiteral.init()` rounds to that scale before resolving its 
zone. The unqualified branch retains six digits, then `parseAddColumnDefault()` 
rounds after binding the session zone. Consequently, under `SET 
time_zone='CET'`, a v3 ADD with `TIMESTAMPTZ(0) DEFAULT '2021-10-31 
02:59:59.6'` persists `01:00 UTC`, while the equivalent explicit `'2021-10-31 
02:59:59.6CET'` rounds locally to `03:00 CET` and persists `02:00 UTC`. Scale 3 
has the same issue for `.9996`. This contradicts the new DST-equality 
regression output and makes equivalent defaults differ by an hour. Preserve 
full precision through explicit-zone resolution and apply the target precision 
once on the resolved instant, consistently with the session-zone path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to