sql Treasure Data&(一部Presto)の知っておいて便利だった关数ref:https://qiita.com/inuscript/items/51b9b3c58260d823

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Treasure Data&(一部Presto)の知っておいて便利だった关数ref:https://qiita.com/inuscript/items/51b9b3c58260d823相关的知识,希望对你有一定的参考价值。

SELECT *
FROM access TABLESAMPLE BERNOULLI(1)
SELECT 
  some_name,
  map_keys(
    histogram(some_type)
  )
FROM foo
GROUP BY some_name
SELECT TD_SESSIONIZE(time, 3600, ip_address) as session_id
FROM ...
ORDER BY ip_address, time 
-- ↑ソートしないと正しく出ない!
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']
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
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
SELECT *
FROM access
WHERE 
  url_extract_host(referer) = "google.com"
  -- 正規表現でやるとこんな感じ
  -- regexp_like(referer, '.*google.com/.*')
SELECT
  :
WHERE 
  -- 1日間のデータなら -1d。一ヶ月なら-30dとか。
  TD_TIME_RANGE(time,
    TD_TIME_ADD(TD_SCHEDULED_TIME(), '-1d', 'JST'), 
    null,
    'JST'
  )

以上是关于sql Treasure Data&(一部Presto)の知っておいて便利だった关数ref:https://qiita.com/inuscript/items/51b9b3c58260d823的主要内容,如果未能解决你的问题,请参考以下文章

删除 Treasure-data/hadoop 中的查询?

网络流 HDU 3468 Treasure Hunting

HDU - 5770 Treasure 思维 + 扫描线 + 线段树 (看题解)

Codeforces Round #660 (Div. 2) D. Captain Flint and Treasure

SQL Fundamentals || DCL(Data Control Language) || 系统权限&对象权限管理(GRANT&REVOKE)

SQL Fundamentals || DCL(Data Control Language) || 用户管理&Profile概要文件