Skip to content

Commit

Permalink
Merge #74821 #74822
Browse files Browse the repository at this point in the history
74821: parser: parse CREATE MATERIALIZED VIEW ... WITH [NO] DATA r=rafiss a=otan

WITH NO DATA is currently unimplemented, but we can no-op the WITH DATA.

Release note (sql change): `CREATE MATERIALIZED VIEW` syntax now
supported `WITH DATA`.

74822: dev: only build `:go_path` if you're building a `cockroach` binary r=irfansharif a=rickystewart

Release note: None

Co-authored-by: Oliver Tan <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
  • Loading branch information
3 people committed Jan 14, 2022
3 parents ffe26ec + 0eb8c2e + 4958987 commit 10b94f6
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 19 deletions.
2 changes: 0 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,5 @@ go_path(
mode = "link",
deps = [
"//pkg/cmd/cockroach-short",
"//pkg/cmd/roachprod",
"//pkg/cmd/roachtest",
],
)
2 changes: 1 addition & 1 deletion dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

# Bump this counter to force rebuilding `dev` on all machines.
DEV_VERSION=3
DEV_VERSION=4

THIS_DIR=$(cd "$(dirname "$0")" && pwd)
BINARY_DIR=$THIS_DIR/bin/dev-versions
Expand Down
8 changes: 4 additions & 4 deletions docs/generated/sql/bnf/create_view_stmt.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ create_view_stmt ::=
| 'CREATE' 'OR' 'REPLACE' opt_temp 'VIEW' view_name 'AS' select_stmt
| 'CREATE' opt_temp 'VIEW' 'IF' 'NOT' 'EXISTS' view_name '(' name_list ')' 'AS' select_stmt
| 'CREATE' opt_temp 'VIEW' 'IF' 'NOT' 'EXISTS' view_name 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' view_name '(' name_list ')' 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' view_name 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' 'IF' 'NOT' 'EXISTS' view_name '(' name_list ')' 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' 'IF' 'NOT' 'EXISTS' view_name 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' view_name '(' name_list ')' 'AS' select_stmt opt_with_data
| 'CREATE' 'MATERIALIZED' 'VIEW' view_name 'AS' select_stmt opt_with_data
| 'CREATE' 'MATERIALIZED' 'VIEW' 'IF' 'NOT' 'EXISTS' view_name '(' name_list ')' 'AS' select_stmt opt_with_data
| 'CREATE' 'MATERIALIZED' 'VIEW' 'IF' 'NOT' 'EXISTS' view_name 'AS' select_stmt opt_with_data
8 changes: 6 additions & 2 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,8 @@ create_view_stmt ::=
'CREATE' opt_temp 'VIEW' view_name opt_column_list 'AS' select_stmt
| 'CREATE' 'OR' 'REPLACE' opt_temp 'VIEW' view_name opt_column_list 'AS' select_stmt
| 'CREATE' opt_temp 'VIEW' 'IF' 'NOT' 'EXISTS' view_name opt_column_list 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' view_name opt_column_list 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' 'IF' 'NOT' 'EXISTS' view_name opt_column_list 'AS' select_stmt
| 'CREATE' 'MATERIALIZED' 'VIEW' view_name opt_column_list 'AS' select_stmt opt_with_data
| 'CREATE' 'MATERIALIZED' 'VIEW' 'IF' 'NOT' 'EXISTS' view_name opt_column_list 'AS' select_stmt opt_with_data

create_sequence_stmt ::=
'CREATE' opt_temp 'SEQUENCE' sequence_name opt_sequence_option_list
Expand Down Expand Up @@ -2025,6 +2025,10 @@ opt_temp ::=
| 'TEMP'
|

opt_with_data ::=
'WITH' 'DATA'
|

sequence_name ::=
db_object_name

