Agent skill

trino

TD Trino SQL with TD-specific functions (td_interval, td_time_range, td_time_string, td_sessionize). Use for time-based filtering, partition pruning, and TD query patterns.

Stars 16
Forks 23

Install this agent skill to your Project

npx add-skill https://github.com/treasure-data/td-skills/tree/main/sql-skills/trino

SKILL.md

TD Trino SQL

TD Time Functions

td_interval (Recommended for relative time)

sql
where td_interval(time, '-1d', 'JST')      -- Yesterday (JST)
where td_interval(time, '-1d')             -- Yesterday (UTC)
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 ago
where td_interval(time, '-1M/-2M', 'JST')  -- 3 months ago

Timezone is optional (defaults to UTC).

Note: Cannot use td_scheduled_time() as first arg. Include td_scheduled_time() elsewhere in query to establish reference date.

td_time_range (Explicit dates)

sql
where td_time_range(time, '2024-01-01', '2024-01-31')
where td_time_range(time, td_time_add(td_scheduled_time(), '-7d'), td_scheduled_time())

td_time_string (Display formatting)

sql
td_time_string(time, 'd!')         -- 2024-01-15 (UTC)
td_time_string(time, 'd!', 'JST')  -- 2024-01-15 (JST)
td_time_string(time, 's!', 'JST')  -- 2024-01-15 10:30:45
td_time_string(time, 'M!')         -- 2024-01
td_time_string(time, 'h!')         -- 2024-01-15 10

Format codes: y!=year, q!=quarter, M!=month, w!=week, d!=day, h!=hour, m!=minute, s!=second. Without the exclamation mark, includes timezone offset. Timezone is optional (defaults to UTC).

Use for display only, never for filtering:

  • Good: select td_time_string(time, 'd!', 'JST') as date
  • Bad: where td_time_string(time, 'd!', 'JST') = '2024-01-01'

td_time_format (Legacy)

sql
td_time_format(time, 'yyyy-MM-dd HH:mm:ss', 'JST')

td_sessionize

sql
select td_sessionize(time, 1800, user_id) as session_id  -- 30min timeout
from events

Table Format

sql
select * from database_name.table_name
where td_interval(time, '-1d', 'JST')

Performance

Always include time filters for partition pruning:

sql
-- Good: Partition pruning
where td_time_range(time, '2024-01-01', '2024-01-02')

-- Bad: Full table scan
where event_type = 'click'  -- Missing time filter!

Use approx_distinct() and approx_percentile() for large datasets.

Common Errors

Error Fix
Query exceeded memory limit Add time filters, use approx_ functions
Partition not found Verify time range syntax

Resources

Expand your agent's capabilities with these related and highly-rated skills.

treasure-data/td-skills

email-campaign

This skill should be used when the user asks to "create an email", "build an email campaign", "design an email template", "generate an email for a segment", "preview an email", or "push an email to Engage". Generates enterprise-grade HTML email templates with live preview in Treasure Studio and natural language editing, then pushes the final version to Treasure Engage.

16 23
Explore
treasure-data/td-skills

action-report

YAML format reference for action reports rendered via preview_action_report. MUST be read before writing any action report YAML — defines the report structure (title, summary, actions array) and action item fields (as_is, to_be, reason, priority, category, impact) with incremental build workflow. Required by seo-analysis and any skill that produces prioritized recommendations.

16 23
Explore
treasure-data/td-skills

grid-dashboard

YAML format reference for grid dashboards rendered via preview_grid_dashboard. MUST be read before writing any dashboard YAML — defines the page structure, 6 cell types (kpi, gauge, scores, table, chart, markdown), grid layout rules, cell merging syntax, and incremental build workflow. Required by seo-analysis and any skill that produces visual data dashboards.

16 23
Explore
treasure-data/td-skills

seo-analysis

Runs SEO and AEO (Answer Engine Optimization) analysis on websites or specific pages. Use when the user mentions SEO, AEO, search rankings, search optimization, or wants to analyze how their pages perform in search engines and AI answers. Produces a data dashboard and action report with before/after recommendations.

16 23
Explore
treasure-data/td-skills

aps-doc-core

Core documentation generation patterns and framework for Treasure Data pipeline layers. Provides shared templates, quality validation, testing framework, and Confluence integration used by all layer-specific documentation skills.

16 23
Explore
treasure-data/td-skills

aps-doc-id-unification

Expert documentation generation for ID unification layers. Documents identity resolution algorithms, merge strategies, match rules, entity graphs, and multi-workflow orchestration. Use when documenting ID unification processes.

16 23
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results