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

Implement statement hints in DMLs #267

Conversation

apstndb
Copy link
Contributor

@apstndb apstndb commented Jan 12, 2025

This PR implements statement hints in DMLs.

Note

  • There is no breaking changes, but this PR introduces some important changes
    • Introduces (*Parser).lookaheadTokenAfterOptionalHint() in parseStatement()
    • Now BadDML and BadStatement have Hint.
    • some parse methods have their *Internal methods. They parses after valid hints.
    • parseUpdate(), parseInsert(), parseDelete() have hint *ast.Hint argument.

Related issues

@apstndb apstndb marked this pull request as ready for review January 12, 2025 05:23
@makenowjust
Copy link
Collaborator

IMHO, lookaheadSomething methods should be safe; that is, they should not cause panic. Furthermore, we should not add lookaheadSomething if it is not necessary.

parser.go Outdated
case p.Token.IsKeywordLike("INSERT") || p.Token.IsKeywordLike("DELETE") || p.Token.IsKeywordLike("UPDATE"):
return p.parseDMLInternal(hint)
case hint != nil:
panic(p.errorfAtToken(&p.Token, "statement hint is only permitted before query or DML, but got: %s", p.Token.Raw))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this error position corresponds to the hint position.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it is fixed. 2c14f63

  • testdata/result/statement/!bad_call_cancel_query_with_hint.sql.txt
  • testdata/result/statement/!bad_call_cancel_query_with_hint_oneline.sql.txt

show example of errors.

@apstndb apstndb requested a review from makenowjust January 12, 2025 14:01
Copy link
Collaborator

@makenowjust makenowjust left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@makenowjust makenowjust merged commit d00c4b7 into cloudspannerecosystem:main Jan 12, 2025
2 checks passed
@apstndb apstndb deleted the feature/support-dml-statement-hints branch January 12, 2025 14:12
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.

Support DML with statements hints
2 participants