Expand Down
31 changes: 24 additions & 7 deletions pkg/cmd/dev/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (d *dev) build(cmd *cobra.Command, commandLine []string) error {
if err := d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...); err != nil {
return err
}
return d.stageArtifacts(ctx, buildTargets, skipGenerate)
return d.stageArtifacts(ctx, buildTargets)
}
// Cross-compilation case.
for _, target := range buildTargets {
Expand Down Expand Up @@ -170,7 +170,7 @@ func (d *dev) build(cmd *cobra.Command, commandLine []string) error {
return nil
}

func (d *dev) stageArtifacts(ctx context.Context, targets []buildTarget, skipGenerate bool) error {
func (d *dev) stageArtifacts(ctx context.Context, targets []buildTarget) error {
workspace, err := d.getWorkspace(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -230,7 +230,13 @@ func (d *dev) stageArtifacts(ctx context.Context, targets []buildTarget, skipGen
logSuccessfulBuild(target.fullName, rel)
}

if !skipGenerate {
shouldHoist := false
for _, target := range targets {
if target.fullName == "//:go_path" {
shouldHoist = true
}
}
if shouldHoist {
if err := d.hoistGeneratedCode(ctx, workspace, bazelBin); err != nil {
return err
}
Expand Down Expand Up @@ -309,10 +315,6 @@ func (d *dev) getBasicBuildArgs(
args = append(args, aliased)
buildTargets = append(buildTargets, buildTarget{fullName: aliased, isGoBinary: true})
}
// If we're hoisting generated code, we also want to build //:go_path.
if !skipGenerate {
args = append(args, "//:go_path")
}

// Add --config=with_ui iff we're building a target that needs it.
for _, target := range buildTargets {
Expand All @@ -321,6 +323,21 @@ func (d *dev) getBasicBuildArgs(
break
}
}
shouldSkipGenerate := true
for _, target := range buildTargets {
if strings.Contains(target.fullName, "//pkg/cmd/cockroach") {
shouldSkipGenerate = false
break
}
}
if shouldSkipGenerate {
skipGenerate = true
}
// If we're hoisting generated code, we also want to build //:go_path.
if !skipGenerate {
args = append(args, "//:go_path")
buildTargets = append(buildTargets, buildTarget{fullName: "//:go_path"})
}
if shouldBuildWithTestConfig {
args = append(args, "--config=test")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ func TestUnimplementedSyntax(t *testing.T) {
{`SET CONSTRAINTS foo`, 0, `set constraints`, ``},
{`SET foo FROM CURRENT`, 0, `set from current`, ``},

{`CREATE MATERIALIZED VIEW a AS SELECT 1 WITH NO DATA`, 74083, ``, ``},

{`CREATE TABLE a(x INT[][])`, 32552, ``, ``},
{`CREATE TABLE a(x INT[1][2])`, 32552, ``, ``},
{`CREATE TABLE a(x INT ARRAY[1][2])`, 32552, ``, ``},
Expand Down
20 changes: 17 additions & 3 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ func (u *sqlSymUnion) setVar() *tree.SetVar {
%type <[]tree.RangePartition> range_partitions
%type <empty> opt_all_clause
%type <empty> opt_privileges_clause
%type <bool> distinct_clause
%type <bool> distinct_clause opt_with_data
%type <tree.DistinctOn> distinct_on_clause
%type <tree.NameList> opt_column_list insert_column_list opt_stats_columns query_stats_cols
%type <tree.OrderBy> sort_clause single_sort_clause opt_sort_clause
Expand Down Expand Up @@ -7634,7 +7634,7 @@ create_view_stmt:
Replace: false,
}
}
| CREATE MATERIALIZED VIEW view_name opt_column_list AS select_stmt
| CREATE MATERIALIZED VIEW view_name opt_column_list AS select_stmt opt_with_data
{
name := $4.unresolvedObjectName().ToTableName()
$$.val = &tree.CreateView{
Expand All @@ -7644,7 +7644,7 @@ create_view_stmt:
Materialized: true,
}
}
| CREATE MATERIALIZED VIEW IF NOT EXISTS view_name opt_column_list AS select_stmt
| CREATE MATERIALIZED VIEW IF NOT EXISTS view_name opt_column_list AS select_stmt opt_with_data
{
name := $7.unresolvedObjectName().ToTableName()
$$.val = &tree.CreateView{
Expand All @@ -7657,6 +7657,20 @@ create_view_stmt:
}
| CREATE opt_temp opt_view_recursive VIEW error // SHOW HELP: CREATE VIEW

opt_with_data:
WITH NO DATA error
{
return unimplementedWithIssue(sqllex, 74083)
}
| WITH DATA
{
$$.val = true
}
| /* EMPTY */
{
$$.val = true
}

role_option:
CREATEROLE
{
Expand Down
16 changes: 16 additions & 0 deletions pkg/sql/parser/testdata/create_view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ CREATE MATERIALIZED VIEW a AS SELECT (*) FROM b -- fully parenthesized
CREATE MATERIALIZED VIEW a AS SELECT * FROM b -- literals removed
CREATE MATERIALIZED VIEW _ AS SELECT * FROM _ -- identifiers removed

parse
CREATE MATERIALIZED VIEW a AS SELECT * FROM b WITH DATA
----
CREATE MATERIALIZED VIEW a AS SELECT * FROM b -- normalized!
CREATE MATERIALIZED VIEW a AS SELECT (*) FROM b -- fully parenthesized
CREATE MATERIALIZED VIEW a AS SELECT * FROM b -- literals removed
CREATE MATERIALIZED VIEW _ AS SELECT * FROM _ -- identifiers removed

parse
CREATE MATERIALIZED VIEW IF NOT EXISTS a AS SELECT * FROM b
----
Expand All @@ -112,6 +120,14 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS a AS SELECT (*) FROM b -- fully parenthes
CREATE MATERIALIZED VIEW IF NOT EXISTS a AS SELECT * FROM b -- literals removed
CREATE MATERIALIZED VIEW IF NOT EXISTS _ AS SELECT * FROM _ -- identifiers removed

parse
CREATE MATERIALIZED VIEW IF NOT EXISTS a AS SELECT * FROM b WITH DATA
----
CREATE MATERIALIZED VIEW IF NOT EXISTS a AS SELECT * FROM b -- normalized!
CREATE MATERIALIZED VIEW IF NOT EXISTS a AS SELECT (*) FROM b -- fully parenthesized
CREATE MATERIALIZED VIEW IF NOT EXISTS a AS SELECT * FROM b -- literals removed
CREATE MATERIALIZED VIEW IF NOT EXISTS _ AS SELECT * FROM _ -- identifiers removed

parse
REFRESH MATERIALIZED VIEW a.b
----
Expand Down

0 comments on commit 10b94f6

Please sign in to comment.