question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have compare_columns support BigQuery Arrays for equality test

See original GitHub issue

Describe the feature

We would like to use the db_utils compare_columns to be able to check BigQuery clolumns with arrays in tests. At the moment, it does not appear to be supported.

Describe alternatives you’ve considered

Alternatives are to not use dbt to test for equality of arrays, and instead to test it via API call and comparing the results in Python, which requires extra work.

Additional context

BigQuery arrays are our use case, but I imagine this problem for any db with arrays and the solution might be generalizable to others.

Who will this benefit?

Any who writes tests and has databases with arrays.

Are you interested in contributing this feature?

Sure, I’d love to take a crack at this if someone points me in the right direction. I see the code here https://github.com/dbt-labs/dbt-utils/blob/37199d3901a97e813899dc25c1f72601714c2c3c/macros/generic_tests/equality.sql. It looks pretty straightforward, just have to support either user supplying a flag or maybe the datatype of the column being an array is inferred. Once there, then it’s a matter of just flattening the column/table (in BigQuery, with UNNEST, other dialects, not sure, hence, maybe this is a BQ specific solution?)

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonqngcommented, Aug 29, 2022

@joellabes Thanks for the pointers. I’ll take a crack at it later this week. I’ll probably need your help with tests and/or other polish, but hopefully I can at least get a prototype PR working for you all to look at.

0reactions
jasonqngcommented, Oct 3, 2022

@pishposh Haven’t had a chance to do so, and yeah, handling structs would be amazing too. Go for it! Look forward to helping to test and review if helpful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Work with arrays | BigQuery - Google Cloud
In Google Standard SQL for BigQuery, an array is an ordered list consisting of zero or more values of the same data type....
Read more >
How do you compare two arrays in BigQuery? - Stack Overflow
I am trying to join two tables that each have an array column like the following. SELECT a.id ...
Read more >
Arrays Explained | BigQuery Syntax and Examples - Count
Arrays are ordered lists in BigQuery. They are very powerful once you know how to use them, and can help with: Transforming non-normalized...
Read more >
How to work with Arrays and Structs in Google BigQuery
Arrays in BigQuery, like in any other language, are a collection of elements of the same data type. For example, this is what...
Read more >
BigQuery Array Simplified: 5 Key Functions and Examples
Since 2016, Google has enabled its users to run queries using Standard SQL. Standard SQL supports new data types: BigQuery Array and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found