Created
May 27, 2016 09:41
-
-
Save sinmetal/381864c8da995a68103cb4f115c7fd16 to your computer and use it in GitHub Desktop.
keyword, arrayを渡して、arrayに含まれる文字を正規表現で探してマッチしたら、マッチした文字列を返すBQのUDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function passthroughExample(row, emit) { | |
var output = []; | |
row.keyword. forEach(function(element, index, array) { | |
var match = row.data.match(element); | |
if (match) { | |
output.push(match[0]); | |
} | |
}) | |
emit({output:output}) | |
} | |
bigquery.defineFunction( | |
'passthrough', // Name of the function exported to SQL | |
['data','keyword'], // Names of input columns | |
[{'name': 'output', 'mode': 'repeated', 'type': 'string'}], | |
passthroughExample // Reference to JavaScript UDF | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment