Skip to content
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

Do not allow to INSERT into a table with row filter #7346

Merged
merged 2 commits into from Mar 20, 2021

Conversation

kokosing
Copy link
Member

Do not allow to INSERT into a table with row filter

@@ -405,4 +405,16 @@ public void testUpdate()
assertThatThrownBy(() -> assertions.query("UPDATE orders SET totalprice = totalprice * 2 WHERE orderkey IN (10, 20, 30)"))
Copy link
Member

Choose a reason for hiding this comment

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

Typo in commit message: filterring

@@ -415,7 +415,7 @@ protected Scope visitInsert(Insert insert, Optional<Scope> scope)

for (ColumnMetadata column : columns) {
if (!accessControl.getColumnMasks(session.toSecurityContext(), targetTable, column.getName(), column.getType()).isEmpty()) {
throw semanticException(NOT_SUPPORTED, insert, "Insert into table with column masks");
throw semanticException(NOT_SUPPORTED, insert, "Insert into table with column masks is not supported");
Copy link
Member

Choose a reason for hiding this comment

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

or "not allowed"

Copy link
Contributor

Choose a reason for hiding this comment

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

This is at least consistent with the analogous message for UPDATE, see e.g. line 1866 and 1873

Copy link
Member Author

Choose a reason for hiding this comment

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

kokosing@m16:~/presto$ grep -i 'not allowed' ./core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
                        throw semanticException(INVALID_COLUMN_REFERENCE, reference, "LATERAL reference not allowed in %s JOIN", node.getType().name());
                            throw semanticException(COLUMN_NOT_FOUND, allColumns, "SELECT * not allowed from relation that has no columns");
                        throw semanticException(COLUMN_NOT_FOUND, allColumns, "SELECT * not allowed in queries without FROM clause");
                    throw semanticException(COLUMN_NOT_FOUND, allColumns, "SELECT * not allowed from relation that has no columns");
                    // Since RECURSIVE is specified, any reference to WITH query name is considered a recursive reference and is not allowed.
                            throw semanticException(INVALID_RECURSIVE_REFERENCE, recursiveReferences.get(0), "recursive reference not allowed in this context");
kokosing@m16:~/presto$ grep -i 'not supported' ./core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
            throw semanticException(NOT_SUPPORTED, node, "USE statement is not supported");
                throw semanticException(NOT_SUPPORTED, insert, "Inserting into materialized views is not supported");
                throw semanticException(NOT_SUPPORTED, insert, "Inserting into views is not supported");
                throw semanticException(NOT_SUPPORTED, insert, "Insert into table with a row filter is not supported");
                    throw semanticException(NOT_SUPPORTED, insert, "Insert into table with column masks is not supported");
                throw semanticException(NOT_SUPPORTED, node, "Deleting from views is not supported");
                throw semanticException(NOT_SUPPORTED, node, "Analyzing views is not supported");
                throw semanticException(NOT_SUPPORTED, node, "Natural join not supported");
                throw semanticException(NOT_SUPPORTED, update, "Updating through views is not supported");
                throw semanticException(NOT_SUPPORTED, update, "Updating a table with a row filter is not supported");
                    throw semanticException(NOT_SUPPORTED, update, "Updating a table with column masks is not supported");
                // filter with window function is not supported yet
                    throw semanticException(NOT_SUPPORTED, windowFunction, "Window function with ORDER BY is not supported");
                    throw semanticException(NOT_SUPPORTED, allColumns, "Column aliases not supported");
                        throw semanticException(NOT_SUPPORTED, node.getSelect(), "SELECT * from outer scope table not supported with anonymous columns");
                    throw semanticException(EXPRESSION_NOT_IN_DISTINCT, expression, "Non deterministic ORDER BY expression is not supported with SELECT DISTINCT")

This is coherent with the current convention. I see your point so I created an issue for this, see: #7369

USER,
new ViewExpression(USER, Optional.empty(), Optional.empty(), "nationkey < 10"));
assertThatThrownBy(() -> assertions.query("INSERT INTO nation VALUES (26, 'POLAND', 0, 'No comment')"))
.hasMessage("This connector does not support inserts");
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong. We should be testing with a connector which does support inserts, or make a mock connector pretend it does that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me squash this commit then to avoid imperfect intermediate state.

@@ -407,6 +407,10 @@ protected Scope visitInsert(Insert insert, Optional<Scope> scope)
}
accessControl.checkCanInsertIntoTable(session.toSecurityContext(), targetTable);

if (!accessControl.getRowFilters(session.toSecurityContext(), targetTable).isEmpty()) {
throw semanticException(NOT_SUPPORTED, insert, "Insert into table with a row filter is not supported");
Copy link
Member

Choose a reason for hiding this comment

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

or "is not allowed"

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@ksobolew ksobolew left a comment

Choose a reason for hiding this comment

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

Some nits, and more serious concerns should be a separate PR

@kokosing kokosing merged commit 6395ff0 into trinodb:master Mar 20, 2021
@kokosing kokosing deleted the origin/master/300_insert branch March 20, 2021 19:35
@kokosing kokosing mentioned this pull request Mar 20, 2021
7 tasks
@kokosing kokosing added this to the 355 milestone Mar 20, 2021
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.

None yet

4 participants