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

release-23.1: sql: fix formatting of export and changefeed #108314

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

annrpom
Copy link
Contributor

@annrpom annrpom commented Aug 7, 2023

Informs: #99185

This commit cherry-picked changes from #107892.

Release note: None
Fixes: #108254 and #108233 (partially)
Release justification: fixes bug with random syntax generation

@blathers-crl
Copy link

blathers-crl bot commented Aug 7, 2023

Thanks for opening a backport.

Please check the backport criteria before merging:

  • Patches should only be created for serious issues or test-only changes.
  • Patches should not break backwards-compatibility.
  • Patches should change as little code as possible.
  • Patches should not change on-disk formats or node communication protocols.
  • Patches should not add new functionality.
  • Patches must not add, edit, or otherwise modify cluster versions; or add version gates.
If some of the basic criteria cannot be satisfied, ensure that the exceptional criteria are satisfied within.
  • There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
  • The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
  • New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters.
  • The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.

Add a brief release justification to the body of your PR to justify this backport.

Some other things to consider:

  • What did we do to ensure that a user that doesn’t know & care about this backport, has no idea that it happened?
  • Will this work in a cluster of mixed patch versions? Did we test that?
  • If a user upgrades a patch version, uses this feature, and then downgrades, what happens?

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Informs: cockroachdb#99185

This commit cherry-picked changes from cockroachdb#107892.

Release note: None
Fixes: cockroachdb#108254 and cockroachdb#108233 (partially)
Release justification: fixes bug with random syntax generation
@annrpom annrpom force-pushed the backport23.1-107892 branch from 476a8d1 to 7ed0bda Compare August 7, 2023 19:52
@annrpom annrpom requested a review from a team August 7, 2023 20:02
@annrpom annrpom marked this pull request as ready for review August 8, 2023 14:01
@annrpom annrpom requested review from a team as code owners August 8, 2023 14:01
@annrpom annrpom requested review from shermanCRL and rafiss and removed request for a team August 8, 2023 14:01
@annrpom annrpom added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Aug 8, 2023
@shermanCRL shermanCRL requested review from jayshrivastava and removed request for shermanCRL August 8, 2023 15:52
Copy link
Contributor

@jayshrivastava jayshrivastava left a comment

Choose a reason for hiding this comment

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

LGTM! The change itself looks good to me, but can you explain how it fixes the randomized test? Just for my own understanding.

@miretskiy
Copy link
Contributor

I'm also curious... We always supported WITH OPTIONS, but the options was ... well, optional. Is this now recommended to use? I'm not too sure if this raises to the backport level though. Do we need it?

@annrpom
Copy link
Contributor Author

annrpom commented Aug 8, 2023

@jayshrivastava from my understanding, TestRandomSyntaxGeneration has failed before with the same pattern - this is a very specific case due to the fact that a BUCKET_COUNT option that is not wrapped with OPTIONS (...) gets converted to the other WITH BUCKET_COUNT syntax (mentioned #107185 and demonstrated in the lexer:

case WITH:
switch nextToken.id {
case TIME, ORDINALITY, BUCKET_COUNT:
lval.id = WITH_LA
}
). thus, CREATE CHANGEFEED ... WITH_LA bucket_count; is actually the statement that is being parsed - causing the syntax error that we see:

sql="CREATE CHANGEFEED FOR SURVIVE . ident . FAMILY , ISERROR INTO PLACEHOLDER WITH OPTIONS ( BUCKET_COUNT )", formattedSQL="CREATE CHANGEFEED FOR TABLE survive.ident.family, TABLE \"iserror\" INTO 'placeholder' WITH bucket_count": at or near "with": syntax error

@miretskiy that's a good question - WITH and WITH OPTIONS both should be supported (except in the special case of bucket_count), but (edit: some of) the tests don't really reflect that... I will be adding the WITH tests back in with a new PR

@rafiss
Copy link
Collaborator

rafiss commented Aug 8, 2023

I'm not too sure if this raises to the backport level though. Do we need it?

Yes, otherwise #108254 will continue failing. In general, it's a good idea to make sure any statement can roundtrip format->parse->format. In some cases, that is actually critical.

@jayshrivastava
Copy link
Contributor

#108254 fails because this SQL

CREATE CHANGEFEED FOR SURVIVE . ident . FAMILY , ISERROR INTO PLACEHOLDER WITH OPTIONS ( BUCKET_COUNT )

Formats to

CREATE CHANGEFEED FOR TABLE survive.ident.family, TABLE \"iserror\" INTO 'placeholder' WITH bucket_count

The latter cannot be parsed because it uses a reserved keyword bucket_count. This change fixes it by making sure we format KV options like this, so it can be parsed.

CREATE CHANGEFEED FOR TABLE survive.ident.family, TABLE \"iserror\" INTO 'placeholder' WITH (bucket_count)

I think the real problem is that both statements (with and without brackets) should be equivalent, but they are not. One can be parsed and the other cannot.

@jayshrivastava
Copy link
Contributor

Actually on second thought, maybe they aren't equivalent. Using brackets allows you to pass in reserved keywords and missing brackets does not let you pass them in.

Nevertheless, I think it's better to format the statement using brackets because we would want formatting to produce the most a parseable output.

@annrpom annrpom merged commit 0e8ff82 into cockroachdb:release-23.1 Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants