Skip to content

Commit

Permalink
created array_distinct function to easily get only the unique values …
Browse files Browse the repository at this point in the history
…from an array
  • Loading branch information
cleentfaar committed Mar 1, 2024
1 parent f81f244 commit d02df49
Showing 1 changed file with 21 additions and 0 deletions.
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<STRING>\"}"
routine_id = "array_distinct${local.branch_suffix_underscore_edition}"
routine_type = "SCALAR_FUNCTION"

arguments {
name = "value"
argument_kind = "FIXED_TYPE"
data_type = "{\"typeKind\" : \"ARRAY<STRING>\"}"
}
}

0 comments on commit d02df49

Please sign in to comment.