Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,7 @@ public List<ColumnSetDefault> getColumnSetDefaultList() {
* existing action-specific API to add or remove entries.
*/
public List<ColumnDefaultAction> getColumnDefaults() {
if (operation != AlterOperation.ALTER || columnSetDefaultList == null
|| constraintType != null && constraintSymbol != null
if (!usesColumnActionBody() || columnSetDefaultList == null
|| columnDropDefaultList != null && !columnDropDefaultList.isEmpty()) {
return Collections.emptyList();
}
Expand Down Expand Up @@ -1077,7 +1076,7 @@ protected void appendBody(StringBuilder b) {
b.append(optionalSpecifier);
} else if (hasExplicitConstraintHeader()) {
toStringConstraintAlter(b);
} else if (hasAlterColumnValueActions()) {
} else if (usesColumnActionBody()) {
toStringAlterColumn(b);
} else if (isSimpleKeywordOperation()) {
toStringSimpleKeyword(b);
Expand All @@ -1101,6 +1100,32 @@ private boolean hasAlterColumnValueActions() {
|| columnSetVisibilityList != null && !columnSetVisibilityList.isEmpty());
}

/**
* Whether the selected body renders ALTER COLUMN default or visibility actions. Subclasses
* overriding {@link #appendBody(StringBuilder)} must reflect their dispatch here as well.
*/
protected boolean usesColumnActionBody() {
return hasAlterColumnValueActions() && !hasExplicitConstraintHeader();
}

/**
* Whether this action currently renders its column definitions through the general body.
* Inactive column metadata is retained in the AST but must not select a different body when
* deparsing. Subclasses with their own body dispatch override this method accordingly.
*/
public boolean hasActiveColumnDefinitions() {
return hasColumnDefinitionPayload() && operation != AlterOperation.UNSPECIFIC
&& !hasExplicitConstraintHeader() && !usesColumnActionBody()
&& !isSimpleKeywordOperation() && !isRenameOperation() && !isDropSpecialOperation()
&& operation != AlterOperation.CONVERT && operation != AlterOperation.COLLATE
&& !isPartitionOperation();
}

/** Whether column definitions take precedence within the general body. */
protected boolean hasColumnDefinitionPayload() {
return commentText == null && columnName == null && colDataTypeList != null;
}

/**
* Appends the common tail (parameters, index comment) shared by all ALTER expressions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return getColumnIdentityActionsFromDefinitions();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return hasColumnDefinitionPayload() && !isDropSpecialOperation()
&& getOperation() != AlterOperation.DROP_PARTITION;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return getOperation() == AlterOperation.RENAME && hasColumnDefinitionPayload();
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ public List<ColumnIdentityAction> getColumnIdentityActions() {
return Collections.emptyList();
}

@Override
protected boolean usesColumnActionBody() {
return false;
}

@Override
public boolean hasActiveColumnDefinitions() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void deParseAction(AlterExpression action) {
expression -> expression.accept(expressionVisitor, null));
return;
}
if (action.getColDataTypeList() != null) {
if (action.hasActiveColumnDefinitions()) {
action.appendColumnDefinitionsTo(builder,
expression -> expression.accept(expressionVisitor, null));
} else {
Expand Down
13 changes: 12 additions & 1 deletion src/site/sphinx/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,18 @@ read-only, but its entries are the original mutable AST objects:
returns their SQL text. Existing ``ColumnSetDefault`` constructors still accept
opaque strings, for which ``getDefaultExpression()`` returns ``null``.
Replacing an expression also replaces any opaque value. Unrelated actions
return an empty list.
return an empty list. This lookup follows the action's current rendering path:
changing an operation or retaining unused metadata does not make a fixed-body
action expose ``SET DEFAULT`` entries it will not render.

``hasActiveColumnDefinitions()`` reports whether the action currently renders
its column definitions through the general ALTER body. ``getColDataTypeList()``
continues to expose stored metadata even when another body takes precedence.
``AlterDeParser`` uses the active path, so expression visitors rewrite the
selected default or column expressions without rendering inactive metadata.
Custom ``AlterExpression`` subclasses overriding ``appendBody`` should also
override ``usesColumnActionBody()`` and ``hasActiveColumnDefinitions()`` when
they change those dispatch rules.

Structured column attributes
============================
Expand Down
Loading
Loading