This guide covers TD time functions, Hive features such as MAPJOIN, lateral view with explode, JSON extraction, and dynamic partitioning. It also compares Hive with Trino and lists common query errors and suggested fixes.
86%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
where td_interval(time, '-1d', 'JST') -- Yesterday
where td_interval(time, '-1w', 'JST') -- Previous week
where td_interval(time, '-1M', 'JST') -- Previous month
where td_interval(time, '-1d/-1d', 'JST') -- 2 days agoNote: Cannot use TD_SCHEDULED_TIME() as first arg. Include TD_SCHEDULED_TIME() elsewhere to establish reference date.
where td_time_range(time, '2024-01-01', '2024-01-31', 'JST')
where td_time_range(time, '2024-01-01', null, 'JST') -- Open-endedTD_TIME_FORMAT(time, 'yyyy-MM-dd HH:mm:ss', 'JST')TD_TIME_PARSE('2024-01-01', 'JST') -- String to Unix timestampTD_DATE_TRUNC('day', time, 'JST')
TD_DATE_TRUNC('hour', time, 'UTC')select /*+ MAPJOIN(small_table) */ *
from large_table l
join small_table s on l.id = s.id
where td_time_range(l.time, '2024-01-01')select user_id, tag
from user_profiles
lateral view explode(tags) tags_table as tag
where td_time_range(time, '2024-01-01')select
get_json_object(json_column, '$.user.id') as user_id,
get_json_object(json_column, '$.event.type') as event_type
from raw_eventsset hive.exec.dynamic.partition = true;
set hive.exec.dynamic.partition.mode = nonstrict;
insert overwrite table target_table partition(dt)
select *, TD_TIME_FORMAT(time, 'yyyy-MM-dd', 'JST') as dt
from source_table
where td_time_range(time, '2024-01-01', '2024-01-31')| Feature | Hive | Trino |
|---|---|---|
| Approx distinct | count(distinct x) | approx_distinct(x) |
| Time format | TD_TIME_FORMAT() | td_time_string() |
| Small table join | /*+ MAPJOIN(t) */ | Automatic |
| Flatten array | lateral view explode() | unnest() |
| Error | Fix |
|---|---|
| OutOfMemoryError | Reduce time range, use MAPJOIN |
| Too many dynamic partitions | Reduce partition count |
treasure-data/td-skills
7c1015d
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.