You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
quick_are_queries_identical macros is not working as expected when there is a empty query result/table is involved.
Steps to reproduce
Scenario 1:
when both the query_a and query_b returns no result(empty output) then the quick_are_queries_identical returns false but ideally it should return true since both the query returns empty result.
Expected results True
Actual results False
{% set old_query %}
select
*
from `bigquery-public-data.faa.us_airports` LIMIT 0
{% endset %}
{% set new_query %}
select
*
from `bigquery-public-data.faa.us_airports` LIMIT 0
{% endset %}
{{
audit_helper.quick_are_queries_identical(
old_query,
new_query,
columns=['object_id','global_id','faa_identifier','name','latitude','longitude','airport_geom','elevation','icao_id','airport_type','service_city','state_abbreviation','country','oper_status','airport_use','iap_exists','dod_hiflip','far_91','far_93','mil_code','airspace_analysis','us_high','us_low','ak_high','ak_low','us_area','pacific']
)
}}
Screenshots and log output
Scenario 2:
when one of the query_a and query_b returns no result(empty output) then the quick_are_queries_identical returns true but ideally it should return false since one of the query returns value and other return empty result.
Expected results False
Actual results True
{% set old_query %}
select
*
from `bigquery-public-data.faa.us_airports`
{% endset %}
{% set new_query %}
select
*
from `bigquery-public-data.faa.us_airports` LIMIT 0
{% endset %}
{{
audit_helper.quick_are_queries_identical(
old_query,
new_query,
columns=['object_id','global_id','faa_identifier','name','latitude','longitude','airport_geom','elevation','icao_id','airport_type','service_city','state_abbreviation','country','oper_status','airport_use','iap_exists','dod_hiflip','far_91','far_93','mil_code','airspace_analysis','us_high','us_low','ak_high','ak_low','us_area','pacific']
)
}}
I believe the reason this is happening is because bit_xor of no result will be NULL and when we do count(distinct hash_result) the NULL value won't be taken into account.
select count(distinct hash_result) = 1 as are_tables_identical
from (
select bit_xor(farm_fingerprint(to_json_string(query_a))) as hash_result
from query_a
union all
select bit_xor(farm_fingerprint(to_json_string(query_b))) as hash_result
from query_b
) as hashes
to handle this we can add IFNULL() to the hash_result
Are you interested in contributing the fix?
Yes!
The text was updated successfully, but these errors were encountered:
mahilaeshwar
changed the title
quick_are_queries_identical macros is not working as expected when there is a empty query result/table is involvedquick_are_queries_identical macros is not working as expected when there is a empty query result/table is involved
Dec 21, 2024
Describe the bug
quick_are_queries_identical
macros is not working as expected when there is a empty query result/table is involved.Steps to reproduce
Scenario 1:
when both the query_a and query_b returns no result(empty output) then the quick_are_queries_identical returns false but ideally it should return true since both the query returns empty result.
Expected results True
Actual results False
Screenshots and log output
Scenario 2:
when one of the query_a and query_b returns no result(empty output) then the quick_are_queries_identical returns true but ideally it should return false since one of the query returns value and other return empty result.
Expected results False
Actual results True
Screenshots and log output
System information
The contents of your
packages.yml
file:Which database are you using dbt with?
The output of
dbt --version
:Additional context
I believe the reason this is happening is because bit_xor of no result will be NULL and when we do count(distinct hash_result) the NULL value won't be taken into account.
to handle this we can add IFNULL() to the hash_result
Are you interested in contributing the fix?
Yes!
The text was updated successfully, but these errors were encountered: