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

Created array_distinct function to easily get only the unique values from an array #101

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions terraform/routines.tf
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,24 @@ resource "google_bigquery_routine" "parse_dutch_date" {
) AS STRING)
EOF
}

resource "google_bigquery_routine" "array_distinct" {
dataset_id = local.routines_dataset
definition_body = <<EOF
(
SELECT ARRAY_AGG(a.b)
FROM (SELECT DISTINCT * FROM UNNEST(value) b) a
)
EOF
language = "SQL"
project = local.google_project_id
return_type = "{\"typeKind\": \"ARRAY\", \"arrayElementType\": {\"typeKind\": \"STRING\"}}"
routine_id = "array_distinct${local.branch_suffix_underscore_edition}"
routine_type = "SCALAR_FUNCTION"

arguments {
argument_kind = "FIXED_TYPE"
data_type = "{\"typeKind\": \"ARRAY\", \"arrayElementType\": {\"typeKind\": \"STRING\"}}"
name = "value"
}
}
Loading