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: support alter column SET VISIBLE and NOT VISIBLE to unhide or hide column #63052

Merged

Conversation

kurokochin
Copy link
Contributor

Addresses #62892

@kurokochin kurokochin requested review from a team and miretskiy and removed request for a team April 3, 2021 04:34
@cockroach-teamcity
Copy link
Member

cockroach-teamcity commented Apr 3, 2021

CLA assistant check
All committers have signed the CLA.

@blathers-crl
Copy link

blathers-crl bot commented Apr 3, 2021

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:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added the O-community Originated from the community label Apr 3, 2021
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@blathers-crl
Copy link

blathers-crl bot commented Apr 3, 2021

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@kurokochin kurokochin force-pushed the kurokochin/alter-column-set-visible branch from 9c384e5 to 07f719c Compare April 3, 2021 10:43
@blathers-crl
Copy link

blathers-crl bot commented Apr 3, 2021

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@otan otan self-requested a review April 5, 2021 09:37
Copy link
Contributor

@otan otan left a 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

{`ALTER TABLE a ALTER COLUMN b SET DEFAULT NULL`},
(both VISIBLE and NOT VISIBLE variants?)

@@ -616,6 +616,23 @@ func readPostgresStmt(
if !found {
return colinfo.NewUndefinedColumnError(cmd.Column.String())
}
case *tree.AlterTableSetVisible:
Copy link
Contributor

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

func TestImportPgDump(t *testing.T) {
!

case *tree.AlterTableSetVisible:
col, err := tableDesc.FindActiveOrNewColumnByName(col.ColName())
if err != nil {
return err
Copy link
Contributor

@otan otan Apr 5, 2021

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
Copy link
Contributor

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?

Copy link
Contributor

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)

ctx.WriteString(" ALTER COLUMN ")
ctx.FormatNode(&node.Column)
if node.Visible {
ctx.WriteString(" SET VISIBLE")
Copy link
Contributor

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")

@otan
Copy link
Contributor

otan commented Apr 5, 2021

You'll also need to ensure your git comment has a release note, e.g.

Release note (sql change): Add ALTER TABLE ... ALTER COLUMN ...
SET [VISIBLE|NOT VISIBLE], which sets the visibility of the column
on the table. If NOT VISIBLE, these columns will not appears on
`SELECT *` queries.

…de column

Release note (sql change): Introduce ALTER TABLE ... ALTER COLUMN SET
[VISIBLE|NOT VISIBLE], which marks columns as visible/not visible.
@otan otan force-pushed the kurokochin/alter-column-set-visible branch from 07f719c to 0e5bf29 Compare April 8, 2021 22:55
Copy link
Contributor

@otan otan left a 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+

@craig
Copy link
Contributor

craig bot commented Apr 9, 2021

Build succeeded:

@craig craig bot merged commit b8fa9b1 into cockroachdb:master Apr 9, 2021
ajstorm added a commit to ajstorm/cockroach that referenced this pull request Apr 21, 2021
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
@rafiss rafiss added this to the 21.1 milestone Apr 22, 2021
ajstorm added a commit to ajstorm/cockroach that referenced this pull request Apr 22, 2021
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
ajstorm added a commit to ajstorm/cockroach that referenced this pull request May 28, 2021
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
ajstorm added a commit to ajstorm/cockroach that referenced this pull request May 31, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants