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

[Bug] BigQuery.upsert fails depending on table's column order #1023

Open
Jason94 opened this issue Mar 21, 2024 · 0 comments
Open

[Bug] BigQuery.upsert fails depending on table's column order #1023

Jason94 opened this issue Mar 21, 2024 · 0 comments
Labels
bug Impact - something is currently broken in Parsons and needs to be fixed

Comments

@Jason94
Copy link
Collaborator

Jason94 commented Mar 21, 2024

GoogleBigQuery.upsert() fails if the columns are ordered differently in the database's table than in the Parsons table.

If the mismatched columns are the same data type, it will silently insert the data into the wrong columns. If the mismatched columns are different data types, then the upsert will fail with an error.

To Reproduce

This script will throw an error when it attempts the upsert because columns a and b have different types:

from parsons import Table
from parsons.google.google_bigquery import GoogleBigQuery

def main():
    bq = GoogleBigQuery()
    table_name = "test.upsert_test_data"

    data = Table([{"a": 1, "b": "abc"}, {"a": 3, "b": "def"}])

    bq.copy(data, table_name, if_exists="drop")

    data2 = Table(
        [
            {"b": "xyz", "a": 1},
            {"b": "zyx", "a": 5},
        ]
    )

    bq.upsert(data2, table_name, "a")

    print(bq.query(f"SELECT * FROM {table_name}"))


if __name__ == "__main__":
    main()

Your Environment

  • Version of Parsons used (if you know): main branch as of 3/21/2024
  • Operating System and version (desktop or mobile): Windows 10
@Jason94 Jason94 added the bug Impact - something is currently broken in Parsons and needs to be fixed label Mar 21, 2024
@Jason94 Jason94 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2024
@Jason94 Jason94 reopened this Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Impact - something is currently broken in Parsons and needs to be fixed
Projects
None yet
Development

No branches or pull requests

1 participant