Skip to content

Add support for SET DEFAULT and DROP DEFAULT statements#26162

Merged
ebyhr merged 2 commits into
trinodb:masterfrom
ebyhr:ebi/core-set-drop-default-clause
Nov 21, 2025
Merged

Add support for SET DEFAULT and DROP DEFAULT statements#26162
ebyhr merged 2 commits into
trinodb:masterfrom
ebyhr:ebi/core-set-drop-default-clause

Conversation

@ebyhr
Copy link
Copy Markdown
Member

@ebyhr ebyhr commented Jul 10, 2025

Description

Add support for the following syntax:

    | ALTER TABLE (IF EXISTS)? tableName=qualifiedName
        ALTER COLUMN columnName=identifier SET DEFAULT literal         #setDefaultValue
    | ALTER TABLE (IF EXISTS)? tableName=qualifiedName
        ALTER COLUMN columnName=identifier DROP DEFAULT                #dropDefaultValue

DROP DEFAULT on columns that don't have defaults throws an exception because SQL spec states "The descriptor of C shall include a default value".

Release notes

## General, Memory
* Add support for `SET DEFAULT` and `DROP DEFAULT` statements. ({issue}`issuenumber`)

@cla-bot cla-bot Bot added the cla-signed label Jul 10, 2025
@github-actions github-actions Bot added docs memory Memory connector labels Jul 10, 2025
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch 3 times, most recently from 5dce2c0 to 5f15ffb Compare July 10, 2025 05:18
@ebyhr ebyhr requested review from Praveen2112, kasiafi and martint July 10, 2025 06:53
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch 2 times, most recently from 71301fb to cb68fd6 Compare July 28, 2025 01:18
Comment on lines +93 to +99
if (columnMetadata.isHidden()) {
throw semanticException(NOT_SUPPORTED, statement, "Cannot modify hidden column");
}
if (columnMetadata.getDefaultValue().isEmpty()) {
throw semanticException(NOT_SUPPORTED, statement, "Column '%s' does not have a default value", column);
}
metadata.dropDefaultValue(session, tableHandle, columnHandle);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like we do for SetDefaultValueTask - can we also check if the Connector supports them out ?

Comment on lines +81 to +93
if (redirectionAwareTableHandle.tableHandle().isEmpty()) {
String exceptionMessage = "Table '%s' does not exist".formatted(tableName);
if (metadata.getMaterializedView(session, tableName).isPresent()) {
exceptionMessage += ", but a materialized view with that name exists.";
}
else if (metadata.isView(session, tableName)) {
exceptionMessage += ", but a view with that name exists.";
}
if (!statement.isTableExists()) {
throw semanticException(TABLE_NOT_FOUND, statement, "%s", exceptionMessage);
}
return immediateVoidFuture();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe as a follow-up - Do we need to abstract this out for all the DDL operations to be perfomed on a table ?

Comment on lines +90 to +93
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName
ALTER COLUMN columnName=identifier SET DEFAULT literal #setDefaultValue
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName
ALTER COLUMN columnName=identifier DROP DEFAULT #dropDefaultValue
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any plans on setting the same for field as well ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no plan about it as far as I know.

@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from cb68fd6 to be71180 Compare August 5, 2025 04:39
@github-actions
Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack.

@github-actions github-actions Bot added the stale label Aug 26, 2025
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from be71180 to 223dff2 Compare August 26, 2025 21:43
@github-actions github-actions Bot removed the stale label Aug 27, 2025
@github-actions
Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack.

@github-actions github-actions Bot added the stale label Sep 17, 2025
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch 3 times, most recently from 17bfa50 to d68f292 Compare September 18, 2025 13:48
@github-actions github-actions Bot removed the stale label Sep 18, 2025
Copy link
Copy Markdown
Member

@kasiafi kasiafi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed.

By the way, I noticed that when we alter column type, we don't do any generic checks related to the default value. What does the spec say about it?

Comment thread core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4 Outdated
Comment thread core/trino-main/src/main/java/io/trino/execution/SetDefaultValueTask.java Outdated
Comment thread core/trino-main/src/test/java/io/trino/execution/TestDropDefaultValueTask.java Outdated
Comment thread core/trino-main/src/main/java/io/trino/execution/DropDefaultValueTask.java Outdated
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from d68f292 to 4fc218e Compare October 5, 2025 00:31
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from 4fc218e to e0de208 Compare October 5, 2025 00:43
@ebyhr
Copy link
Copy Markdown
Member Author

ebyhr commented Oct 5, 2025

The spec doesn't explicitly mention checking default values in 11.19 <alter column data type clause>, if I understand it correctly.

@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from e0de208 to a9591b6 Compare October 5, 2025 04:27
Copy link
Copy Markdown
Member

@kasiafi kasiafi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec doesn't explicitly mention checking default values in 11.19 , if I understand it correctly.

Right. Instead, the spec defines constraints on the new type based on the existing type. If those constraints are respected, then probably it guarantees that the default value remains valid.
However, we don't enforce these constraints in the engine, so the consistency here depends on the connector behavior.
@martint is this something we should revisit?

throw semanticException(NOT_SUPPORTED, statement, "Cannot modify hidden column");
}
if (columnMetadata.getDefaultValue().isEmpty()) {
throw semanticException(GENERIC_USER_ERROR, statement, "Column '%s' does not have a default value", columnName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a new error code for this case.

@github-actions
Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack.

@github-actions github-actions Bot added the stale label Oct 27, 2025
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from a9591b6 to 66d0138 Compare October 27, 2025 22:26
@github-actions github-actions Bot removed the stale label Oct 28, 2025
@github-actions
Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack.

@github-actions github-actions Bot added the stale label Nov 18, 2025
@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from 66d0138 to 75e1604 Compare November 18, 2025 23:52
@github-actions github-actions Bot removed the stale label Nov 19, 2025
@martint
Copy link
Copy Markdown
Member

martint commented Nov 21, 2025

Syntax looks good.

@ebyhr ebyhr force-pushed the ebi/core-set-drop-default-clause branch from 75e1604 to e29ef5c Compare November 21, 2025 02:50
@ebyhr
Copy link
Copy Markdown
Member Author

ebyhr commented Nov 21, 2025

(Squashed a fixup commit)

@ebyhr ebyhr merged commit 487112c into trinodb:master Nov 21, 2025
3 of 13 checks passed
@ebyhr ebyhr deleted the ebi/core-set-drop-default-clause branch November 21, 2025 02:51
@github-actions github-actions Bot added this to the 479 milestone Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants