Skip to content

[Bug]: SpannerChangeStreamsToBigQuery does not support null primary key column values. #831

Open

Description

@rob-pomelo

Related Template(s)

SpannerChangeStreamsToBigQuery

What happened?

In Spanner it is valid to have nullable columns in a primary key.

However, the way the pipeline reads values out of json here it seems like it is extracting null when a column in the primary key is null and passing that value to bigquery.

Bigquery does not seem accept this and throws "This field: XXX is not a record."

This is blocking us rolling out a new feature that relies on a null primary key column.

Full example:

CREATE TABLE TestTable (
    Col1 STRING(40),
    Col2 STRING(40)
) PRIMARY KEY (Col1, Col2)

say we delete row with the following values:

Col1="123",Col2=NULL

keysJson will be:

{\"Col1\":\"123\",\"Col2\":null}

error is:

"location":"col2","message":"This field: col2 is not a record.","reason":"invalid"}],"index":0}}

Beam Version

Newer than 2.46.0

Relevant log output

{"message":{"keysJson":"{\"XXX\":null,\"XXX\":\"XXXX\",\"XXX\":\"XXX\"}","newValuesJson":"{}","commitTimestampSeconds":XXX,"commitTimestampNanos":XXX,"serverTransactionId":"XXX","isLastRecordInTransactionInPartition":false,"recordSequence":"XXX","tableName":"XXX","modType":"DELETE","valueCaptureType":"OLD_AND_NEW_VALUES","numberOfRecordsInTransaction":2,"numberOfPartitionsInTransaction":1,"_metadata_error":{"errors":[{"debugInfo":"","location":"XXX","message":"This field: XXX is not a record.","reason":"invalid"}],"index":0},"_metadata_retry_count":1},"error_message":{"errors":[{"debugInfo":"","location":"XXX","message":"This field: XXX is not a record.","reason":"invalid"}],"index":0}}

Activity

  1. added
    bug
    on Jun 30, 2023
  2. changed the title [-][Bug]: SpannerChangeStreamsToBigQuery does not support null primary key values.[/-] on Jun 30, 2023
  3. rob-pomelo commented on Jun 30, 2023

    @rob-pomelo
    Author

    As a followup i dug deeper and i think the issue is that

    val jsonObject =
          JSONObject("{\"Col1\":null,\"Col2\":\"123\"}")
    val v = j.get("Col1")
    val isNull = v != null  // TRUE, because JSONObject.NULL and not java null
    

    Details on null: https://stleary.github.io/JSON-java/org/json/JSONObject.html#NULL

    This differs from non PK fields where java null is used and works

    I think an explicit isNull check and skip similar to the following would fix it

  4. rob-pomelo commented on Jul 27, 2023

    @rob-pomelo
    Author

    hi any updates here?

  5. github-actions commented on May 20, 2024

    @github-actions
    Contributor

    This issue has been marked as stale due to 180 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the issue at any time. Thank you for your contributions.

  6. rob-pomelo commented on May 20, 2024

    @rob-pomelo
    Author

    this still is not fixed

  7. github-actions commented on Jan 22, 2025

    @github-actions
    Contributor

    This issue has been marked as stale due to 180 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the issue at any time. Thank you for your contributions.

  8. rob-pomelo commented on Jan 22, 2025

    @rob-pomelo
    Author

    still not fixed

  9. github-actions commented on Dec 20, 2025

    @github-actions
    Contributor

    This issue has been marked as stale due to 180 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the issue at any time. Thank you for your contributions.

  10. rob-pomelo commented on Dec 22, 2025

    @rob-pomelo
    Author

    Still not fixed

  11. github-actions commented on Jun 20, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 180 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the issue at any time. Thank you for your contributions.

  12. rob-pomelo commented on Jun 20, 2026

    @rob-pomelo
    Author

    Still not fixed

  13. mvanhorn commented on Oct 23, 2026

    @mvanhorn

    The keys JSON parser represents a JSON null as the JSONObject.NULL sentinel, not Java null. That sentinel is copied onto the BigQuery row, and the typed key getters reject it.

    If a primary-key name is present and JSON-null, key construction appends a null string and skips the typed getter, and the BigQuery row stores Java null instead of the sentinel. Missing keys still fail.

    #4471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions