mrhhsg commented on code in PR #63528:
URL: https://github.com/apache/doris/pull/63528#discussion_r4307511698
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java:
##########
@@ -628,20 +622,28 @@ private void validateInternal(boolean isOlap, Set<String>
keysSet, Set<String> c
/**
* Validate non-null defaults for complex types before connector-specific
validation.
+ * ARRAY, MAP and STRUCT defaults are rewritten into the canonical literal
text that BE parses.
*/
public void validateComplexTypeDefaultValue() throws AnalysisException {
- if (!defaultValue.isPresent() || defaultValue.get() ==
DefaultValue.NULL_DEFAULT_VALUE) {
+ if (!hasNonNullDefaultValue()) {
return;
}
- if (type.isMapType()) {
- throw new AnalysisException("Map type column default value just
support null");
- } else if (type.isStructType()) {
- throw new AnalysisException("Struct type column default value just
support null");
+ if (type.isArrayType() || type.isMapType() || type.isStructType()) {
+ defaultValue = Optional.of(new DefaultValue(
+ ComplexTypeDefaultValue.canonicalize(type,
defaultValue.get().getValue())));
Review Comment:
Addressed in 10c3d567f16 and 8c75c0303a2.
`ColumnDefinition.toSql()` is the ALTER binlog serializer. For an
ARRAY/MAP/STRUCT default it now reuses `Column.quoteDefaultValue()`, so `ALTER
TABLE t ADD COLUMN m MAP<STRING,INT> DEFAULT '{"a":1}'` is serialized as
`DEFAULT '{"a":1}'`; the DDL parser keeps the text between the quotes verbatim
and replays the canonical value into the canonicalizer. Scalars keep
`SqlUtils.escapeQuota`: the canonical complex text never contains a single
quote, while a scalar default may contain both quote characters and would
become unparsable if wrapped in single quotes.
`AlterTableCommandTest.testAddColumnComplexDefaultSqlRoundTrip` serializes
and reparses the ADD COLUMN statement and asserts the same canonical default;
`testAddColumnScalarDefaultKeepsEscapedQuotes` covers the scalar case. Both are
part of the 20 `AlterTableCommandTest` cases (0 failures) that pass here,
together with `ColumnDefinitionTest`.
--
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]