Commit 730d375
[SPARK-55756][SQL][TESTS] Add --DEBUG directive for golden file test framework
### What changes were proposed in this pull request?
Add a `--DEBUG` marker directive for the SQL golden file test framework (`SQLQueryTestSuite`). When placed on its own line before a query in an input `.sql` file, it enables a focused debug mode:
- **Selective execution**: Only `--DEBUG`-marked queries and setup commands (CREATE TABLE, INSERT, SET, etc.) are executed; all other queries are skipped.
- **Full error details**: Failed queries print the complete stacktrace to the console.
- **Golden comparison**: Results are still compared against the golden file so you can verify correctness.
- **Safety net**: The test always fails at the end with a reminder to remove `--DEBUG` markers before committing.
- **DataFrame access**: Documentation guides users to set a breakpoint in `runDebugQueries` to inspect the `DataFrame` instance for ad-hoc plan analysis.
Example usage in an input file:
```sql
CREATE TABLE t (id INT, val INT) USING parquet;
INSERT INTO t VALUES (1, 10), (2, 20);
-- this query is skipped in debug mode
SELECT count(*) FROM t;
-- this is the query I'm debugging
--DEBUG
SELECT sum(val) OVER (ORDER BY id) FROM t;
```
Example console output when running the test:
```
=== DEBUG: Query #3 ===
SQL: SELECT sum(val) OVER (ORDER BY id) FROM t
Golden answer: matches
```
When the debug query fails:
```
=== DEBUG: Query #3 ===
SQL: SELECT sum(val) OVER (ORDER BY id) FROM t
org.apache.spark.sql.AnalysisException: [ERROR_CLASS] ...
at org.apache.spark.sql.catalyst.analysis...
at ...
Golden answer: matches
```
### Why are the changes needed?
Debugging golden file test failures is currently painful:
1. You must run all queries even if only one needs debugging.
2. Error output is minimal (just the error class/message), with no stacktrace.
3. There is no way to access the `DataFrame` instance for plan inspection.
This change addresses all three issues with a simple, zero-config marker that can be temporarily added during development.
### Does this PR introduce _any_ user-facing change?
No. This is a test infrastructure improvement only.
### How was this patch tested?
- Manually tested with `--DEBUG` markers on both passing and failing queries in `inline-table.sql`.
- Verified backward compatibility: tests pass normally when no `--DEBUG` markers are present.
- Verified debug mode output includes full stacktraces, golden answer comparison, and the safety-fail message.
### Was this patch authored or co-authored using generative AI tooling?
Yes. cursor
Closes #54554 from cloud-fan/golden.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Kent Yao <kentyao@microsoft.com>1 parent 959cc95 commit 730d375
2 files changed
Lines changed: 176 additions & 17 deletions
File tree
- sql/core/src/test/scala/org/apache/spark/sql
Lines changed: 20 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
| 403 | + | |
| 404 | + | |
404 | 405 | | |
405 | 406 | | |
406 | | - | |
407 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
408 | 413 | | |
409 | 414 | | |
410 | 415 | | |
| |||
450 | 455 | | |
451 | 456 | | |
452 | 457 | | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
457 | 470 | | |
458 | 471 | | |
459 | 472 | | |
| |||
Lines changed: 156 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
| |||
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
95 | 116 | | |
96 | 117 | | |
97 | 118 | | |
| |||
232 | 253 | | |
233 | 254 | | |
234 | 255 | | |
235 | | - | |
| 256 | + | |
236 | 257 | | |
| 258 | + | |
237 | 259 | | |
238 | | - | |
239 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
240 | 264 | | |
241 | 265 | | |
242 | 266 | | |
243 | | - | |
| 267 | + | |
244 | 268 | | |
245 | 269 | | |
246 | 270 | | |
| |||
287 | 311 | | |
288 | 312 | | |
289 | 313 | | |
290 | | - | |
291 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
292 | 319 | | |
293 | | - | |
294 | | - | |
295 | | - | |
| 320 | + | |
296 | 321 | | |
297 | 322 | | |
298 | 323 | | |
| |||
337 | 362 | | |
338 | 363 | | |
339 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
340 | 486 | | |
341 | 487 | | |
342 | 488 | | |
| |||
0 commit comments