sql/parser: recognize qualified type names#47216
sql/parser: recognize qualified type names#47216craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
|
Opening up a draft with the ideas i mentioned, please take a look! |
|
❌ The GitHub CI (Cockroach) build has failed on 2307f3dc. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. I am experimental - my owner is otan. |
|
Nice, the failures don't seem worrying, just slightly different output in some error messages. |
|
❌ The GitHub CI (Cockroach) build has failed on b8b78641. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. I am experimental - my owner is otan. |
|
Good start! Here are some things that postgres supports but your patch doesn't (yet):
|
a416562 to
2ba58aa
Compare
|
❌ The GitHub CI (Cockroach) build has failed on 2ba58aa7. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. I am experimental - my owner is otan. |
|
PTAL -- my original commit had support for the first two but I forgot to add a test. Adding @jordanlewis here, might have some comments. I think that we because added type aliases as keywords (something postgres doesn't do) led to a variety of conflicts. I removed the keywords for these and moved some of these aliases to be resolved by a lookup table during parsing (it replaces what we have now, but an argument could be that this should only be done during typechecking). For these aliases, we can reference them like you mentioned above ( Additionally, it seems like allowing types to be named Does this all make sense, or am i just making this tower of blocks more fragile? I don't have a good intuition for this yet. |
|
❌ The GitHub CI (Cockroach) build has failed on 6f43cf36. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. I am experimental - my owner is otan. |
443a0df to
21bc1b1
Compare
|
Additionally I don't see a way of parsing certain type keywords that are used in other places (like JSON, STRING) without quotes as qualified accessors for types -- e.g. I don't see a way to get |
|
❌ The GitHub CI (Cockroach) build has failed on 21bc1b1a. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. I am experimental - my owner is otan. |
|
❌ The GitHub CI (Cockroach) build has failed on d07d3c57. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. I am experimental - my owner is otan. |
|
Well it's odd to me that this is so complex, given that pg supports it with comparatively fewer grammar rules. |
|
I think I'm bringing us closer to pg here -- PG doesn't have all of these typenames in unreserved, so it doesn't run into the conflicts I'm trying to fix here (its unclear to me how it avoids conflicts for the few keywords I have left in unreserved_type_keyword). The apparent complexity of this PR is just in separating these unreserved_type_keywords and The most confusing this about pg's grammar around this for me is their rule for and So I don't know where they get their qualifications from. Our conflicts arise from names potentially starting with |
|
You misread pg's grammar: The magic is in |
916f117 to
4cc9fdb
Compare
|
Alright, I was able to simplify this more. I got rid of the separation between reserved and unreserved type keywords, which don't exist in PG's grammar. Now the only separation is in the type_func_keywords to possibly contain our extensions. |
knz
left a comment
There was a problem hiding this comment.
This is very, very good.
Reviewed 4 of 4 files at r1, 1 of 7 files at r2.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @knz and @rohany)
pkg/sql/parser/parse_test.go, line 3287 at r2 (raw file):
{`SELECT 1::int4.typ`, 0, `qualified types`, ``}, {`SELECT 1::db.schem.typ`, 0, `qualified types`, ``}, {`CREATE TABLE t (x special.type)`, 0, `qualified types`, ``},
can you add the additional CREATE TABLE tests with composite type names containing keywords here to see which errors are reported.
Also verify:
<composite type> ARRAY [ ]<composite type> ARRAY [ 123 ]123 IS OF (<composite type>, <composite type>)
also with mixes of keywords and non-keywords.
pkg/sql/parser/sql.y, line 8354 at r2 (raw file):
} | func_name '(' expr_list opt_sort_clause ')' SCONST { return unimplemented(sqllex, $1.unresolvedName().String() + "(...) SCONST") } // The key here is that none of the keywords in the func_name_no_type_reserved
Would it be possible to pull both this rule and that below (const_typename SCONST) into a separate non-terminal called typed_literal or something and explain it as a separate thing.
This makes it easier visually to connect the two things together.
pkg/sql/parser/sql.y, line 8357 at r2 (raw file):
// production can overlap with the type rules in const_typename, otherwise // we will have conflicts between this rule and the one below. | func_name_no_type_reserved SCONST
Separate comment: maybe the name func_name_excluding_const_typenames would be better? This way it's clearer visually that they don't overlap when quickly glancing through.
pkg/sql/parser/sql.y, line 9802 at r2 (raw file):
// Type/function identifier without CRDB extra reserved keywords. type_function_name_no_crdb_extra:
Keep the naming pattern from type_func_name_keyword:
type_function_name_no_crdb_extra -> type_func_name_keyword_no_crdb_extra
This ensures that both type_func_name_keyword AND type_func_name_keyword_no_crdb_extra get highlighted in a text editor search when searching for the common prefix.
pkg/sql/parser/sql.y, line 10158 at r2 (raw file):
type_func_name_keyword: pg_type_func_name_keyword | cockroachdb_extra_type_func_name_keyword
You already used _no_crdb_extra above. I recommend the following renames:
pg_type_func_name_keyword->func_name_keyword_no_crdb_extracockroachdb_extra_type_func_name_keyword->func_name_keyword_crdb_extra
rohany
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @knz)
pkg/sql/parser/parse_test.go, line 3287 at r2 (raw file):
Previously, knz (kena) wrote…
can you add the additional CREATE TABLE tests with composite type names containing keywords here to see which errors are reported.
Also verify:
<composite type> ARRAY [ ]<composite type> ARRAY [ 123 ]123 IS OF (<composite type>, <composite type>)also with mixes of keywords and non-keywords.
Done
pkg/sql/parser/sql.y, line 8354 at r2 (raw file):
Previously, knz (kena) wrote…
Would it be possible to pull both this rule and that below (
const_typename SCONST) into a separate non-terminal calledtyped_literalor something and explain it as a separate thing.
This makes it easier visually to connect the two things together.
Done, that makes thing clearer.
pkg/sql/parser/sql.y, line 8357 at r2 (raw file):
Previously, knz (kena) wrote…
Separate comment: maybe the name
func_name_excluding_const_typenameswould be better? This way it's clearer visually that they don't overlap when quickly glancing through.
I renamed it -- after I got rid of separate typenames, this should just be named func_name_no_crdb_extra, since that is the only difference now.
pkg/sql/parser/sql.y, line 9802 at r2 (raw file):
Previously, knz (kena) wrote…
Keep the naming pattern from
type_func_name_keyword:
type_function_name_no_crdb_extra->type_func_name_keyword_no_crdb_extraThis ensures that both
type_func_name_keywordANDtype_func_name_keyword_no_crdb_extraget highlighted in a text editor search when searching for the common prefix.
I think type_function_name_no_crdb_extra follows along with the patterns we have so far -- it mirrors the rule type_function_name, so I don't want to change that prefix.
pkg/sql/parser/sql.y, line 10158 at r2 (raw file):
Previously, knz (kena) wrote…
You already used
_no_crdb_extraabove. I recommend the following renames:
pg_type_func_name_keyword->func_name_keyword_no_crdb_extracockroachdb_extra_type_func_name_keyword->func_name_keyword_crdb_extra
I did something similar. I need to end the production with keyword so the keyword generator picks it up, so I can't follow this exactly.
jordanlewis
left a comment
There was a problem hiding this comment.
Great simplification! Looks good to me.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @knz and @rohany)
pkg/sql/parser/parse_test.go, line 2652 at r3 (raw file):
{ `SELECT CAST(1.2+2.3 AS notatype)`, `at or near ")": syntax error: type does not exist
Hmm... I'd definitely like to see this error improved somehow. Can it say type "notatype" does not exist?
pkg/sql/parser/sql.y, line 7355 at r3 (raw file):
case 0: // Note: we can only report an unimplemented error for specific // known type names. Anything else may return PII.
nit: I'm not sure the phrase "PII" is used much here - how about "sensitive info"?
This PR allows the parser to recognize qualified typenames and generic typenames. To accomplish this, we move some type and typecast related productions closer to how the postgres grammar operates, and separate out type names from the unreserved_keyword_list. Release note: None
rohany
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis and @knz)
pkg/sql/parser/parse_test.go, line 2652 at r3 (raw file):
Previously, jordanlewis (Jordan Lewis) wrote…
Hmm... I'd definitely like to see this error improved somehow. Can it say
type "notatype" does not exist?
Done.
knz
left a comment
There was a problem hiding this comment.
Reviewed 2 of 7 files at r2, 3 of 5 files at r3, 2 of 2 files at r4.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis)
|
bors r+ TFTR! |
Build succeeded |
This PR allows the parser to recognize qualified typenames
and generic typenames.
To accomplish this, we move some type and typecast related
productions closer to how the postgres grammar operates,
and separate out type names from the unreserved_keyword_list.
Release note: None