Commit 42e344b
authored
Experimental postgres query (PR 2/4): provisioned + JSON/CSV streaming + types (#5136)
## PR Stack
1. [#5135](#5135) — PR 1: scaffold
+ autoscaling targeting + text output
2. **PR 2 (this PR)** —
[#5136](#5136) — provisioned +
JSON/CSV streaming + typed values + `experimental/libs/sqlcli` for
output handling
3. [#5138](#5138) — PR 3:
multi-input + multi-statement rejection + error formatting
4. [#5143](#5143) — PR 4:
cancellation + timeout + TUI
Stacked on PR 1.
## Why
Two things in this PR. The user-facing one: postgres query learns
JSON/CSV streaming and provisioned-instance support. The architectural
one: aitools query and postgres query had near-identical output-mode
handling (same env var, same flag/env precedence, same threshold).
Promote the duplication to a shared `experimental/libs/sqlcli` package
before the second consumer ossifies the divergence.
## Changes
**Architectural:** `experimental/libs/sqlcli/` is a new package under
`experimental/libs/` (not `libs/`) so it inherits the
experimental-stability guarantee of its consumers. Exposes:
- `sqlcli.EnvOutputFormat`, `sqlcli.StaticTableThreshold` constants.
- `sqlcli.Format` typedef + `sqlcli.OutputText/JSON/CSV` consts +
`sqlcli.AllFormats`.
- `sqlcli.ResolveFormat` — flag > env > default precedence with the
explicit-text-on-pipe-is-honoured rule.
aitools query migrates to use sqlcli (pure refactor, no behavior
change). postgres query was about to add its own copy of all of this;
instead it uses sqlcli from day one.
**User-facing changes for postgres query:**
- `--target my-instance` now resolves a provisioned instance.
- `--output json` streams typed values: numbers stay numeric, jsonb
stays nested, NaN/Inf/bigints-outside-2^53 become strings.
- `--output csv` streams (no buffering).
- `DATABRICKS_OUTPUT_FORMAT` honoured.
- Auto-fallback to JSON when stdout is piped.
- Duplicate column names get deterministic `__N` suffixes with a stderr
warning.
Also adds `cmdio.IsOutputTTY` (a small public wrapper around the
existing private `isTTY`) so commands can ask "is stdout a terminal?"
without folding in `NO_COLOR` / `TERM=dumb` (both of which
`cmdio.SupportsColor` ANDs in for the colour-rendering decision).
## Test plan
- [x] `go test ./experimental/aitools/... ./experimental/postgres/...
./experimental/libs/...` (unit, sinks, value mapping, format selection,
aitools tests still pass after migration)
- [x] `go tool ... golangci-lint run ./experimental/...` (0 issues)1 parent fadaebc commit 42e344b
17 files changed
Lines changed: 1340 additions & 163 deletions
File tree
- experimental
- aitools/cmd
- libs/sqlcli
- postgres/cmd
- internal/target
- libs/cmdio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 37 | | |
49 | 38 | | |
50 | 39 | | |
| |||
55 | 44 | | |
56 | 45 | | |
57 | 46 | | |
58 | | - | |
59 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
60 | 54 | | |
61 | 55 | | |
62 | 56 | | |
| |||
67 | 61 | | |
68 | 62 | | |
69 | 63 | | |
70 | | - | |
| 64 | + | |
71 | 65 | | |
72 | 66 | | |
73 | 67 | | |
| |||
119 | 113 | | |
120 | 114 | | |
121 | 115 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
140 | 125 | | |
141 | 126 | | |
142 | 127 | | |
| |||
146 | 131 | | |
147 | 132 | | |
148 | 133 | | |
149 | | - | |
| 134 | + | |
150 | 135 | | |
151 | 136 | | |
152 | 137 | | |
| |||
173 | 158 | | |
174 | 159 | | |
175 | 160 | | |
176 | | - | |
| 161 | + | |
177 | 162 | | |
178 | 163 | | |
179 | 164 | | |
| |||
190 | 175 | | |
191 | 176 | | |
192 | 177 | | |
193 | | - | |
| 178 | + | |
194 | 179 | | |
195 | 180 | | |
196 | 181 | | |
| |||
206 | 191 | | |
207 | 192 | | |
208 | 193 | | |
209 | | - | |
| 194 | + | |
210 | 195 | | |
211 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
212 | 201 | | |
213 | 202 | | |
214 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | | - | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
| 274 | + | |
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
| 298 | + | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
| 301 | + | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
| 306 | + | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
| 314 | + | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
| 324 | + | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
0 commit comments