Skip to content

Instantly share code, notes, and snippets.

@sinmetal
Created May 27, 2016 09:41
Show Gist options
  • Save sinmetal/381864c8da995a68103cb4f115c7fd16 to your computer and use it in GitHub Desktop.
Save sinmetal/381864c8da995a68103cb4f115c7fd16 to your computer and use it in GitHub Desktop.
keyword, arrayを渡して、arrayに含まれる文字を正規表現で探してマッチしたら、マッチした文字列を返すBQのUDF
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