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

[Cloud Spanner to BigQuery Template] Fix a NPE when one of the source fields contains a NULL value. #1720

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

an2x
Copy link
Member

@an2x an2x commented Jul 8, 2024

Without this fix, the template expects all the source record fields to have non-NULL values. If there is one, an exception is thrown:

org.apache.beam.sdk.util.UserCodeException:java.lang.NullPointerException: Column field0 contains NULL value.

The reason is that SpannerUtils class tries to call struct.getString/getLong/etc. unconditionally, and these methods throw an exception if the value is null. The fix is to skip such fields and not include them in the JSON object (TableRow) being written to BigQuery. This will also allow a target field in BigQuery to not exist at all if the corresponding source field in Spanner is always null.

… fields contains a NULL value.

Without this fix, the template expects all the source record fields to have non-NULL values. If there is one, an exception is thrown:

org.apache.beam.sdk.util.UserCodeException:java.lang.NullPointerException: Column field0 contains NULL value.

The reason is that SpannerUtils class tries to call struct.getString/getLong/etc. unconditionally, and these methods throw an exception if the value is null. The fix is to skip such fields and not include them in the JSON object (TableRow) being written to BigQuery.
This will also allow a target field in BigQuery to not exist at all if the corresponding source field in Spanner is always null.
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 42.27%. Comparing base (5663044) to head (d14c765).
Report is 77 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1720      +/-   ##
============================================
+ Coverage     41.26%   42.27%   +1.00%     
+ Complexity     3242     3165      -77     
============================================
  Files           771      791      +20     
  Lines         45127    46133    +1006     
  Branches       4819     4935     +116     
============================================
+ Hits          18622    19502     +880     
- Misses        24938    25039     +101     
- Partials       1567     1592      +25     
Components Coverage Δ
spanner-templates 63.62% <ø> (+2.34%) ⬆️
spanner-import-export 64.40% <ø> (-0.03%) ⬇️
spanner-live-forward-migration 74.97% <ø> (+0.83%) ⬆️
spanner-live-reverse-replication 51.44% <ø> (+0.87%) ⬆️
spanner-bulk-migration 83.14% <ø> (+2.50%) ⬆️
Files Coverage Δ
...m/google/cloud/teleport/v2/utils/SpannerUtils.java 57.30% <100.00%> (+0.98%) ⬆️

... and 43 files with indirect coverage changes

Set the default value for the LastName column in the target BQ table, not in the source Spanner table.
@pull-request-size pull-request-size bot added size/L and removed size/M labels Jul 11, 2024
@an2x an2x added the Google LGTM Approval of a pull request to be merged into the repository label Jul 12, 2024
@copybara-service copybara-service bot merged commit ad37e9b into GoogleCloudPlatform:main Jul 12, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Google LGTM Approval of a pull request to be merged into the repository size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants