@treasuredata/tdx 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +706 -0
  3. package/dist/api/http-client.d.ts +95 -0
  4. package/dist/api/http-client.d.ts.map +1 -0
  5. package/dist/api/http-client.js +1 -0
  6. package/dist/api/http-client.js.map +1 -0
  7. package/dist/api/rate-limiter.d.ts +55 -0
  8. package/dist/api/rate-limiter.d.ts.map +1 -0
  9. package/dist/api/rate-limiter.js +1 -0
  10. package/dist/api/rate-limiter.js.map +1 -0
  11. package/dist/api/td-client.d.ts +90 -0
  12. package/dist/api/td-client.d.ts.map +1 -0
  13. package/dist/api/td-client.js +1 -0
  14. package/dist/api/td-client.js.map +1 -0
  15. package/dist/api/trino-client.d.ts +85 -0
  16. package/dist/api/trino-client.d.ts.map +1 -0
  17. package/dist/api/trino-client.js +1 -0
  18. package/dist/api/trino-client.js.map +1 -0
  19. package/dist/cli.d.ts +9 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +2 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/client/cdp-client.d.ts +84 -0
  24. package/dist/client/cdp-client.d.ts.map +1 -0
  25. package/dist/client/cdp-client.js +1 -0
  26. package/dist/client/cdp-client.js.map +1 -0
  27. package/dist/client/http-client.d.ts +95 -0
  28. package/dist/client/http-client.d.ts.map +1 -0
  29. package/dist/client/http-client.js +1 -0
  30. package/dist/client/http-client.js.map +1 -0
  31. package/dist/client/rate-limiter.d.ts +55 -0
  32. package/dist/client/rate-limiter.d.ts.map +1 -0
  33. package/dist/client/rate-limiter.js +1 -0
  34. package/dist/client/rate-limiter.js.map +1 -0
  35. package/dist/client/td-client.d.ts +90 -0
  36. package/dist/client/td-client.d.ts.map +1 -0
  37. package/dist/client/td-client.js +1 -0
  38. package/dist/client/td-client.js.map +1 -0
  39. package/dist/client/trino-client.d.ts +85 -0
  40. package/dist/client/trino-client.d.ts.map +1 -0
  41. package/dist/client/trino-client.js +1 -0
  42. package/dist/client/trino-client.js.map +1 -0
  43. package/dist/client/workflow-client.d.ts +92 -0
  44. package/dist/client/workflow-client.d.ts.map +1 -0
  45. package/dist/client/workflow-client.js +1 -0
  46. package/dist/client/workflow-client.js.map +1 -0
  47. package/dist/commands/activations.d.ts +15 -0
  48. package/dist/commands/activations.d.ts.map +1 -0
  49. package/dist/commands/activations.js +1 -0
  50. package/dist/commands/activations.js.map +1 -0
  51. package/dist/commands/command.d.ts +72 -0
  52. package/dist/commands/command.d.ts.map +1 -0
  53. package/dist/commands/command.js +1 -0
  54. package/dist/commands/command.js.map +1 -0
  55. package/dist/commands/database-command.d.ts +16 -0
  56. package/dist/commands/database-command.d.ts.map +1 -0
  57. package/dist/commands/database-command.js +1 -0
  58. package/dist/commands/database-command.js.map +1 -0
  59. package/dist/commands/database.d.ts +16 -0
  60. package/dist/commands/database.d.ts.map +1 -0
  61. package/dist/commands/database.js +1 -0
  62. package/dist/commands/database.js.map +1 -0
  63. package/dist/commands/databases.d.ts +16 -0
  64. package/dist/commands/databases.d.ts.map +1 -0
  65. package/dist/commands/databases.js +1 -0
  66. package/dist/commands/databases.js.map +1 -0
  67. package/dist/commands/describe.d.ts +26 -0
  68. package/dist/commands/describe.d.ts.map +1 -0
  69. package/dist/commands/describe.js +1 -0
  70. package/dist/commands/describe.js.map +1 -0
  71. package/dist/commands/query-command.d.ts +20 -0
  72. package/dist/commands/query-command.d.ts.map +1 -0
  73. package/dist/commands/query-command.js +1 -0
  74. package/dist/commands/query-command.js.map +1 -0
  75. package/dist/commands/query.d.ts +20 -0
  76. package/dist/commands/query.d.ts.map +1 -0
  77. package/dist/commands/query.js +1 -0
  78. package/dist/commands/query.js.map +1 -0
  79. package/dist/commands/segment-command.d.ts +56 -0
  80. package/dist/commands/segment-command.d.ts.map +1 -0
  81. package/dist/commands/segment-command.js +1 -0
  82. package/dist/commands/segment-command.js.map +1 -0
  83. package/dist/commands/segments.d.ts +16 -0
  84. package/dist/commands/segments.d.ts.map +1 -0
  85. package/dist/commands/segments.js +1 -0
  86. package/dist/commands/segments.js.map +1 -0
  87. package/dist/commands/show.d.ts +26 -0
  88. package/dist/commands/show.d.ts.map +1 -0
  89. package/dist/commands/show.js +1 -0
  90. package/dist/commands/show.js.map +1 -0
  91. package/dist/commands/table-command.d.ts +50 -0
  92. package/dist/commands/table-command.d.ts.map +1 -0
  93. package/dist/commands/table-command.js +1 -0
  94. package/dist/commands/table-command.js.map +1 -0
  95. package/dist/commands/table.d.ts +35 -0
  96. package/dist/commands/table.d.ts.map +1 -0
  97. package/dist/commands/table.js +1 -0
  98. package/dist/commands/table.js.map +1 -0
  99. package/dist/commands/tables.d.ts +20 -0
  100. package/dist/commands/tables.d.ts.map +1 -0
  101. package/dist/commands/tables.js +1 -0
  102. package/dist/commands/tables.js.map +1 -0
  103. package/dist/commands/workflow-command.d.ts +77 -0
  104. package/dist/commands/workflow-command.d.ts.map +1 -0
  105. package/dist/commands/workflow-command.js +1 -0
  106. package/dist/commands/workflow-command.js.map +1 -0
  107. package/dist/core/auth.d.ts +48 -0
  108. package/dist/core/auth.d.ts.map +1 -0
  109. package/dist/core/auth.js +1 -0
  110. package/dist/core/auth.js.map +1 -0
  111. package/dist/core/command.d.ts +71 -0
  112. package/dist/core/command.d.ts.map +1 -0
  113. package/dist/core/command.js +1 -0
  114. package/dist/core/command.js.map +1 -0
  115. package/dist/core/config.d.ts +59 -0
  116. package/dist/core/config.d.ts.map +1 -0
  117. package/dist/core/config.js +1 -0
  118. package/dist/core/config.js.map +1 -0
  119. package/dist/index.d.ts +37 -0
  120. package/dist/index.d.ts.map +1 -0
  121. package/dist/index.js +1 -0
  122. package/dist/index.js.map +1 -0
  123. package/dist/sdk/client.d.ts +25 -0
  124. package/dist/sdk/client.d.ts.map +1 -0
  125. package/dist/sdk/client.js +1 -0
  126. package/dist/sdk/client.js.map +1 -0
  127. package/dist/sdk/database.d.ts +36 -0
  128. package/dist/sdk/database.d.ts.map +1 -0
  129. package/dist/sdk/database.js +1 -0
  130. package/dist/sdk/database.js.map +1 -0
  131. package/dist/sdk/errors.d.ts +11 -0
  132. package/dist/sdk/errors.d.ts.map +1 -0
  133. package/dist/sdk/errors.js +1 -0
  134. package/dist/sdk/errors.js.map +1 -0
  135. package/dist/sdk/index.d.ts +143 -0
  136. package/dist/sdk/index.d.ts.map +1 -0
  137. package/dist/sdk/index.js +1 -0
  138. package/dist/sdk/index.js.map +1 -0
  139. package/dist/sdk/query.d.ts +57 -0
  140. package/dist/sdk/query.d.ts.map +1 -0
  141. package/dist/sdk/query.js +1 -0
  142. package/dist/sdk/query.js.map +1 -0
  143. package/dist/sdk/segment.d.ts +152 -0
  144. package/dist/sdk/segment.d.ts.map +1 -0
  145. package/dist/sdk/segment.js +1 -0
  146. package/dist/sdk/segment.js.map +1 -0
  147. package/dist/sdk/table.d.ts +118 -0
  148. package/dist/sdk/table.d.ts.map +1 -0
  149. package/dist/sdk/table.js +1 -0
  150. package/dist/sdk/table.js.map +1 -0
  151. package/dist/sdk/workflow.d.ts +250 -0
  152. package/dist/sdk/workflow.d.ts.map +1 -0
  153. package/dist/sdk/workflow.js +1 -0
  154. package/dist/sdk/workflow.js.map +1 -0
  155. package/dist/types/endpoints.d.ts +64 -0
  156. package/dist/types/endpoints.d.ts.map +1 -0
  157. package/dist/types/endpoints.js +1 -0
  158. package/dist/types/endpoints.js.map +1 -0
  159. package/dist/types/index.d.ts +280 -0
  160. package/dist/types/index.d.ts.map +1 -0
  161. package/dist/types/index.js +1 -0
  162. package/dist/types/index.js.map +1 -0
  163. package/dist/types/trino.d.ts +117 -0
  164. package/dist/types/trino.d.ts.map +1 -0
  165. package/dist/types/trino.js +1 -0
  166. package/dist/types/trino.js.map +1 -0
  167. package/dist/types/workflow.d.ts +186 -0
  168. package/dist/types/workflow.d.ts.map +1 -0
  169. package/dist/types/workflow.js +1 -0
  170. package/dist/types/workflow.js.map +1 -0
  171. package/dist/utils/colors.d.ts +60 -0
  172. package/dist/utils/colors.d.ts.map +1 -0
  173. package/dist/utils/colors.js +1 -0
  174. package/dist/utils/colors.js.map +1 -0
  175. package/dist/utils/command-output.d.ts +118 -0
  176. package/dist/utils/command-output.d.ts.map +1 -0
  177. package/dist/utils/command-output.js +1 -0
  178. package/dist/utils/command-output.js.map +1 -0
  179. package/dist/utils/format-detector.d.ts +41 -0
  180. package/dist/utils/format-detector.d.ts.map +1 -0
  181. package/dist/utils/format-detector.js +1 -0
  182. package/dist/utils/format-detector.js.map +1 -0
  183. package/dist/utils/formatters.d.ts +59 -0
  184. package/dist/utils/formatters.d.ts.map +1 -0
  185. package/dist/utils/formatters.js +1 -0
  186. package/dist/utils/formatters.js.map +1 -0
  187. package/dist/utils/option-validation.d.ts +57 -0
  188. package/dist/utils/option-validation.d.ts.map +1 -0
  189. package/dist/utils/option-validation.js +1 -0
  190. package/dist/utils/option-validation.js.map +1 -0
  191. package/dist/utils/segment-ref-parser.d.ts +17 -0
  192. package/dist/utils/segment-ref-parser.d.ts.map +1 -0
  193. package/dist/utils/segment-ref-parser.js +1 -0
  194. package/dist/utils/segment-ref-parser.js.map +1 -0
  195. package/dist/utils/simple-formatter.d.ts +23 -0
  196. package/dist/utils/simple-formatter.d.ts.map +1 -0
  197. package/dist/utils/simple-formatter.js +1 -0
  198. package/dist/utils/simple-formatter.js.map +1 -0
  199. package/dist/utils/spinner.d.ts +97 -0
  200. package/dist/utils/spinner.d.ts.map +1 -0
  201. package/dist/utils/spinner.js +1 -0
  202. package/dist/utils/spinner.js.map +1 -0
  203. package/dist/utils/sql-parser.d.ts +68 -0
  204. package/dist/utils/sql-parser.d.ts.map +1 -0
  205. package/dist/utils/sql-parser.js +1 -0
  206. package/dist/utils/sql-parser.js.map +1 -0
  207. package/dist/utils/string-utils.d.ts +68 -0
  208. package/dist/utils/string-utils.d.ts.map +1 -0
  209. package/dist/utils/string-utils.js +1 -0
  210. package/dist/utils/string-utils.js.map +1 -0
  211. package/dist/utils/table-ref-parser.d.ts +119 -0
  212. package/dist/utils/table-ref-parser.d.ts.map +1 -0
  213. package/dist/utils/table-ref-parser.js +1 -0
  214. package/dist/utils/table-ref-parser.js.map +1 -0
  215. package/package.json +81 -0
package/README.md ADDED
@@ -0,0 +1,706 @@
1
+ # tdx - AI-Native CLI for Treasure Data
2
+
3
+ > **Status:** 🚧 Under Development (Phase 1)
4
+
5
+ A modern, AI-native command-line interface for Treasure Data, optimized for both human engineers and AI coding assistants.
6
+
7
+ ## Features
8
+
9
+ - 🤖 **AI-Native Design**: Consistent JSON output, predictable error codes, structured responses
10
+ - 🌍 **Multi-Site Support**: Easy switching between US, JP, EU, and AP regions
11
+ - 🚀 **Modern Distribution**: Install via `npx` or `npm` without prior setup
12
+ - ⚡ **Fast & Efficient**: Built with TypeScript on Node.js 24+
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ # Run directly with npx (no installation required)
18
+ npx @treasuredata/tdx databases
19
+
20
+ # Or install globally
21
+ npm install -g @treasuredata/tdx
22
+
23
+ # Alternative: Use with Bun
24
+ bun x @treasuredata/tdx databases
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### 1. Configure API Key
30
+
31
+ Create `~/.config/tdx/.env`:
32
+
33
+ ```bash
34
+ # Single API key (recommended for most users)
35
+ TD_API_KEY=your-api-key-here/...
36
+
37
+ # Or use site-specific keys if working with multiple sites
38
+ # TD_API_KEY_US01=your-us-key-here/...
39
+ # TD_API_KEY_JP01=your-jp-key-here/...
40
+ ```
41
+
42
+ Alternatively, set as environment variable:
43
+ ```bash
44
+ # Export for all commands in session
45
+ export TD_API_KEY=your-api-key-here/...
46
+
47
+ # Or set inline for a single command
48
+ TD_API_KEY=your-api-key-here/... tdx databases
49
+ ```
50
+
51
+ ### 2. Run Commands
52
+
53
+ ```bash
54
+ # List databases
55
+ tdx databases
56
+
57
+ # List databases in Tokyo region
58
+ tdx databases --site jp01
59
+
60
+ # Show table contents
61
+ tdx show sample_datasets.www_access --limit 10
62
+
63
+ # Run a query
64
+ tdx query "SELECT * FROM mytable LIMIT 10"
65
+
66
+ # Get JSON output (two ways)
67
+ tdx databases --json
68
+ tdx databases --format json
69
+
70
+ # Get JSON Lines output
71
+ tdx query "SELECT * FROM users" --jsonl
72
+
73
+ # Get TSV output
74
+ tdx query "SELECT * FROM users" --tsv
75
+
76
+ # Get human-readable table output (default)
77
+ tdx databases --format table
78
+ ```
79
+
80
+ ## Available Commands
81
+
82
+ ```bash
83
+ tdx <command> [options] [arguments]
84
+ ```
85
+
86
+ ### Global Options
87
+
88
+ Available for all commands:
89
+
90
+ - `--site <site>`: TD site/region (us01, jp01, eu01, ap02) - default: us01
91
+ - `--format <format>`: Output format (table, json, jsonl, tsv) - default: table
92
+ - `--json`: Output in JSON format (shorthand for --format json)
93
+ - `--jsonl`: Output in JSON Lines format (shorthand for --format jsonl)
94
+ - `--tsv`: Output in TSV format (shorthand for --format tsv)
95
+ - `--output <file>`: Save output to file
96
+ - `--limit <rows>`: Maximum rows to display in table format - default: 40
97
+ - `--color`: Force ANSI color output (overrides TTY detection)
98
+ - `--no-color`: Disable ANSI color output (also respects NO_COLOR env var)
99
+ - `--verbose`: Enable verbose logging
100
+ - `--timeout <seconds>`: Set operation timeout - default: 30
101
+ - `--dry-run`: Preview operation without executing
102
+ - `-y, --yes`: Skip confirmation prompts
103
+
104
+ **Note:** Shorthand flags (--json, --jsonl, --tsv) are only applied when --format is not explicitly specified. If both are provided, --format is used.
105
+
106
+ ### Interactive Table Navigation
107
+
108
+ When viewing table output in an interactive terminal, `tdx` automatically pipes the output through `less` for easy navigation of large datasets. This allows you to:
109
+
110
+ - View all rows without truncation (unlimited data display)
111
+ - Scroll through wide tables without column truncation
112
+ - Search and navigate efficiently
113
+
114
+ **Keyboard shortcuts in less:**
115
+
116
+ | Key | Action |
117
+ |-----|--------|
118
+ | `q` | Quit and return to terminal |
119
+ | `↑` / `↓` | Scroll up/down one line |
120
+ | `Space` / `Page Down` | Scroll down one page |
121
+ | `b` / `Page Up` | Scroll up one page |
122
+ | `←` / `→` | Scroll left/right (for wide tables) |
123
+ | `/pattern` | Search forward for pattern |
124
+ | `?pattern` | Search backward for pattern |
125
+ | `n` | Repeat previous search forward |
126
+ | `N` | Repeat previous search backward |
127
+ | `g` | Go to first line |
128
+ | `G` | Go to last line |
129
+ | `h` | Show help |
130
+
131
+ **Note:** Less pagination is automatically enabled for table format output in interactive terminals. It's disabled when:
132
+ - Output is piped to another command
133
+ - Output is saved to a file with `--output`
134
+ - Using non-table formats (JSON, JSONL, TSV)
135
+
136
+
137
+ ### Database Commands
138
+
139
+ | Command | Description | Example |
140
+ |---------|-------------|---------|
141
+ | `databases` | List all databases | `tdx databases` |
142
+ | | Filter by pattern (glob/wildcards) | `tdx databases "prod_*"` or `tdx databases "*_analytics"` |
143
+
144
+ ### Table Commands
145
+
146
+ All table commands use dot-separated patterns: `(database).(table)`
147
+
148
+ | Command | Description | Example |
149
+ |---------|-------------|---------|
150
+ | `tables` | List all tables from all databases | `tdx tables` |
151
+ | | List all tables from specific database | `tdx tables "mydb.*"` or `tdx tables --in mydb` |
152
+ | | List tables from database (--database flag) | `tdx tables --database mydb` |
153
+ | | Filter tables with pattern | `tdx tables "mydb.user_*"` |
154
+ | | Database pattern with table | `tdx tables "prod_*.access_log"` |
155
+ | | Wildcard database and table | `tdx tables "*.user*"` |
156
+ | | All tables from all databases | `tdx tables "*.*"` |
157
+ | `describe <table>` (alias: `desc`) | Show table schema | `tdx describe mydb.users` |
158
+ | | Using --in or --database flag | `tdx describe users --in mydb` or `tdx describe users -d mydb` |
159
+ | `show <table>` | Show table contents (SELECT * with limit) | `tdx show mydb.users` |
160
+ | | With custom row limit | `tdx show mydb.users --limit 10` |
161
+ | | With explicit catalog | `tdx show td.mydb.users --limit 5` |
162
+ | | Using --in or --database flag | `tdx show users --in mydb` or `tdx show users -d mydb` |
163
+
164
+ **Pattern syntax:**
165
+ - Database wildcard: `"mydb.*"` → all tables from mydb (use this or `--database mydb`)
166
+ - Database.table: `mydb.users` → specific table
167
+ - Wildcards: `"*.users"`, `"prod_*.user*"` → pattern matching
168
+ - Catalog: `"td.mydb.users"` → with catalog prefix
169
+
170
+ **Table-specific options:**
171
+ - `-d, --database <database>`: Specify database name when not included in pattern
172
+ - `--in <database>`: Alias for `--database` (natural language style)
173
+
174
+ **Alternative syntax for specifying database:**
175
+
176
+ There are multiple ways to specify the database for table commands:
177
+
178
+ ```bash
179
+ # Using dot notation (recommended for patterns)
180
+ tdx tables "mydb.*"
181
+
182
+ # Using --in flag (natural language style, no quotes needed)
183
+ tdx tables --in mydb
184
+
185
+ # Using --database flag (or -d shorthand)
186
+ tdx tables --database mydb
187
+ tdx tables -d mydb
188
+
189
+ # All three are equivalent for listing all tables from a database
190
+
191
+ # Works with describe and show commands too
192
+ tdx describe users --in mydb
193
+ tdx show users --in mydb
194
+
195
+ # List tables matching pattern from "mydb"
196
+ tdx tables "user*" --in mydb
197
+ ```
198
+
199
+ **Note:** If the pattern already includes a database (e.g., `mydb.users`), the `--database` option is ignored:
200
+
201
+ ```bash
202
+ # Uses "mydb" from pattern, ignores --database option
203
+ tdx tables mydb.users --database other
204
+ # Result: Lists users table from mydb, not other
205
+ ```
206
+
207
+ ### Query Commands
208
+
209
+ Usage: `tdx query [options] [sql]`
210
+
211
+ | Option/Usage | Description | Example |
212
+ |--------------|-------------|---------|
213
+ | `<sql>` | Execute SQL query | `tdx query "SELECT * FROM table"` |
214
+ | `-f, --file <path>` | Execute SQL from file | `tdx query -f query.sql` |
215
+ | Multi-statement | Execute multiple statements (CLI or file) | `tdx query "SELECT 1; SELECT 2"` |
216
+ | | Multi-statement from file | `tdx query -f setup-and-query.sql` |
217
+
218
+ **Query-specific options**:
219
+ - `-f, --file <path>`: Read SQL from file
220
+ - `-d, --database <db>`: Database to query (default: information_schema)
221
+ - `--in <db>`: Alias for `--database` (natural language style)
222
+ - `--catalog <catalog>`: Trino catalog (default: td)
223
+
224
+ **Examples**:
225
+ ```bash
226
+ # Query with --in flag
227
+ tdx query "SELECT * FROM users" --in mydb
228
+
229
+ # Equivalent to --database
230
+ tdx query "SELECT * FROM users" --database mydb
231
+ tdx query "SELECT * FROM users" -d mydb
232
+ ```
233
+
234
+ ### Job Commands
235
+
236
+ Usage: `tdx job <subcommand>`
237
+
238
+ | Subcommand | Description | Status |
239
+ |------------|-------------|--------|
240
+ | - | Job management | Coming soon |
241
+
242
+ ### Segment Commands (CDP)
243
+
244
+ Usage: `tdx segment <subcommand> [options] [arguments]`
245
+
246
+ CDP (Customer Data Platform) segment management for audiences and activations.
247
+
248
+ **ID Format Conventions:**
249
+ - Parent segment: `parent_id` (e.g., `987900`)
250
+ - Child segment: `parent_id.child_id` (e.g., `987900.1463552`) - uses dot notation
251
+ - Folder ID: Direct folder ID (e.g., `1453821`)
252
+ - Pattern: Commands accept `(parent_id)(.child_id)?` format
253
+
254
+ | Command | Description | Example |
255
+ |---------|-------------|---------|
256
+ | `segments` | List all parent segments | `tdx segments` |
257
+ | `segments <parent_id>` | List child segments under parent | `tdx segments 987900` |
258
+ | `segment describe <id>` (alias: `desc`) | Show parent or child segment details | `tdx segment describe 987900` or `tdx segment desc 987900.1463552` |
259
+ | `segment show <id>` | Execute segment SQL query and show results | `tdx segment show 987900` or `tdx segment show 987900.1463552 --limit 100` |
260
+ | `segment sql <id>` | Get SQL query for segment | `tdx segment sql 987900` or `tdx segment sql 987900.1463552` |
261
+ | `segment folders <parent_id>` | List folders under parent | `tdx segment folders 987900` |
262
+ | `segment folder show <folder_id>` | Show folder details | `tdx segment folder show 1453821` |
263
+
264
+ **Examples**:
265
+ ```bash
266
+ # List all parent segments
267
+ tdx segments --format json
268
+
269
+ # List child segments under parent
270
+ tdx segments 987900
271
+
272
+ # Show parent segment metadata
273
+ tdx segment describe 987900
274
+ # or use the alias
275
+ tdx segment desc 987900
276
+
277
+ # Show child segment metadata (dot notation)
278
+ tdx segment describe 987900.1463552
279
+
280
+ # Execute parent segment query and show results (default: 40 rows)
281
+ tdx segment show 987900
282
+
283
+ # Execute child segment query with custom limit (dot notation)
284
+ tdx segment show 987900.1463552 --limit 100
285
+
286
+ # Execute segment query and save as JSON
287
+ tdx segment show 987900 --format json --output results.json
288
+
289
+ # Get SQL for parent segment
290
+ tdx segment sql 987900 > parent-query.sql
291
+
292
+ # Get SQL for child segment with filtering (dot notation)
293
+ tdx segment sql 987900.1463552 > child-query.sql
294
+
295
+ # List folders under parent
296
+ tdx segment folders 987900
297
+
298
+ # Show folder details (direct folder ID)
299
+ tdx segment folder show 1453821
300
+ ```
301
+
302
+ ### Activation Commands (CDP)
303
+
304
+ Manage CDP activations (syndications) for segments.
305
+
306
+ | Command | Description | Example |
307
+ |---------|-------------|---------|
308
+ | `activations <segment_id>` | List activations for a child segment | `tdx activations 987900.1463552` |
309
+
310
+ **Examples**:
311
+ ```bash
312
+ # List activations for a child segment (dot notation)
313
+ tdx activations 987900.1463552
314
+
315
+ # Get activations as JSON
316
+ tdx activations 987900.1463552 --format json
317
+
318
+ # Using Tokyo region
319
+ tdx activations 987900.1463552 --site jp01
320
+ ```
321
+
322
+ ### Workflow Commands
323
+
324
+ Usage: `tdx workflow <subcommand>` (alias: `tdx wf`)
325
+
326
+ Manage Treasure Data workflows powered by Digdag. Monitor execution sessions, view logs, and control workflow attempts.
327
+
328
+ | Subcommand | Description | Example |
329
+ |------------|-------------|---------|
330
+ | `projects [pattern]` | List workflow projects (supports glob patterns) | `tdx wf projects` or `tdx wf projects "cdp_*"` |
331
+ | `workflows [project]` (alias: `ls`) | List workflows (filter by project, supports globs) | `tdx wf workflows` or `tdx wf workflows "lda*"` |
332
+ | `sessions [project]` | List workflow execution sessions | `tdx wf sessions` or `tdx wf sessions myproject` or `tdx wf sessions myproject.daily_etl` |
333
+ | `attempts [project]` | List workflow attempts | `tdx wf attempts` or `tdx wf attempts myproject` or `tdx wf attempts myproject.workflow` |
334
+ | `attempt <attempt-id>` | Show specific attempt details | `tdx wf attempt 67890` |
335
+ | `tasks <attempt-id>` | Show tasks for an attempt | `tdx wf tasks 67890` |
336
+ | `logs <attempt-id> <task-name>` | Show logs for a specific task | `tdx wf logs 67890 +step1` |
337
+ | `kill <attempt-id>` | Kill a running attempt | `tdx wf kill 67890` |
338
+ | `retry <session-id\|attempt-id>` | Retry a session or attempt | `tdx wf retry session:12345` or `tdx wf retry attempt:67890` |
339
+
340
+ **Workflow-specific options:**
341
+
342
+ For `sessions` command:
343
+ - `--status <status>`: Filter by status (running, success, error, blocked, all)
344
+ - `--from <timestamp>`: Start time filter (ISO 8601 format)
345
+ - `--to <timestamp>`: End time filter (ISO 8601 format)
346
+
347
+ For `attempts` command:
348
+ - `--include-retried`: Include retried attempts in the output
349
+
350
+ For `tasks` command:
351
+ - `--include-subtasks`: Include subtasks in the output
352
+
353
+ For `logs` command:
354
+ - `--offset <number>`: Starting offset for logs (default: 0)
355
+
356
+ For `kill` command:
357
+ - `--reason <text>`: Reason for killing the attempt
358
+ - `-y, --yes`: Skip confirmation prompt
359
+
360
+ For `retry` command:
361
+ - `--from-task <task>`: Resume from specific task (session retry only)
362
+ - `--resume-from <task>`: Resume from specific task (attempt retry only)
363
+ - `--params <json>`: Override parameters (JSON string or @file.json)
364
+ - `--force`: Force retry even if not failed (attempt retry only)
365
+ - `-y, --yes`: Skip confirmation prompt
366
+
367
+ **Examples**:
368
+ ```bash
369
+ # List all workflow projects
370
+ tdx wf projects
371
+
372
+ # Filter projects by pattern
373
+ tdx wf projects "cdp_segment_*"
374
+
375
+ # List all workflows
376
+ tdx wf workflows
377
+
378
+ # List workflows for a specific project
379
+ tdx wf workflows myproject
380
+
381
+ # Filter workflows by project pattern
382
+ tdx wf workflows "lda*"
383
+
384
+ # List all workflow sessions
385
+ tdx wf sessions
386
+
387
+ # List sessions for a specific project
388
+ tdx wf sessions myproject
389
+
390
+ # List sessions for specific workflow
391
+ tdx wf sessions myproject.daily_etl
392
+
393
+ # Filter sessions by status
394
+ tdx wf sessions --status error
395
+
396
+ # Filter sessions by time range
397
+ tdx wf sessions --from "2025-01-01" --to "2025-01-31"
398
+
399
+ # List all attempts
400
+ tdx wf attempts
401
+
402
+ # List attempts for a project
403
+ tdx wf attempts myproject
404
+
405
+ # List attempts for a workflow
406
+ tdx wf attempts myproject.daily_etl
407
+
408
+ # Include retried attempts
409
+ tdx wf attempts --include-retried
410
+
411
+ # Show specific attempt details
412
+ tdx wf attempt 67890
413
+
414
+ # Show tasks for an attempt
415
+ tdx wf tasks 67890
416
+
417
+ # Show tasks including subtasks
418
+ tdx wf tasks 67890 --include-subtasks
419
+
420
+ # View logs for a specific task
421
+ tdx wf logs 67890 +step1
422
+
423
+ # View logs with pagination
424
+ tdx wf logs 67890 +step1 --offset 100 --limit 500
425
+
426
+ # Kill a running attempt (with confirmation)
427
+ tdx wf kill 67890
428
+
429
+ # Kill with reason and skip confirmation
430
+ tdx wf kill 67890 --reason "manual stop" -y
431
+
432
+ # Retry entire session
433
+ tdx wf retry session:12345
434
+
435
+ # Retry session from specific task
436
+ tdx wf retry session:12345 --from-task +step2
437
+
438
+ # Retry attempt
439
+ tdx wf retry attempt:67890
440
+
441
+ # Retry attempt from specific task
442
+ tdx wf retry attempt:67890 --resume-from +step2
443
+
444
+ # Retry with parameter override
445
+ tdx wf retry attempt:67890 --params '{"key":"value"}'
446
+
447
+ # Retry with params from file
448
+ tdx wf retry attempt:67890 --params @params.json
449
+
450
+ # Force retry without confirmation
451
+ tdx wf retry attempt:67890 --force -y
452
+
453
+ # Get workflow data as JSON
454
+ tdx wf sessions --format json --output sessions.json
455
+ ```
456
+
457
+ ## Advanced Query Features
458
+
459
+ ### File Input
460
+
461
+ Read SQL queries from files using the `-f` or `--file` option:
462
+
463
+ ```bash
464
+ # Execute SQL from file
465
+ tdx query --file query.sql
466
+
467
+ # Short form
468
+ tdx query -f query.sql
469
+
470
+ # With options
471
+ tdx query -f query.sql --database mydb --format json --output results.json
472
+ ```
473
+
474
+ ### Multi-Statement Execution
475
+
476
+ Execute multiple SQL statements sequentially by separating them with semicolons. This works for both command-line input and file input:
477
+
478
+ **From command line**:
479
+ ```bash
480
+ tdx query "SELECT COUNT(*) FROM users; SELECT COUNT(*) FROM orders"
481
+ ```
482
+
483
+ **From file** (`setup-and-query.sql`):
484
+ ```sql
485
+ CREATE TABLE temp_users AS SELECT * FROM users WHERE active = true;
486
+ CREATE TABLE temp_orders AS SELECT * FROM orders WHERE user_id IN (SELECT id FROM temp_users);
487
+ SELECT COUNT(*) as order_count FROM temp_orders;
488
+ ```
489
+
490
+ ```bash
491
+ tdx query -f setup-and-query.sql
492
+ ```
493
+
494
+ **Output behavior**:
495
+ - Each statement executes sequentially with progress indication
496
+ - **Console output**: All results displayed as they complete
497
+ - **File output** (`--output results.txt`): All results appended to single file
498
+ - **Fail-fast**: Execution stops on first error
499
+
500
+ **Example output**:
501
+ ```
502
+ ✔ Statement 1/3 - Query completed: Processed 1,000 rows in 2.3s
503
+ ┌────────────┐
504
+ │ user_count │
505
+ ├────────────┤
506
+ │ 1000 │
507
+ └────────────┘
508
+ ✔ Statement 2/3 - Query completed: Processed 5,000 rows in 3.1s
509
+ ┌─────────────┐
510
+ │ order_count │
511
+ ├─────────────┤
512
+ │ 5000 │
513
+ └─────────────┘
514
+ ✔ Statement 3/3 - Query completed: Processed 1 rows in 0.5s
515
+ ┌─────────────┐
516
+ │ order_count │
517
+ ├─────────────┤
518
+ │ 5000 │
519
+ └─────────────┘
520
+ ```
521
+
522
+ **With `--output`** (file mode):
523
+ ```bash
524
+ tdx query -f statements.sql --output results.txt
525
+ ```
526
+ - Console shows only progress messages
527
+ - All results written to `results.txt` (appended sequentially)
528
+ - Message: "All results saved to results.txt"
529
+
530
+ ## Output Formats
531
+
532
+ tdx supports multiple output formats for query results and command outputs:
533
+
534
+ ### Table Format (default)
535
+ Human-readable ASCII table with column types and row counts:
536
+ ```bash
537
+ tdx query "SELECT name, age FROM users LIMIT 2"
538
+ ```
539
+ ```
540
+ ┌───────┬─────┐
541
+ │ name │ age │
542
+ │ string│ int │
543
+ ├───────┼─────┤
544
+ │ Alice │ 25 │
545
+ │ Bob │ 30 │
546
+ ├───────┴─────┤
547
+ │ 2 rows │
548
+ └─────────────┘
549
+ ```
550
+
551
+ ### JSON Format
552
+ Readable JSON array with newlines (no metadata):
553
+ ```bash
554
+ tdx query "SELECT name, age FROM users LIMIT 2" --format json
555
+ ```
556
+ ```json
557
+ [
558
+ {"name":"Alice","age":25},
559
+ {"name":"Bob","age":30}
560
+ ]
561
+ ```
562
+
563
+ Each object is compact (single line) but separated by newlines for readability.
564
+
565
+ Perfect for piping to `jq`:
566
+ ```bash
567
+ tdx query "SELECT * FROM users" --format json | jq '.[0]'
568
+ tdx query "SELECT * FROM users" --format json | jq 'length'
569
+ ```
570
+
571
+ ### JSON Lines Format (jsonl)
572
+ One JSON object per line - ideal for streaming and line-by-line processing:
573
+ ```bash
574
+ tdx query "SELECT name, age FROM users LIMIT 2" --format jsonl
575
+ ```
576
+ ```
577
+ {"name":"Alice","age":25}
578
+ {"name":"Bob","age":30}
579
+ ```
580
+
581
+ Process line by line:
582
+ ```bash
583
+ tdx query "SELECT * FROM users" --format jsonl | while read line; do
584
+ echo "$line" | jq '.name'
585
+ done
586
+ ```
587
+
588
+ ### TSV Format
589
+ Tab-separated values with header row:
590
+ ```bash
591
+ tdx query "SELECT name, age FROM users LIMIT 2" --format tsv
592
+ ```
593
+ ```
594
+ name age
595
+ Alice 25
596
+ Bob 30
597
+ ```
598
+
599
+ ### Color Output
600
+
601
+ `tdx` automatically adds ANSI colors to output in interactive terminals to improve readability:
602
+
603
+ **Table format:**
604
+ - Table borders: Dark gray (dim)
605
+ - Column headers: Plain text (no color)
606
+ - Type row: Dim gray
607
+ - Data values: Plain text (no color)
608
+
609
+ **JSON format:**
610
+ - Keys: Blue
611
+ - Strings: Green
612
+ - Numbers: Cyan
613
+ - Booleans: Yellow
614
+ - Null values: Dim
615
+
616
+ **JSONL format:**
617
+ - Same color scheme as JSON format
618
+ - Compact one-line-per-object output with colors in interactive terminals
619
+
620
+ **Automatic detection:**
621
+ - Colors are enabled automatically when output is to an interactive terminal (TTY)
622
+ - Colors are disabled automatically when:
623
+ - Output is piped to another command
624
+ - Output is saved to a file with `--output`
625
+ - Respects the `NO_COLOR` environment variable (see https://no-color.org/)
626
+
627
+ **Manual control:**
628
+ ```bash
629
+ # Force colors on (even when piping or saving to file)
630
+ tdx databases --color
631
+ tdx databases --color --output results.txt
632
+
633
+ # Disable colors (even in interactive terminal)
634
+ tdx databases --no-color
635
+
636
+ # Disable colors via environment variable
637
+ NO_COLOR=1 tdx databases
638
+ ```
639
+
640
+ **Priority order:**
641
+ 1. `--no-color` flag (highest priority)
642
+ 2. `--color` flag
643
+ 3. `NO_COLOR` environment variable
644
+ 4. TTY detection (automatic)
645
+
646
+
647
+ ## Development
648
+
649
+ ```bash
650
+ # Install dependencies
651
+ npm install
652
+
653
+ # Run in development mode
654
+ npm run dev
655
+
656
+ # Build
657
+ npm run build
658
+
659
+ # Run tests
660
+ npm test
661
+
662
+ # Type checking
663
+ npm run typecheck
664
+
665
+ # Linting
666
+ npm run lint
667
+
668
+ # Format code
669
+ npm run format
670
+ ```
671
+
672
+ ## Requirements
673
+
674
+ - **Node.js 22.0.0 or higher** (Node.js 24 Active LTS recommended for development)
675
+ - TD API key with appropriate permissions
676
+
677
+ ## Architecture
678
+
679
+ - **Language**: TypeScript 5.x
680
+ - **Runtime**: Node.js 24+
681
+ - **CLI Framework**: Commander.js
682
+ - **Testing**: Vitest
683
+ - **Distribution**: NPM package
684
+
685
+ ## Security
686
+
687
+ - API keys stored in `~/.config/tdx/.env`
688
+ - All authorization enforced server-side via API key permissions
689
+ - Safe mode with confirmation prompts for destructive operations
690
+
691
+ ## License
692
+
693
+ Apache-2.0
694
+
695
+ ## Contributing
696
+
697
+ This project is maintained by the Treasure Data DevAI Unit.
698
+
699
+ For issues and feature requests, please visit:
700
+ https://github.com/treasure-data/tdx/issues
701
+
702
+ ## Related Documentation
703
+
704
+ - **ERD**: [New TD CLI (tdx) for AI Compatibility](https://system-docs.treasuredata.com/design-notes/2025/10/31/ERD/tdx-cli) (TD internal-only)
705
+ - **ADD**: [New TD CLI for AI Compatibility](https://system-docs.treasuredata.com/design-notes/2025/10/29/ADD/treasure-cli-ai-compatibility) (TD internal-only)
706
+ - **JIRA**: [DEVAI-374](https://treasure-data.atlassian.net/browse/DEVAI-374)