Skip to content

Commit

Permalink
Merge #31635
Browse files Browse the repository at this point in the history
31635: sql/parser: add missing telemetry for unimplemented features r=knz a=knz

Requested by @awoods187.

I feel really like a doofus for forgetting CREATE SCHEMA the first time around given that we have a lot of focus on it...



Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
  • Loading branch information
craig[bot] and knz committed Oct 21, 2018
2 parents 3035b84 + df3712a commit 91fb450
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ unreserved_keyword ::=
| 'DAY'
| 'DEALLOCATE'
| 'DELETE'
| 'DEFERRED'
| 'DISCARD'
| 'DOMAIN'
| 'DOUBLE'
Expand Down Expand Up @@ -589,6 +590,7 @@ unreserved_keyword ::=
| 'HIGH'
| 'HISTOGRAM'
| 'HOUR'
| 'IMMEDIATE'
| 'IMPORT'
| 'INCREMENT'
| 'INCREMENTAL'
Expand Down Expand Up @@ -634,6 +636,7 @@ unreserved_keyword ::=
| 'OF'
| 'OFF'
| 'OID'
| 'OIDS'
| 'OIDVECTOR'
| 'OPERATOR'
| 'OPTION'
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,7 @@ func TestUnimplementedSyntax(t *testing.T) {
{`CREATE OPERATOR a`, 0, `create operator`},
{`CREATE PUBLICATION a`, 0, `create publication`},
{`CREATE RULE a`, 0, `create rule`},
{`CREATE SCHEMA a`, 26443, `create`},
{`CREATE SERVER a`, 0, `create server`},
{`CREATE SUBSCRIPTION a`, 0, `create subscription`},
{`CREATE TEXT SEARCH a`, 7821, `create text`},
Expand All @@ -2578,6 +2579,7 @@ func TestUnimplementedSyntax(t *testing.T) {
{`DROP OPERATOR a`, 0, `drop operator`},
{`DROP PUBLICATION a`, 0, `drop publication`},
{`DROP RULE a`, 0, `drop rule`},
{`DROP SCHEMA a`, 26443, `drop`},
{`DROP SERVER a`, 0, `drop server`},
{`DROP SUBSCRIPTION a`, 0, `drop subscription`},
{`DROP TEXT SEARCH a`, 7821, `drop text`},
Expand All @@ -2598,11 +2600,26 @@ func TestUnimplementedSyntax(t *testing.T) {
{`CREATE TEMP VIEW a AS SELECT b`, 5807, ``},
{`CREATE TEMP SEQUENCE a`, 5807, ``},

{`CREATE TABLE a(LIKE b)`, 30840, ``},

{`CREATE TABLE a(b INT) WITH OIDS`, 0, `create table with oids`},
{`CREATE TABLE a(b INT) WITH foo = bar`, 0, `create table with foo`},

{`CREATE TABLE a AS SELECT b WITH NO DATA`, 0, `create table as with no data`},

{`CREATE TABLE a(b INT AS (123) VIRTUAL)`, 0, `virtual computed columns`},
{`CREATE TABLE a(b INT REFERENCES c(x) MATCH FULL`, 0, `references match full`},
{`CREATE TABLE a(b INT REFERENCES c(x) MATCH PARTIAL`, 0, `references match partial`},
{`CREATE TABLE a(b INT REFERENCES c(x) MATCH SIMPLE`, 0, `references match simple`},

{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) DEFERRABLE)`, 31632, `deferrable`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) INITIALLY DEFERRED)`, 31632, `initially deferred`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) INITIALLY IMMEDIATE)`, 31632, `initially immediate`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) DEFERRABLE INITIALLY DEFERRED)`, 31632, `initially deferred`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) DEFERRABLE INITIALLY IMMEDIATE)`, 31632, `initially immediate`},
{`CREATE TABLE a(b INT, UNIQUE (b) DEFERRABLE)`, 31632, `deferrable`},
{`CREATE TABLE a(b INT, CHECK (b > 0) DEFERRABLE)`, 31632, `deferrable`},

{`CREATE SEQUENCE a AS DOUBLE PRECISION`, 25110, `FLOAT8`},
{`CREATE SEQUENCE a OWNED BY b`, 26382, ``},

Expand Down
48 changes: 36 additions & 12 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func newNameFromStr(s string) *tree.Name {
%token <str> CURRENT_USER CYCLE

%token <str> DATA DATABASE DATABASES DATE DAY DEC DECIMAL DEFAULT
%token <str> DEALLOCATE DEFERRABLE DELETE DESC
%token <str> DEALLOCATE DEFERRABLE DEFERRED DELETE DESC
%token <str> DISCARD DISTINCT DO DOMAIN DOUBLE DROP

%token <str> ELSE ENCODING END ENUM ESCAPE EXCEPT
Expand All @@ -502,7 +502,7 @@ func newNameFromStr(s string) *tree.Name {

%token <str> HAVING HIGH HISTOGRAM HOUR

%token <str> IMPORT INCREMENT INCREMENTAL IF IFERROR IFNULL ILIKE IN ISERROR
%token <str> IMMEDIATE IMPORT INCREMENT INCREMENTAL IF IFERROR IFNULL ILIKE IN ISERROR
%token <str> INET INET_CONTAINED_BY_OR_EQUALS INET_CONTAINS_OR_CONTAINED_BY
%token <str> INET_CONTAINS_OR_EQUALS INDEX INDEXES INJECT INTERLEAVE INITIALLY
%token <str> INNER INSERT INT INT2VECTOR INT2 INT4 INT8 INT64 INTEGER
Expand All @@ -521,7 +521,7 @@ func newNameFromStr(s string) *tree.Name {
%token <str> NAN NAME NAMES NATURAL NEXT NO NO_INDEX_JOIN NORMAL
%token <str> NOT NOTHING NOTNULL NULL NULLIF NUMERIC

%token <str> OF OFF OFFSET OID OIDVECTOR ON ONLY OPTION OPTIONS OR
%token <str> OF OFF OFFSET OID OIDS OIDVECTOR ON ONLY OPTION OPTIONS OR
%token <str> ORDER ORDINALITY OUT OUTER OVER OVERLAPS OVERLAY OWNED OPERATOR

%token <str> PARENT PARTIAL PARTITION PASSWORD PAUSE PHYSICAL PLACING
Expand Down Expand Up @@ -1975,6 +1975,7 @@ create_unsupported:
| CREATE OPERATOR error { return unimplemented(sqllex, "create operator") }
| CREATE PUBLICATION error { return unimplemented(sqllex, "create publication") }
| CREATE opt_or_replace RULE error { return unimplemented(sqllex, "create rule") }
| CREATE SCHEMA error { return unimplementedWithIssueDetail(sqllex, 26443, "create") }
| CREATE SERVER error { return unimplemented(sqllex, "create server") }
| CREATE SUBSCRIPTION error { return unimplemented(sqllex, "create subscription") }
| CREATE TEXT error { return unimplementedWithIssueDetail(sqllex, 7821, "create text") }
Expand Down Expand Up @@ -2007,6 +2008,7 @@ drop_unsupported:
| DROP OPERATOR error { return unimplemented(sqllex, "drop operator") }
| DROP PUBLICATION error { return unimplemented(sqllex, "drop publication") }
| DROP RULE error { return unimplemented(sqllex, "drop rule") }
| DROP SCHEMA error { return unimplementedWithIssueDetail(sqllex, 26443, "drop") }
| DROP SERVER error { return unimplemented(sqllex, "drop server") }
| DROP SUBSCRIPTION error { return unimplemented(sqllex, "drop subscription") }
| DROP TEXT error { return unimplementedWithIssueDetail(sqllex, 7821, "drop text") }
Expand Down Expand Up @@ -3657,7 +3659,7 @@ pause_stmt:
// WEBDOCS/create-table.html
// WEBDOCS/create-table-as.html
create_table_stmt:
CREATE opt_temp TABLE table_name '(' opt_table_elem_list ')' opt_interleave opt_partition_by
CREATE opt_temp TABLE table_name '(' opt_table_elem_list ')' opt_interleave opt_partition_by opt_table_with
{
$$.val = &tree.CreateTable{
Table: $4.normalizableTableNameFromUnresolvedName(),
Expand All @@ -3669,7 +3671,7 @@ create_table_stmt:
PartitionBy: $9.partitionBy(),
}
}
| CREATE opt_temp TABLE IF NOT EXISTS table_name '(' opt_table_elem_list ')' opt_interleave opt_partition_by
| CREATE opt_temp TABLE IF NOT EXISTS table_name '(' opt_table_elem_list ')' opt_interleave opt_partition_by opt_table_with
{
$$.val = &tree.CreateTable{
Table: $7.normalizableTableNameFromUnresolvedName(),
Expand All @@ -3682,30 +3684,40 @@ create_table_stmt:
}
}

opt_table_with:
/* EMPTY */ { /* no error */ }
| WITHOUT OIDS { /* SKIP DOC */ /* this is also the default in CockroachDB */ }
| WITH name error { return unimplemented(sqllex, "create table with " + $2) }

create_table_as_stmt:
CREATE opt_temp TABLE table_name opt_column_list AS select_stmt
CREATE opt_temp TABLE table_name opt_column_list opt_table_with AS select_stmt opt_create_as_data
{
$$.val = &tree.CreateTable{
Table: $4.normalizableTableNameFromUnresolvedName(),
IfNotExists: false,
Interleave: nil,
Defs: nil,
AsSource: $7.slct(),
AsSource: $8.slct(),
AsColumnNames: $5.nameList(),
}
}
| CREATE opt_temp TABLE IF NOT EXISTS table_name opt_column_list AS select_stmt
| CREATE opt_temp TABLE IF NOT EXISTS table_name opt_column_list opt_table_with AS select_stmt opt_create_as_data
{
$$.val = &tree.CreateTable{
Table: $7.normalizableTableNameFromUnresolvedName(),
IfNotExists: true,
Interleave: nil,
Defs: nil,
AsSource: $10.slct(),
AsSource: $11.slct(),
AsColumnNames: $8.nameList(),
}
}

opt_create_as_data:
/* EMPTY */ { /* no error */ }
| WITH DATA { /* SKIP DOC */ /* This is the default */ }
| WITH NO DATA { return unimplemented(sqllex, "create table as with no data") }

/*
* Redundancy here is needed to avoid shift/reduce conflicts,
* since TEMP is not a reserved word. See also OptTempTableName.
Expand Down Expand Up @@ -3755,6 +3767,7 @@ table_elem:
{
$$.val = $1.constraintDef()
}
| LIKE table_name error { return unimplementedWithIssue(sqllex, 30840) }

opt_interleave:
INTERLEAVE IN PARENT table_name '(' name_list ')' opt_interleave_drop_behavior
Expand Down Expand Up @@ -4034,13 +4047,13 @@ table_constraint:
}

constraint_elem:
CHECK '(' a_expr ')'
CHECK '(' a_expr ')' opt_deferrable
{
$$.val = &tree.CheckConstraintTableDef{
Expr: $3.expr(),
}
}
| UNIQUE '(' index_params ')' opt_storing opt_interleave opt_partition_by
| UNIQUE '(' index_params ')' opt_storing opt_interleave opt_partition_by opt_deferrable
{
$$.val = &tree.UniqueConstraintTableDef{
IndexTableDef: tree.IndexTableDef{
Expand All @@ -4061,7 +4074,7 @@ constraint_elem:
}
}
| FOREIGN KEY '(' name_list ')' REFERENCES table_name
opt_column_list key_match reference_actions
opt_column_list key_match reference_actions opt_deferrable
{
$$.val = &tree.ForeignKeyConstraintTableDef{
Table: $7.normalizableTableNameFromUnresolvedName(),
Expand All @@ -4071,6 +4084,14 @@ constraint_elem:
}
}

opt_deferrable:
/* EMPTY */ { /* no error */ }
| DEFERRABLE { return unimplementedWithIssueDetail(sqllex, 31632, "deferrable") }
| DEFERRABLE INITIALLY DEFERRED { return unimplementedWithIssueDetail(sqllex, 31632, "def initially deferred") }
| DEFERRABLE INITIALLY IMMEDIATE { return unimplementedWithIssueDetail(sqllex, 31632, "def initially immediate") }
| INITIALLY DEFERRED { return unimplementedWithIssueDetail(sqllex, 31632, "initially deferred") }
| INITIALLY IMMEDIATE { return unimplementedWithIssueDetail(sqllex, 31632, "initially immediate") }

storing:
COVERING
| STORING
Expand Down Expand Up @@ -8377,6 +8398,7 @@ unreserved_keyword:
| DAY
| DEALLOCATE
| DELETE
| DEFERRED
| DISCARD
| DOMAIN
| DOUBLE
Expand Down Expand Up @@ -8408,6 +8430,7 @@ unreserved_keyword:
| HIGH
| HISTOGRAM
| HOUR
| IMMEDIATE
| IMPORT
| INCREMENT
| INCREMENTAL
Expand Down Expand Up @@ -8453,6 +8476,7 @@ unreserved_keyword:
| OF
| OFF
| OID
| OIDS
| OIDVECTOR
| OPERATOR
| OPTION
Expand Down

0 comments on commit 91fb450

Please sign in to comment.