Skip to content

Conversation

ebyhr
Copy link
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 112
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
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 +94
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
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
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
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
Copy link

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
Copy link

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
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?

@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
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
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
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.

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.

3 participants