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: add notice for Alter TYPE ADD VALUE IF NOT EXIST command #52534
sql: add notice for Alter TYPE ADD VALUE IF NOT EXIST command #52534
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:
I have added a few people who may be able to assist in reviewing: 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
pkg/sql/sqlbase/type_desc.go
Outdated
@@ -268,7 +269,7 @@ func (desc *MutableTypeDescriptor) AddEnumValue(node *tree.AlterTypeAddValue) er | |||
} | |||
if found { | |||
if node.IfNotExists { | |||
return nil | |||
return pgnotice.Newf("enum label %q already exists, skipping", node.NewVal) |
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.
We don't want to return an error here. Instead, we want to use p.SendClientNotice
and return nil. Also add a test in pkg/sql/logictest/testdata/logic_test/notice
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.
ohh... thanks for your review @rohany . i have noticed that sqlbase package is getting removed here #52519. Also planner struct is not accessible in sqlbase package. So using p.SendClientNotice directly doesn't seems feasible to me.
I have just started with this project and i am reading architecture docs in details. So your guidelines will be really helpful for me as a beginner to opensource world as i really want to learn and contribute to this project.
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 have noticed that sqlbase package is getting removed here #52519.
This isn't a worry -- all of the code will still be here, the package is just getting split up into smaller packages.
Also planner struct is not accessible in sqlbase package. So using p.SendClientNotice directly doesn't seems feasible to me.
There are a couple options here:
- return an error here, and then catch it and convert it into a notice in the statement execution path
- pass a closure into this function that does the work of sending a notice
- In the statement (alter_type.go) just check if the enum value exists or not. Then this function can just error if it finds the value already present in the enum.
Overall, I think that the third is the cleanest
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. |
@@ -154,7 +154,7 @@ ALTER TYPE build ADD VALUE 'a' BEFORE 'b' | |||
statement error pq: \"b\" is not an existing enum label | |||
ALTER TYPE build ADD VALUE 'a' AFTER 'b' | |||
|
|||
statement ok | |||
statement error pq: enum label \"c\" already exists, skipping |
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.
Please look at the test I mentioned. It isn't correct to return an error here! The idea of a notice is that the statement executes successfully, but just prints out a notice to the user.
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.
this is pushed before i saw your reviews, i have submitted the changes as requested by you. I have added logic test in notice file and sent a client notice in alter_type.go file.
pkg/sql/sqlbase/type_desc.go
Outdated
@@ -268,7 +269,7 @@ func (desc *MutableTypeDescriptor) AddEnumValue(node *tree.AlterTypeAddValue) er | |||
} | |||
if found { | |||
if node.IfNotExists { | |||
return nil | |||
return pgnotice.Newf("enum label %q already exists, skipping", node.NewVal) |
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 have noticed that sqlbase package is getting removed here #52519.
This isn't a worry -- all of the code will still be here, the package is just getting split up into smaller packages.
Also planner struct is not accessible in sqlbase package. So using p.SendClientNotice directly doesn't seems feasible to me.
There are a couple options here:
- return an error here, and then catch it and convert it into a notice in the statement execution path
- pass a closure into this function that does the work of sending a notice
- In the statement (alter_type.go) just check if the enum value exists or not. Then this function can just error if it finds the value already present in the enum.
Overall, I think that the third is the cleanest
5e6d5d0
to
e61ff04
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. |
e61ff04
to
d8f17e1
Compare
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 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.
Looking good! Small comments now.
pkg/sql/alter_type.go
Outdated
found := false | ||
for _, member := range n.desc.EnumMembers { | ||
if member.LogicalRepresentation == node.NewVal { | ||
found = true |
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.
Not sure why it wasn't written this way in the first place, but we don't need a new variable and a break -- just do the notice/error return in here.
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.
my bad, i have updated this now.
@@ -255,24 +255,6 @@ func (desc *MutableTypeDescriptor) IsNew() bool { | |||
|
|||
// AddEnumValue adds an enum member to the type. | |||
func (desc *MutableTypeDescriptor) AddEnumValue(node *tree.AlterTypeAddValue) error { |
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.
Update the comment here now to say that "AddEnumValue assumes that the type is an enum, and that the new value doesn't exist already in the enum"
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.
updated comment, i will make sure to do such descriptive code comments in future contributions.
d8f17e1
to
f7ff5c4
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.
Some more nits.
Please update your commit title and message with the following:
- The commit title should be prefaced with the packages touched (i.e
sql: add notice for ALTER TYPE ADD VALUE ...
) - The release note should also be a properly formatted sentence, and should use the correct release note tag -- in this case, it would be
sql change
, not justsql
pkg/sql/alter_type.go
Outdated
return nil | ||
} | ||
return pgerror.Newf(pgcode.DuplicateObject, "enum label %q already exists", node.NewVal) | ||
|
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.
remove this newline
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.
fixed
pkg/sql/sqlbase/type_desc.go
Outdated
@@ -253,26 +253,8 @@ func (desc *MutableTypeDescriptor) IsNew() bool { | |||
return desc.ClusterVersion == nil | |||
} | |||
|
|||
// AddEnumValue adds an enum member to the type. | |||
//AddEnumValue assumes that the type is an enum, and that the new value doesn't exist already in the enum |
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.
make sure that your comment lines don't exceed 80 characters, and are full sentences (with a period at the end). You also must add a space after the //
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.
fixed
f7ff5c4
to
f033923
Compare
@@ -253,26 +253,9 @@ func (desc *MutableTypeDescriptor) IsNew() bool { | |||
return desc.ClusterVersion == nil | |||
} | |||
|
|||
// AddEnumValue adds an enum member to the type. | |||
// AddEnumValue assumes that the type is an enum, and that the new value | |||
// doesn't exist already in the enum. |
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.
Last nit -- don't also remove the comment that actually tells what the function does!
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.
fixed
Release note (sql change): Show notice to user when user tries to add value which already exists in enum.
f033923
to
98e7deb
Compare
Thanks for the contribution! Merging. bors r=rohany |
Build succeeded: |
Fixes: #52327
Added a notice message similar to postgres if user tries to add a value in enum which already exists using IF NOT EXIST command.
However, I noticed similar behaviour in other command like ALTER TABLE command. Altering existing table with if not exist
command doesn't shows any notice.
Release note (sql change): Show notice to user when user tries to add value which already exists in enum .