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

sql/parser: unreserve INDEX and NOTHING from the RHS of SET statements #31731

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,8 @@ kv_option_list ::=

complex_table_pattern ::=
complex_db_object_name
| name '.' unrestricted_name '.' '*'
| name '.' '*'
| db_object_name_component '.' unrestricted_name '.' '*'
| db_object_name_component '.' '*'
| '*'

table_pattern ::=
Expand Down Expand Up @@ -1052,7 +1052,7 @@ to_or_eq ::=

var_value ::=
a_expr
| 'ON'
| extra_var_value

opt_on_targets_roles ::=
'ON' targets_roles
Expand Down Expand Up @@ -1095,11 +1095,11 @@ set_clause ::=
| multiple_set_clause

simple_db_object_name ::=
name
db_object_name_component

complex_db_object_name ::=
name '.' unrestricted_name
| name '.' unrestricted_name '.' unrestricted_name
db_object_name_component '.' unrestricted_name
| db_object_name_component '.' unrestricted_name '.' unrestricted_name

non_reserved_word ::=
'identifier'
Expand All @@ -1113,6 +1113,11 @@ kv_option ::=
| 'SCONST' '=' string_or_placeholder
| 'SCONST'

db_object_name_component ::=
name
| cockroachdb_extra_type_func_name_keyword
| cockroachdb_extra_reserved_keyword

unrestricted_name ::=
'identifier'
| unreserved_keyword
Expand Down Expand Up @@ -1416,6 +1421,10 @@ offset_clause ::=
generic_set ::=
var_name to_or_eq var_list

extra_var_value ::=
'ON'
| cockroachdb_extra_reserved_keyword

targets_roles ::=
'ROLE' name_list
| targets
Expand All @@ -1432,7 +1441,6 @@ multiple_set_clause ::=
type_func_name_keyword ::=
'COLLATION'
| 'CROSS'
| 'FAMILY'
| 'FULL'
| 'INNER'
| 'ILIKE'
Expand All @@ -1441,14 +1449,22 @@ type_func_name_keyword ::=
| 'JOIN'
| 'LEFT'
| 'LIKE'
| 'MAXVALUE'
| 'MINVALUE'
| 'NATURAL'
| 'NOTNULL'
| 'OUTER'
| 'OVERLAPS'
| 'RIGHT'
| 'SIMILAR'
| cockroachdb_extra_type_func_name_keyword

cockroachdb_extra_type_func_name_keyword ::=
'FAMILY'
| 'MAXVALUE'
| 'MINVALUE'

cockroachdb_extra_reserved_keyword ::=
'INDEX'
| 'NOTHING'

reserved_keyword ::=
'ALL'
Expand Down Expand Up @@ -1492,7 +1508,6 @@ reserved_keyword ::=
| 'GROUP'
| 'HAVING'
| 'IN'
| 'INDEX'
| 'INITIALLY'
| 'INTERSECT'
| 'INTO'
Expand All @@ -1502,7 +1517,6 @@ reserved_keyword ::=
| 'LOCALTIME'
| 'LOCALTIMESTAMP'
| 'NOT'
| 'NOTHING'
| 'NULL'
| 'OFFSET'
| 'ON'
Expand Down Expand Up @@ -1531,6 +1545,7 @@ reserved_keyword ::=
| 'WHERE'
| 'WINDOW'
| 'WITH'
| cockroachdb_extra_reserved_keyword

transaction_iso_level ::=
'ISOLATION' 'LEVEL' iso_level
Expand Down Expand Up @@ -1651,9 +1666,9 @@ interval ::=

column_path_with_star ::=
column_path
| name '.' unrestricted_name '.' unrestricted_name '.' '*'
| name '.' unrestricted_name '.' '*'
| name '.' '*'
| db_object_name_component '.' unrestricted_name '.' unrestricted_name '.' '*'
| db_object_name_component '.' unrestricted_name '.' '*'
| db_object_name_component '.' '*'

func_expr ::=
func_application filter_clause over_clause
Expand Down Expand Up @@ -2050,9 +2065,9 @@ interval_qualifier ::=
| 'MINUTE' 'TO' interval_second

prefixed_column_path ::=
name '.' unrestricted_name
| name '.' unrestricted_name '.' unrestricted_name
| name '.' unrestricted_name '.' unrestricted_name '.' unrestricted_name
db_object_name_component '.' unrestricted_name
| db_object_name_component '.' unrestricted_name '.' unrestricted_name
| db_object_name_component '.' unrestricted_name '.' unrestricted_name '.' unrestricted_name

func_name ::=
type_function_name
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/parser/all_keywords.awk
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ BEGIN {
category = "C"
} else if ($1 == "unreserved_keyword:") {
category = "U"
} else if ($1 == "type_func_name_keyword:") {
} else if ($1 == "type_func_name_keyword:" || $1 == "cockroachdb_extra_type_func_name_keyword:") {
category = "T"
} else if ($1 == "reserved_keyword:") {
} else if ($1 == "reserved_keyword:" || $1 == "cockroachdb_extra_reserved_keyword:") {
category ="R"
} else {
print "unknown keyword type:", $1 >>"/dev/stderr"
Expand All @@ -36,7 +36,7 @@ BEGIN {
keyword = 0
}

{
/^ *\|? *[A-Z]/ {
if (keyword && $NF != "") {
printf("\"%s\": {%s, \"%s\"},\n", tolower($NF), $NF, category) | sort
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,21 @@ func TestParse2(t *testing.T) {
{`ALTER TABLE a ALTER b DROP NOT NULL`, `ALTER TABLE a ALTER COLUMN b DROP NOT NULL`},
{`ALTER TABLE a ALTER b TYPE INT`, `ALTER TABLE a ALTER COLUMN b SET DATA TYPE INT`},
{`EXPLAIN ANALYZE SELECT 1`, `EXPLAIN ANALYZE (DISTSQL) SELECT 1`},

{`SET a = INDEX`, `SET a = "index"`},
{`SET a = NOTHING`, `SET a = "nothing"`},

// Regression for #31589
{`CREATE TABLE FAMILY (x INT)`,
`CREATE TABLE "family" (x INT)`},
{`CREATE TABLE INDEX (x INT)`,
`CREATE TABLE "index" (x INT)`},
{`CREATE TABLE NOTHING (x INT)`,
`CREATE TABLE "nothing" (x INT)`},
{`CREATE TABLE MINVALUE (x INT)`,
`CREATE TABLE "minvalue" (x INT)`},
{`CREATE TABLE MAXVALUE (x INT)`,
`CREATE TABLE "maxvalue" (x INT)`},
}
for _, d := range testData {
stmts, err := parser.Parse(d.sql)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/parser/reserved_keywords.awk
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
next
}

/^type_func_name_keyword:/ {
/^(cockroachdb_extra_)?type_func_name_keyword:/ {
reserved_keyword = 1
next
}

/^reserved_keyword:/ {
/^(cockroachdb_extra_)?reserved_keyword:/ {
reserved_keyword = 1
next
}
Expand Down
Loading