Process final query without trailing newline - #1160
Conversation
|
Ok, but is it important? |
|
Yes. Two entries on main are affected: Turso and chdb-dataframe both have 43 queries but no final newline, so the current loop runs only 42. |
|
Query 43 is a distinct workload: a minute-level time-bucket aggregation over a date range. Skipping it removes all three cold/warm measurements for that query rather than merely affecting formatting. |
| # Read the same query file that bench_run_query consumed. | ||
| local queries=() q | ||
| while IFS= read -r q; do | ||
| while IFS= read -r q || [ -n "$q" ]; do |
There was a problem hiding this comment.
I'm trying to read this single line of code, and it is not obvious to me. Will it be an endless loop after consuming all results?
There was a problem hiding this comment.
read returns status 1 when it reaches EOF before a newline, but it still assigns the partial line to q. Since while A || B runs when either condition succeeds, [ -n "$q" ] is true for that final query and the body runs.
On the next condition check, the file descriptor is already at EOF. read returns 1 with no data and q becomes empty, so [ -n "$q" ] is also false. The while condition is therefore false and the loop exits.
Summary
Why
Bash
readfills the variable but returns a non-zero status when it reaches EOF before a newline. Since that status controls these loops, the last query was silently skipped for unterminated query files.Testing
bash -n lib/benchmark-common.shshellcheck lib/benchmark-common.sh