Skip to content

Add extra validation to SpannerToBigQuery Template#2035

Merged
jrmccluskey merged 3 commits intoGoogleCloudPlatform:mainfrom
jrmccluskey:spannerToBQUpdate
Dec 3, 2024
Merged

Add extra validation to SpannerToBigQuery Template#2035
jrmccluskey merged 3 commits intoGoogleCloudPlatform:mainfrom
jrmccluskey:spannerToBQUpdate

Conversation

@jrmccluskey
Copy link
Copy Markdown
Contributor

The SpannerToBigQuery template wasn't failing with a clear error if the create disposition was not CREATE_NEVER but no BigQuery schema was provided, instead just throwing a vague NullPointerException in the write step. This replaces that exception with an IllegalArgumentException and a clear message before runtime.

@liferoad liferoad requested a review from Abacn November 26, 2024 16:37
@jrmccluskey jrmccluskey added the improvement Making existing code better label Nov 26, 2024
@Abacn
Copy link
Copy Markdown
Contributor

Abacn commented Dec 2, 2024

Sorry for late reply.

just throwing a vague NullPointerException in the write step

Would you mind pointing out the code path for this Exception?

I'm wondering by any chance the original setting could work in some use case, e.g. CREATE_IF_NEEDED + not provide schema + the table actually existed, and with this change it now fails.

@jrmccluskey
Copy link
Copy Markdown
Contributor Author

The failure pops up here:

@Abacn
Copy link
Copy Markdown
Contributor

Abacn commented Dec 3, 2024

The failure pops up here:

~I see, NPE raised in getGcsFileAsString. Currently the error will happen regardless of CREATE_DISPOSITION. We should move .withJsonSchema(getGcsFileAsString(..) into a branch as here ~

if (Write.CreateDisposition.valueOf(options.getCreateDisposition())

then CREATE_NEVER won't cause NPE

never mind, I see it already did in writeToBigQuery method

Copy link
Copy Markdown
Contributor

@Abacn Abacn left a comment

Choose a reason for hiding this comment

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

thank you!

@jrmccluskey jrmccluskey merged commit c37f721 into GoogleCloudPlatform:main Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Making existing code better size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants