-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ALTER COLUMN SET DATA TYPE statement #11608
Conversation
04a6a48
to
9344ed4
Compare
* | ||
* @throws AccessDeniedException if not allowed | ||
*/ | ||
void checkCanAlterColumn(SecurityContext context, QualifiedObjectName tableName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if checkCanAlterTable
is not enough here. However this can be modeled by the implementation of the access control easily. So I think checkCanAlterColumn
is good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the SQL spec:
- The enabled authorization identifiers shall include the
<authorization identifier>
that owns the schema identified by the<schema name>
of the table identified by<table name>
.
0d98dcc
to
188323d
Compare
52ec290
to
f92141a
Compare
f92141a
to
bcd411b
Compare
bcd411b
to
e4ce14c
Compare
e4ce14c
to
6699757
Compare
6699757
to
d32f968
Compare
d32f968
to
2c321a2
Compare
6d7ca24
to
b01be62
Compare
b01be62
to
14a445d
Compare
6f137a4
to
d23f22c
Compare
👋 @ebyhr - this PR has become inactive. If you're still interested in working on it, please let us know. We're working on closing out old and inactive PRs, so if you're too busy or this has too many merge conflicts to be worth picking back up, we'll be making another pass to close it out in a few weeks. |
core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
Outdated
Show resolved
Hide resolved
@ebyhr can you please chop it a little bit? let's have a grammar commit (antlr grammar, astbuilder, sqlformatter) let's also move mongo stuff to separate PR; i tend not to review Mongo-related stuff |
a305366
to
8df8da2
Compare
Separate into two commits and removed a MongoDB commit. |
core/trino-main/src/main/java/io/trino/execution/SetColumnTypeTask.java
Outdated
Show resolved
Hide resolved
8df8da2
to
34d7298
Compare
CI hit #15367 |
accessControl.checkCanAlterColumn(session.toSecurityContext(), redirectionAwareTableHandle.getRedirectedTableName().orElse(qualifiedObjectName)); | ||
|
||
TableHandle tableHandle = redirectionAwareTableHandle.getTableHandle().get(); | ||
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you make sure the user can see the column here using accessControl.filterColumns
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, other column tasks (e.g. DROP COLUMN
) don't have such logic.
@kokosing Do you have any opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the accessControl.filterColumns
check is relevant currently only within information_schema.columns
metadata table.
core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/SetColumnType.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/SetColumnType.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/SetColumnType.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/SetColumnType.java
Outdated
Show resolved
Hide resolved
accessControl.checkCanAlterColumn(session.toSecurityContext(), redirectionAwareTableHandle.getRedirectedTableName().orElse(qualifiedObjectName)); | ||
|
||
TableHandle tableHandle = redirectionAwareTableHandle.getTableHandle().get(); | ||
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the accessControl.filterColumns
check is relevant currently only within information_schema.columns
metadata table.
List<ColumnMetadata> columns = new ArrayList<>(tableMetadata.getColumns()); | ||
ColumnMetadata columnMetadata = getColumnMetadata(session, tableHandle, column); | ||
columns.set(columns.indexOf(columnMetadata), ColumnMetadata.builderFrom(columnMetadata).setType(type).build()); | ||
tables.put(tableName, new ConnectorTableMetadata(tableName, ImmutableList.copyOf(columns), tableMetadata.getProperties(), tableMetadata.getComment())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is the copy of the columns actually necessary?
} | ||
|
||
@Override | ||
public boolean shallowEquals(Node other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this override needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hopefully not needed, please remove
(the current impl isn't correct yet, it should check all local fields)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The javadoc of shallowEquals
method says below. I don't think we should check all fields. I will remove either though.
Compare with another node by considering internal state excluding any Node returned by getChildren()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you might be right. Still -- let's try to remove it, and avoid need for discussing it.
For example, AddColumn
doesn't implement this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you might be right. Still -- let's try to remove it, and avoid need for discussing it.
@ebyhr thoughts?
} | ||
|
||
private SetColumnType(Optional<NodeLocation> location, QualifiedName tableName, Identifier columnName, DataType type, boolean tableExists) | ||
public SetColumnType(Optional<NodeLocation> location, QualifiedName tableName, Identifier columnName, DataType type, boolean tableExists) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
location is always known (except for io.trino.execution.TestSetColumnTypeTask#executeSetColumnType
where you can fill it with dummy value), so no need for optional?
@Test | ||
public void testAlterColumnSetDataType() | ||
{ | ||
assertStatement("ALTER TABLE foo.t ALTER COLUMN a SET DATA TYPE bigint", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertStatement
is deprecated (although my IDE doesn't highlight that, perhaps because this is same class)
use assertThat(statement(....))
.
} | ||
|
||
@Override | ||
public boolean shallowEquals(Node other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hopefully not needed, please remove
(the current impl isn't correct yet, it should check all local fields)
Addressed comments. |
30e57f9
to
e0a1f6e
Compare
(squashed and rebased) |
public SetColumnType(NodeLocation location, QualifiedName tableName, Identifier columnName, DataType type, boolean tableExists) | ||
{ | ||
this(Optional.of(location), tableName, columnName, type, tableExists); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in this class should all go in the first commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% commit boundaries alignment and shallowEquals removal
e0a1f6e
to
1db772f
Compare
1db772f
to
b85a786
Compare
Incorporate following changes Pass properties when checking access for CREATE SCHEMA trinodb/trino#15153 trinodb/trino@e16620f Support ALTER COLUMN SET DATA TYPE statement trinodb/trino#11608 trinodb/trino@ef94c0d
Incorporate following changes Pass properties when checking access for CREATE SCHEMA trinodb/trino#15153 trinodb/trino@e16620f Support ALTER COLUMN SET DATA TYPE statement trinodb/trino#11608 trinodb/trino@ef94c0d
Description
Support ALTER COLUMN SET DATA TYPE statement. ANSI specification:
Documentation
( ) No documentation is needed.
(x) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
( ) No release notes entries required.
(x) Release notes entries required with the following suggested text:
Fixes #10736