Skip to content

Commit

Permalink
Support RECORD (#59)
Browse files Browse the repository at this point in the history
* Support `RECORD`

Signed-off-by: Yu Ishikawa <[email protected]>

* Improve the test case

Signed-off-by: Yu Ishikawa <[email protected]>

---------

Signed-off-by: Yu Ishikawa <[email protected]>
  • Loading branch information
yu-iskw authored Nov 8, 2023
1 parent 391813d commit 1116f04
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
"level": "restricted",
},
},
},
"dummy_record": {
"data_type": "RECORD",
"meta": {
"data_privacy": {
"level": "internal",
},
},
}
},
where="1 = 1",
Expand Down Expand Up @@ -141,6 +149,7 @@ WITH privacy_protected_model AS (
) AS `consents`,
dummy_column AS `dummy_column`,
dummy_array AS `dummy_array`,
dummy_record AS `dummy_record`,
FROM
{{ ref('test_restricted_users') }} AS __original_table
WHERE
Expand Down
2 changes: 1 addition & 1 deletion macros/pseudonymization/sha256.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- macro bigquery__sha256(expression, data_type=none) -%}
{% set secured_expression = "SHA256(CAST({} AS STRING))".format(expression)%}

{% if data_type | upper == "ARRAY" %}
{% if data_type | upper in ["ARRAY", "RECORD"] %}
{% set secured_expression = "ARRAY(SELECT SHA256(CAST(e AS STRING)) FROM UNNEST({}) AS e)".format(expression)%}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion macros/pseudonymization/sha512.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- macro bigquery__sha512(expression, data_type=none) -%}
{% set secured_expression = "SHA512(CAST({} AS STRING))".format(expression)%}

{% if data_type | upper == "ARRAY" %}
{% if data_type | upper in ["ARRAY", "RECORD"] %}
{% set secured_expression = "ARRAY(SELECT SHA512(CAST(e AS STRING)) FROM UNNEST({}) AS e)".format(expression)%}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion macros/pseudonymization/udf_hash.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{%- macro bigquery__udf_hash(expression, udf_function, data_type=none) -%}
{% set secured_expression = "{}(CAST({} AS STRING))".format(udf_function, expression)%}

{% if data_type | upper == "ARRAY" %}
{% if data_type | upper in ["ARRAY", "RECORD"] %}
{% set secured_expression = "ARRAY(SELECT {}(CAST(e AS STRING)) FROM UNNEST({}) AS e)".format(udf_function, expression)%}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% set is_array = false %}
{% if restructured_column.original_info is defined
and restructured_column.original_info.data_type is defined
and restructured_column.original_info.data_type == "ARRAY" %}
and restructured_column.original_info.data_type in ["ARRAY", "RECORD"] %}
{% set is_array = true %}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% set is_array = false %}
{% if restructured_column.original_info is defined
and restructured_column.original_info.data_type is defined
and restructured_column.original_info.data_type == "ARRAY" %}
and restructured_column.original_info.data_type in ["ARRAY", "RECORD"] %}
{% set is_array = true %}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% if restructured_column.original_info is defined
and restructured_column.original_info is mapping
and restructured_column.original_info.data_type is defined
and restructured_column.original_info.data_type == "ARRAY" %}
and restructured_column.original_info.data_type in ["ARRAY", "RECORD"] %}
{% set is_array = true %}
{% endif %}

Expand Down

0 comments on commit 1116f04

Please sign in to comment.