Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active September 1, 2016 08:55
Show Gist options
  • Save yancya/ee0fc79a10b1ae6a79a57bd55dba3939 to your computer and use it in GitHub Desktop.
Save yancya/ee0fc79a10b1ae6a79a57bd55dba3939 to your computer and use it in GitHub Desktop.
BigQuery StandardSQL の SQL UDF で書いた、文字列配列の包含判定関数
CREATE TEMP FUNCTION connotation(a ARRAY<STRING>, b ARRAY<STRING>)
RETURNS BOOL AS ((SELECT COUNT(b_) = 0
FROM UNNEST(b) AS b_
LEFT OUTER JOIN UNNEST(a) AS a_ ON b_ = a_
WHERE a_ IS NULL));
SELECT connotation(['a', 'b'], ['a']) --> true
, connotation(['a'], ['a', 'b']) --> false
, connotation(['a', 'b', 'c'], ['c']) --> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment