Skip to content

Instantly share code, notes, and snippets.

@o0h
Created March 22, 2018 03:40
Show Gist options
  • Save o0h/8648aa649390497e7861a0d296c1c920 to your computer and use it in GitHub Desktop.
Save o0h/8648aa649390497e7861a0d296c1c920 to your computer and use it in GitHub Desktop.
event_dimを引数に取ってゴニョゴニョするUDFを書きたいんだけど型不一致で怒られて動かないよ、というお話
CREATE TEMP FUNCTION
hoge(event
STRUCT<
name STRING,
params ARRAY<
STRUCT<
key STRING,
value STRUCT<string_value STRING, int_value INT64, float_value FLOAT64, double_value FLOAT64>
>
>,
timestamp_micros INT64,
previous_timestamp_micors INT64,
date STRING
>
)
RETURNS ARRAY <STRUCT<message string,
path string>>
LANGUAGE js AS """
var result = [];
for (var i in event.params) {
result.push({message: event.params[i].key, path: i});
}
return result;
""";
CREATE TEMP FUNCTION
getErrors(events
ARRAY <
STRUCT<
name STRING,
params ARRAY<
STRUCT<
key STRING,
value STRUCT<string_value STRING, int_value INT64, float_value FLOAT64, double_value FLOAT64>
>
>,
timestamp_micros INT64,
previous_timestamp_micors INT64,
date STRING
>
>
)
RETURNS ARRAY <STRUCT<message string,
path string>>
AS (ARRAY(SELECT STRUCT('ss' AS message, '22' AS path)));
SELECT
user_dim.user_id,
ARRAY(select event_dim[offset(0)]) e0
, hoge(event_dim[offset(0)]) e1
, event_dim
, getErrors(event_dim) e21
--, getErrors(ARRAY(select event_dim[offset(0)])) e2
FROM
`firebase-analytics-sample-data.android_dataset.app_events_20160607`
LIMIT
10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment