-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Verify column name length in PostgreSQL and SQL Server #13742
Conversation
4bb1cb8
to
4c10f34
Compare
4c10f34
to
88dae14
Compare
@ebyhr can you please rebase? there are conflicts. |
88dae14
to
831a156
Compare
Rebased on upstream to resolved conflicts. |
@@ -150,6 +150,8 @@ | |||
// An empty character means that the table doesn't have a comment in MariaDB | |||
private static final String NO_COMMENT = ""; | |||
|
|||
private static final int PARSE_ERROR = 1064; |
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 it documented? can you link to docs?
@@ -457,7 +459,7 @@ public void renameColumn(ConnectorSession session, JdbcTableHandle handle, JdbcC | |||
execute(connection, sql); | |||
} | |||
catch (TrinoException e) { | |||
if (e.getCause() instanceof SQLSyntaxErrorException) { | |||
if (e.getCause() instanceof SQLSyntaxErrorException syntaxError && syntaxError.getErrorCode() == PARSE_ERROR) { |
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.
SQLSyntaxErrorException contains invalid column name.
add a code comment
// Note: SQLSyntaxErrorException can be throw also when column name is invalid
BTW do we need this complicated logic?
why not "drop support" for the older MariaDB version and simplify 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.
I think throwing an MariaDB exception without conversion is also fine. Let me handle in a follow-up PR.
jdbcColumn.getColumnName(), | ||
newRemoteColumnName); |
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.
Why aren't these quoted?
(i know they weren't quoted before the refactor)
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.
Thanks for catching that. Let me fix in a follow-up PR.
// PostgreSQL truncates table name to 63 chars silently | ||
// PostgreSQL driver caches the max column name length in a DatabaseMetaData object. The cost to call this method per column is low. | ||
if (columnName.length() > databaseMetadata.getMaxColumnNameLength()) { | ||
throw new TrinoException(NOT_SUPPORTED, format("Column name must be shorter than or equal to '%s' characters but got '%s'", databaseMetadata.getMaxColumnNameLength(), columnName.length())); |
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.
Quote the contents of the columnName
in the message besides their length.
It's important for CREATE TABLE statement, where there can be multiple potentially problematic columns in play
// SQL Server truncates table name to the max length silently when renaming a column | ||
// SQL Server driver doesn't communicate with a server in getMaxColumnNameLength. The cost to call this method per column is low. | ||
if (columnName.length() > databaseMetadata.getMaxColumnNameLength()) { | ||
throw new TrinoException(NOT_SUPPORTED, format("Column name must be shorter than or equal to '%s' characters but got '%s'", databaseMetadata.getMaxColumnNameLength(), columnName.length())); |
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.
Quote the contents of the columnName
in the message besides their length
SQLSyntaxErrorException contains invalid column name.
testRenameColumn was skipped by SUPPORTS_CREATE_TABLE condition.
831a156
to
b01e763
Compare
Today while in looking into something related I saw a very disturbing behaviour from postgres. Directly in Postgres:
This means that Postgres truncates ALL occurences of long identifiers and the truncated values are treated equivalently. However when selecting from a relation which produces So it seems we're still "safe" in the sense that if for example join pushdown caused truncated identifiers then the worst thing that can happen would be query failure because postgres would complain of ambiguity. |
Description
Fixes #12882
Documentation
(x) No documentation is needed.
Release notes
(x) Release notes entries required with the following suggested text: