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: remove extra type hint from SHOW CREATE VIEW #95679

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

e-mbrown
Copy link
Contributor

@e-mbrown e-mbrown commented Jan 23, 2023

Resolves: #87886

Views created with user provided type hints were given
extra type annotations. The format functions for AnnotateTypeExpr
and Array were both annotating the expression. This commit alters
the format function of AnnotateTypeExpr so it doesnt duplicate
annotations for arrays.

Release note: None

@e-mbrown e-mbrown requested a review from a team January 23, 2023 15:11
@e-mbrown e-mbrown requested a review from a team as a code owner January 23, 2023 15:11
@cockroach-teamcity
Copy link
Member

This change is Reviewable

table_name create_statement
t2 CREATE VIEW public.t2 (
"array"
) AS SELECT ARRAY[1:::INT8, 2:::INT8, 3:::INT8]::INT8[]:::INT8[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this still has an extra :::INT8[] type annotation at the end. (and same for t1 above this)

@@ -885,7 +885,7 @@ func (node *Array) Format(ctx *FmtCtx) {
// UNKNOWN[], since that's not a valid annotation.
if ctx.HasFlags(FmtParsable) && node.typ != nil {
if node.typ.ArrayContents().Family() != types.UnknownFamily {
ctx.WriteString(":::")
ctx.WriteString("::")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm wondering if what we need is to keep track of whether there already was a type annotation wrapping the Array expr. or alternatively, update AnnotateTypeExpr.Format so it doesn't print the annotation if the inner expr already is going to

@e-mbrown e-mbrown force-pushed the eb/showcreate branch 2 times, most recently from 271fb92 to 2c9c878 Compare February 6, 2023 19:24
Copy link
Contributor Author

@e-mbrown e-mbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)


pkg/sql/sem/tree/expr.go line 888 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i'm wondering if what we need is to keep track of whether there already was a type annotation wrapping the Array expr. or alternatively, update AnnotateTypeExpr.Format so it doesn't print the annotation if the inner expr already is going to

Done.


pkg/sql/logictest/testdata/logic_test/views line 162 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

it looks like this still has an extra :::INT8[] type annotation at the end. (and same for t1 above this)

Done.

@e-mbrown e-mbrown requested a review from rafiss February 6, 2023 19:45
@@ -884,7 +884,7 @@ func (node *Array) Format(ctx *FmtCtx) {
// If the array has a type, add an annotation. Don't add it if the type is
// UNKNOWN[], since that's not a valid annotation.
if ctx.HasFlags(FmtParsable) && node.typ != nil {
if node.typ.ArrayContents().Family() != types.UnknownFamily {
if node.typ.ArrayContents().Family() != types.UnknownFamily && node.typeAnnotation.typ == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to summarize what we discussed offline: node.typ and node.typeAnnotation.typ refer to the same thing, so this change doesn't have the intended affect.

perhaps instead our approach should be to update formatViewQueryForDisplay to detect when an annotation would be duplicated, and prevent that.

@e-mbrown e-mbrown force-pushed the eb/showcreate branch 2 times, most recently from 329be31 to 2d06063 Compare February 21, 2023 16:37
@e-mbrown e-mbrown requested a review from rafiss February 21, 2023 18:09
Views created with user provided type hints were given
extra type annotations. The format functions for `AnnotateTypeExpr`
and `Array` were both annotating the expression. This commit alters
the format function of `AnnotateTypeExpr` so it doesnt duplicate
annotations for arrays.

Release note: None
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@e-mbrown
Copy link
Contributor Author

Woo!

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Feb 22, 2023

Build succeeded:

@craig craig bot merged commit 2431b4b into cockroachdb:master Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SHOW CREATE VIEW adds extra type hint for empty array constructor
3 participants