Skip to content

BigQuery: Add support for BEGIN #1718

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

Merged
merged 1 commit into from
Feb 24, 2025
Merged

Conversation

iffyio
Copy link
Contributor

@iffyio iffyio commented Feb 8, 2025

Adds support for the BEGIN ... EXCEPTION ... END syntax in BigQuery:

BEGIN
  SELECT 1;
  SELECT 2;
EXCEPTION WHEN ERROR THEN
  SELECT 3;
  SELECT 4;
END

https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend

@iffyio iffyio force-pushed the bq-begin-exception branch from 46f28fa to f3c803d Compare February 8, 2025 16:53
Copy link
Contributor

@yoavcloud yoavcloud left a comment

Choose a reason for hiding this comment

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

LGTM @iffyio. I recently added support for something similar in MS-SQL, but only for the case where there's a semi-colon after the BEGIN/END TRY/CATCH keywords. I think your approach of Vec<Statement> is better, and I'll align to that.

@iffyio iffyio force-pushed the bq-begin-exception branch from f3c803d to f018574 Compare February 9, 2025 08:49
@iffyio iffyio requested a review from alamb February 17, 2025 06:36
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @iffyio and @yoavcloud -- looks like a nice improvement to me!

src/ast/mod.rs Outdated
/// END;
/// ```
/// <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
has_exception_when_clause: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wondered if this field redundant with when exception_statements is empty? However, given the test cases below, it seems it is possible to have a EXCEPTION WHEN ERROR THEN END (without any statements) so distinguishing is necessary

BTW another more Rusty way might be to represent this as

        exception_statements: Option<Vec<Statement>>,

I don't feel strongly about this however

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think that makes sense, I initially figured to use an explicit flag in case it was possible to have exception statements with a different syntax but probably no need to do that unless necessary, will update to use an option!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think using the somewhat akward Option<Vec<..>> would allow the different syntax.

I can help if that would be good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! updated to use an Option

Adds support for the `BEGIN ... EXCEPTION ... END` syntax
in BigQuery:

```sql
BEGIN
  SELECT 1;
  SELECT 2;
EXCEPTION WHEN ERROR THEN
  SELECT 3;
  SELECT 4;
END
```

https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend
@iffyio iffyio force-pushed the bq-begin-exception branch from f018574 to 798f070 Compare February 24, 2025 07:31
@iffyio iffyio merged commit aab12ad into apache:main Feb 24, 2025
9 checks passed
@iffyio iffyio deleted the bq-begin-exception branch February 24, 2025 07:34
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks very nice @iffyio

// since display_separated doesn't handle that case.
write!(f, ";")?;
}
if let Some(exception_statements) = exception_statements {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

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.

3 participants