-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[StatementVerifier] Fix up issues in ToString implementations of classes derived from SQLStatement #11625
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
Conversation
… deprecated) ToSQL()
…ll append the catalog to the result
Mytherin
left a comment
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 the PR! Some comments below
|
Thanks! |
Merge pull request duckdb/duckdb#11625 from Tishj/statement_to_string_fixes Merge pull request duckdb/duckdb#11770 from pdet/mv_test Merge pull request duckdb/duckdb#11784 from szarnyasg/ci-job-expected-behavior-label
|
The change from the string I see
In particular, not 100% following this:
Wouldn't that be true for all the other types as well? Why would NULL need to be special cased, the return value of |
|
Quotes are added to other types that need them as well - for example: D select typeof(null::struct(this_is_an_unquoted_identifier integer)) AS struct_type;
┌────────────────────────────────────────────────┐
│ struct_type │
│ varchar │
├────────────────────────────────────────────────┤
│ STRUCT(this_is_an_unquoted_identifier INTEGER) │
└────────────────────────────────────────────────┘
D select typeof(null::struct("this is a quoted identifier" integer)) AS struct_type;
┌───────────────────────────────────────────────┐
│ struct_type │
│ varchar │
├───────────────────────────────────────────────┤
│ STRUCT("this is a quoted identifier" INTEGER) │
└───────────────────────────────────────────────┘
The main idea here is that We could strip the quotes from |
|
To add to that - here's the SQL that shows that D select cast(null as int) AS result;
┌────────┐
│ result │
│ int32 │
├────────┤
│ NULL │
└────────┘
D select cast(null as null) AS result;
-- Parser Error: syntax error at or near "null"
-- LINE 1: select cast(null as null) AS result;
-- ^
D select cast(null as "null") AS result;
┌────────┐
│ result │
│ int32 │
├────────┤
│ NULL │
└────────┘
|
|
Ah, got it. The double quote wasn't clicking, but now it makes sense: you need them to differentiate betwee NULL-the-value and NULL-the-identifier-that-refers-to-a-type. |
We add a virtual method to SQLStatement (and CreateInfo) calledHasToString, used to signify thatToStringhas been overridden for that type and it can safely be called.(The defaultSQLStatement::ToStringjust throws an InternalException)Instead of the switch case in the statement verifier path, we now use this method.The default
ToStringhas been changed to throw a NotImplementedException instead, in places where ToString can be used, we employtry/catchas a boolean to indicate whetherToStringwas implemented.This uncovered some issues in existing ToString implementations, which this PR fixes.
LogicalType::ToStringproblemOne notable change (which we might want to find a better solution for):
the SQLNULL type ToString used to return
NULL, now turned into"NULL", because when it appears in a query it has to be quoted.See
test/sql/types/test_null_type.testPossible Solution
Similar to
Valueperhaps we need a differentiation between ToString and ToSQLString for LogicalType as well.Where the SQLString uses the quoting rules, and ToString doesn't