-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: support alter column SET VISIBLE and NOT VISIBLE to unhide or hide column #63052
sql: support alter column SET VISIBLE and NOT VISIBLE to unhide or hide column #63052
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
9c384e5
to
07f719c
Compare
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
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! this is looking close, just a couple of places for adding tests.
can you also add the syntax to
cockroach/pkg/sql/parser/parse_test.go
Line 1456 in 6e5dfc4
{`ALTER TABLE a ALTER COLUMN b SET DEFAULT NULL`}, |
@@ -616,6 +616,23 @@ func readPostgresStmt( | |||
if !found { | |||
return colinfo.NewUndefinedColumnError(cmd.Column.String()) | |||
} | |||
case *tree.AlterTableSetVisible: |
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.
can you add a test case for this?
somewhere in
cockroach/pkg/ccl/importccl/import_stmt_test.go
Line 5559 in 6e5dfc4
func TestImportPgDump(t *testing.T) { |
case *tree.AlterTableSetVisible: | ||
col, err := tableDesc.FindActiveOrNewColumnByName(col.ColName()) | ||
if err != nil { | ||
return err |
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.
can you add a logic test that tries to alter a column that does not exist?
CREATE TABLE visible_table (a int primary key) | ||
|
||
statement ok | ||
ALTER TABLE visible_table ALTER COLUMN a SET VISIBLE |
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.
can you add a
query TT
SHOW CREATE TABLE
----
after both ALTER statements, and then run make testccllogic FILES='alter_table_locality' TESTFLAGS='-rewrite'
to make sure they match expectations?
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.
can you also add tests that SET VISIBLE/NOT VISIBLE on already VISIBLE/NOT VISIBLE columns respectively (i.e. check they are idempotent)
pkg/sql/sem/tree/alter_table.go
Outdated
ctx.WriteString(" ALTER COLUMN ") | ||
ctx.FormatNode(&node.Column) | ||
if node.Visible { | ||
ctx.WriteString(" SET VISIBLE") |
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.
there is an extra space here. may i suggest:
ctx.WriteString(" ALTER COLUMN SET ")
ctx.FormatNode(&node.Column)
if !node.Visible {
ctx.WriteString(" NOT ")
}
ctx.WriteString("VISIBLE")
You'll also need to ensure your git comment has a release note, e.g.
|
…de column Release note (sql change): Introduce ALTER TABLE ... ALTER COLUMN SET [VISIBLE|NOT VISIBLE], which marks columns as visible/not visible.
07f719c
to
0e5bf29
Compare
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.
i've fixed them up and merging this!
bors r+
Build succeeded: |
Previously we were unable to make CREATE TABLE AS run on a REGIONAL BY ROW TABLE end up with a table that was (nearly) identical to the original REGIONAL BY ROW table. This was due to the fact that we didn't support setting a column to be NOT VISIBLE. With cockroachdb#63052 we added the support for NOT VISIBLE on ALTER COLUMN which makes getting pretty close to a REGIONAL BY ROW TABLE now possible when starting from CREATE TABLE AS. This commit adds a test case to illustrate this fact. Resolves cockroachdb#62326. Release note: None
Previously we were unable to make CREATE TABLE AS run on a REGIONAL BY ROW TABLE end up with a table that was (nearly) identical to the original REGIONAL BY ROW table. This was due to the fact that we didn't support setting a column to be NOT VISIBLE. With cockroachdb#63052 we added the support for NOT VISIBLE on ALTER COLUMN which makes getting pretty close to a REGIONAL BY ROW TABLE now possible when starting from CREATE TABLE AS. This commit adds a test case to illustrate this fact. Resolves cockroachdb#62326. Release note: None
Previously we were unable to make CREATE TABLE AS run on a REGIONAL BY ROW TABLE end up with a table that was (nearly) identical to the original REGIONAL BY ROW table. This was due to the fact that we didn't support setting a column to be NOT VISIBLE. With cockroachdb#63052 we added the support for NOT VISIBLE on ALTER COLUMN which makes getting pretty close to a REGIONAL BY ROW TABLE now possible when starting from CREATE TABLE AS. This commit adds a test case to illustrate this fact. Resolves cockroachdb#62326. Release note: None
Previously we were unable to make CREATE TABLE AS run on a REGIONAL BY ROW TABLE end up with a table that was (nearly) identical to the original REGIONAL BY ROW table. This was due to the fact that we didn't support setting a column to be NOT VISIBLE. With cockroachdb#63052 we added the support for NOT VISIBLE on ALTER COLUMN which makes getting pretty close to a REGIONAL BY ROW TABLE now possible when starting from CREATE TABLE AS. This commit adds a test case to illustrate this fact. Resolves cockroachdb#62326. Release note: None
Addresses #62892