Skip to content

Instantly share code, notes, and snippets.

Avatar

Caleb Waldner calebwaldner

  • FUEL Studios
  • Minneapolis
View GitHub Profile
@calebwaldner
calebwaldner / GetMainStringValue
Last active May 12, 2021
A BigQuery function that accepts an array of similar strings and returns the string that occurs most within array.
View GetMainStringValue
CREATE TEMP FUNCTION GetMainStringValue(arr ARRAY<STRING>) RETURNS STRING AS (
ARRAY(
SELECT list FROM (
SELECT list,
count(*) count,
FROM UNNEST(arr) list
GROUP BY list
ORDER BY count DESC
)
)[SAFE_OFFSET(0)]