Last active
December 19, 2017 02:19
-
-
Save terrierscript/4366195fd7a87ca0b716a2e1d7aeaef6 to your computer and use it in GitHub Desktop.
Treasure Data & (一部Presto) の知っておいて便利だった関数 ref: https://qiita.com/inuscript/items/51b9b3c58260d823739c
This file contains hidden or 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
| SELECT | |
| : | |
| WHERE | |
| -- 1日間のデータなら -1d。一ヶ月なら-30dとか。 | |
| TD_TIME_RANGE(time, | |
| TD_TIME_ADD(TD_SCHEDULED_TIME(), '-1d', 'JST'), | |
| null, | |
| 'JST' | |
| ) |
This file contains hidden or 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
| SELECT * | |
| FROM access | |
| WHERE | |
| url_extract_host(referer) = "google.com" | |
| -- 正規表現でやるとこんな感じ | |
| -- regexp_like(referer, '.*google.com/.*') |
This file contains hidden or 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
| SELECT | |
| TD_PARSE_AGENT(user_agent)['os_family'] | |
| TD_PARSE_AGENT(user_agent)['os_major'] | |
| TD_PARSE_AGENT(user_agent)['os_minor'] | |
| TD_PARSE_AGENT(user_agent)['ua_family'] | |
| TD_PARSE_AGENT(user_agent)['ua_major'] | |
| TD_PARSE_AGENT(user_agent)['ua_minor'] | |
| TD_PARSE_AGENT(user_agent)['device'] | |
| FROM access |
This file contains hidden or 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
| WITH a AS ( | |
| SELECT | |
| TD_PARSE_AGENT(user_agent)['ua_family'] AS family, | |
| TD_PARSE_AGENT(user_agent)['ua_major'] AS version | |
| FROM | |
| access | |
| ), | |
| b AS ( | |
| SELECT | |
| if(family = 'IE', family || version, family) AS browser | |
| FROM a | |
| ) | |
| SELECT * FROM b |
This file contains hidden or 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
| SELECT | |
| * | |
| TD_PARSE_AGENT(user_agent)['ua_family'] AS family, | |
| TD_PARSE_AGENT(user_agent)['ua_major'] AS version | |
| FROM | |
| access | |
| WHERE TD_PARSE_AGENT(user_agent) IN ['pc', 'smartphone'] |
This file contains hidden or 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
| SELECT TD_SESSIONIZE(time, 3600, ip_address) as session_id | |
| FROM ... | |
| ORDER BY ip_address, time | |
| -- ↑ソートしないと正しく出ない! |
This file contains hidden or 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
| SELECT | |
| some_name, | |
| map_keys( | |
| histogram(some_type) | |
| ) | |
| FROM foo | |
| GROUP BY some_name |
This file contains hidden or 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
| SELECT * | |
| FROM access TABLESAMPLE BERNOULLI(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment