github-actions[bot] commented on code in PR #70220:
URL: https://github.com/apache/doris/pull/70220#discussion_r4676672067
##########
fe/fe-catalog/src/main/java/org/apache/doris/catalog/Column.java:
##########
@@ -695,7 +699,7 @@ public String getDefaultValueSql() {
if (this.type.isNumericType()) {
return defaultValue;
} else {
- return "'" + defaultValue.replace("'", "''") + "'";
+ return SqlUtils.quoteStringLiteral(defaultValue,
noBackslashEscapes);
Review Comment:
[P1] Preserve legacy persisted defaults when changing their encoding
With `sql_mode=''`, an OLAP table created on the old FE using `DEFAULT
'a\\b'` (two source backslashes) persists `defaultValue=615C5C62`, and
omitted-column INSERTs parse that SQL text once to write `615C62`. After replay
on this head, this call treats the same stored text as decoded bytes and
doubles the slashes, so identical INSERTs now write `615C5C62` without any
ALTER. `Column.defaultValue` has no representation marker or migration in
`gsonPostProcess`; the new tests create all defaults with the new parser.
Preserve legacy-column semantics while distinguishing newly decoded defaults,
and cover an old persisted Column/image through INSERT and DEFAULT under both
SQL modes. This differs from the existing fixed thread, which concerns defaults
created by the new parser.
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinitionTest.java:
##########
@@ -60,6 +64,105 @@ public void tearDown() {
Config.enable_non_aggregate_table_state_types = false;
}
+ @Test
+ public void testCivilTemporalDefaultsAreNormalizedForExternalDdl() {
+ DataType[] types = {DateV2Type.INSTANCE, DateTimeV2Type.of(6),
DateTimeV2Type.of(6), DateTimeV2Type.of(3)};
+ String[] inputs = {"20240102", "20240102030405", "2024-01-02
03:04:05.123456",
+ "2024-01-02 03:04:05.123999"};
+ String[] expected = {"2024-01-02", "2024-01-02 03:04:05.000000",
"2024-01-02 03:04:05.123456",
+ "2024-01-02 03:04:05.124"};
+ for (int i = 0; i < types.length; i++) {
+ ColumnDefinition column = new ColumnDefinition("added", types[i],
+ false, null, false, Optional.of(new
DefaultValue(inputs[i])), "");
+ column.validate(false, ImmutableSet.of(), ImmutableSet.of(),
false, KeysType.DUP_KEYS);
+ Assertions.assertEquals(expected[i],
column.translateToCatalogStyle().getDefaultValue());
+ Assertions.assertEquals(expected[i],
column.translateToCatalogStyleForSchemaChange().getDefaultValue());
+ }
+ }
+
+ @Test
+ public void testZonedExternalDefaultsRetainConnectorInput() {
+ ConnectContext previous = ConnectContext.get();
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ String[] zones = {"Asia/Shanghai", "UTC"};
+ String expected = "2024-01-02 03:04:05.123456";
+ for (int i = 0; i < zones.length; i++) {
+ context.getSessionVariable().setTimeZone(zones[i]);
+ ColumnDefinition column = new ColumnDefinition("added",
TimeStampTzType.of(6),
+ false, null, false, Optional.of(new
DefaultValue("2024-01-02 03:04:05.123456")), "");
+ column.validate(false, ImmutableSet.of(), ImmutableSet.of(),
false, KeysType.DUP_KEYS);
+ Assertions.assertEquals(expected,
column.translateToCatalogStyle().getDefaultValue());
+ Assertions.assertEquals(expected,
+
column.translateToCatalogStyleForSchemaChange().getDefaultValue());
+ }
+ } finally {
+ ConnectContext.remove();
+ if (previous != null) {
+ previous.setThreadLocalInfo();
+ }
+ }
+ }
+
+ @Test
+ public void
testZonedExternalDefaultsRetainCivilPrecisionUntilZoneBinding() {
+ String[] values = {"20240102030405", "20240102030405.123456",
"2024-01-02 03:04:05.123999",
+ "2024-01-02 03:04:05.123999+08:00", "2021-10-31
02:59:59.9994999CET",
Review Comment:
[P2] Align the guard-digit success test with the preceding validator
Both `.9994999` inputs have seven fractional digits, but the call at line
120 first runs `ColumnDef.validateDefaultValue` through
`ColumnDefinition.validateInternal`. Its typed TIMESTAMPTZ path invokes
`DateLiteralUtils` with `appendFraction(MICRO_OF_SECOND, 0, 6, true)`, so the
first CET input throws `AnalysisException` before `normalizeExternalDefault`
runs. This newly added test therefore cannot pass as written. Align external
ADD validation with the guard-digit-aware normalization before asserting
success, or explicitly test the existing rejection. Direct connector tests
bypass this engine validator.
--
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]