Skip to content

Commit 1dd4994

Browse files
committed
GizmoSQL: split benchmark.sh + use gizmosql_client (depends on #860)
Adopts the per-system 7-script interface from #860 for gizmosql/, and replaces the Java sqlline-based gizmosqlline client with the C++ gizmosql_client shell that ships with gizmosql_server. Scripts (matching the contract from lib/benchmark-common.sh): benchmark.sh - 4-line shim that exec's ../lib/benchmark-common.sh install - apt + curl gizmosql_cli_linux_$ARCH.zip; no openjdk, no separate gizmosqlline download start - idempotent server bring-up (skips if port 31337 is open) check - cheap TCP probe (auth-gated SQL would need credentials) stop - kills tracked PID; pkill belt-and-braces fallback load - rm -f clickbench.db, then create.sql + load.sql via gizmosql_client; deletes hits.parquet and sync's query - reads one query from stdin, runs via gizmosql_client with .timer on + .mode trash; emits fractional seconds as the last stderr line (parsed from "Run Time: X.XXs") data-size - wc -c clickbench.db Notes: - BENCH_DOWNLOAD_SCRIPT=download-hits-parquet-single, BENCH_RESTARTABLE=yes (gizmosql is a server, so per-query restart neutralizes warm-process effects, matching the clickhouse/postgres pattern in #860). - util.sh now exports GIZMOSQL_HOST/PORT/USER/PASSWORD - the env vars gizmosql_client reads natively, so query/load can call gizmosql_client with no flags. The server still receives the username via --username. - PID_FILE moved to a stable /tmp path (was /tmp/gizmosql_server_$$.pid, which broke across the start/stop process boundary in the new layout). This PR depends on #860 (which introduces lib/benchmark-common.sh and the contract). Once #860 lands, this PR's diff against main will be only the gizmosql/ files. Validated locally on macOS with gizmosql v1.22.4: the query script produces the expected fractional-seconds last line on stdout/stderr separation, and exits non-zero on error paths. See https://docs.gizmosql.com/#/client for gizmosql_client docs.
1 parent a6fe952 commit 1dd4994

10 files changed

Lines changed: 132 additions & 136 deletions

File tree

gizmosql/benchmark.sh

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,5 @@
11
#!/bin/bash
2-
3-
# needed by DuckDB
4-
export HOME=/home/ubuntu
5-
6-
# Install requirements
7-
apt-get update -y
8-
apt install openjdk-17-jre-headless unzip netcat-openbsd -y
9-
10-
# Detect architecture (maps x86_64->amd64, aarch64->arm64)
11-
ARCH=$(uname -m)
12-
if [ "$ARCH" = "x86_64" ]; then
13-
ARCH="amd64"
14-
elif [ "$ARCH" = "aarch64" ]; then
15-
ARCH="arm64"
16-
fi
17-
18-
# Server setup Install
19-
curl -L -o gizmosql.zip "https://github.com/gizmodata/gizmosql/releases/latest/download/gizmosql_cli_linux_${ARCH}.zip"
20-
unzip gizmosql.zip
21-
mv gizmosql_server gizmosql_client /usr/local/bin/
22-
23-
# Install Java and the GizmoSQLLine CLI client
24-
pushd /tmp
25-
curl -L -o gizmosqlline https://github.com/gizmodata/gizmosqlline/releases/latest/download/gizmosqlline
26-
chmod +x gizmosqlline
27-
mv gizmosqlline /usr/local/bin/
28-
popd
29-
30-
# Source our env vars and utility functions for starting/stopping gizmosql server
31-
. util.sh
32-
33-
# Start the GizmoSQL server in the background
34-
start_gizmosql
35-
36-
# Create the table
37-
gizmosqlline \
38-
-u ${GIZMOSQL_SERVER_URI} \
39-
-n ${GIZMOSQL_USERNAME} \
40-
-p ${GIZMOSQL_PASSWORD} \
41-
-f create.sql
42-
43-
# Load the data
44-
../download-hits-parquet-single
45-
46-
echo -n "Load time: "
47-
time gizmosqlline \
48-
-u ${GIZMOSQL_SERVER_URI} \
49-
-n ${GIZMOSQL_USERNAME} \
50-
-p ${GIZMOSQL_PASSWORD} \
51-
-f load.sql
52-
53-
stop_gizmosql
54-
55-
# Run the queries
56-
./run.sh 2>&1 | tee log.txt
57-
58-
# Remove carriage returns from the log
59-
sed -i 's/\r$//' log.txt
60-
61-
echo -n "Data size: "
62-
wc -c clickbench.db
63-
64-
cat log.txt | \
65-
grep -E 'rows? selected \([0-9.]+ seconds\)|Killed|Segmentation' | \
66-
sed -E 's/.*rows? selected \(([0-9.]+) seconds\).*/\1/; s/.*(Killed|Segmentation).*/null/' | \
67-
awk '{
68-
if (NR % 3 == 1) printf "[";
69-
if ($1 == "null") printf "null";
70-
else printf $1;
71-
if (NR % 3 == 0) printf "],\n";
72-
else printf ", ";
73-
}'
2+
# Thin shim — actual flow is in lib/benchmark-common.sh.
3+
export BENCH_DOWNLOAD_SCRIPT="download-hits-parquet-single"
4+
export BENCH_RESTARTABLE=yes
5+
exec ../lib/benchmark-common.sh

gizmosql/check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
. ./util.sh
5+
6+
# A simple TCP probe is the cheapest health check; the Arrow Flight SQL
7+
# endpoint is auth-gated, so we just check the listener is up.
8+
exec nc -z "${GIZMOSQL_HOST}" "${GIZMOSQL_PORT}"

gizmosql/data-size

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
wc -c < clickbench.db | awk '{print $1}'

gizmosql/install

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
sudo apt-get update -y
5+
sudo apt-get install -y unzip netcat-openbsd curl
6+
7+
ARCH=$(uname -m)
8+
if [ "$ARCH" = "x86_64" ]; then
9+
ARCH="amd64"
10+
elif [ "$ARCH" = "aarch64" ]; then
11+
ARCH="arm64"
12+
fi
13+
14+
# gizmosql_client and gizmosql_server ship together in the same archive.
15+
if ! command -v gizmosql_server >/dev/null 2>&1; then
16+
curl -L -o gizmosql.zip \
17+
"https://github.com/gizmodata/gizmosql/releases/latest/download/gizmosql_cli_linux_${ARCH}.zip"
18+
unzip -o gizmosql.zip
19+
sudo mv gizmosql_server gizmosql_client /usr/local/bin/
20+
fi

gizmosql/load

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
. ./util.sh
5+
6+
# Idempotent: blow away any prior database.
7+
rm -f clickbench.db
8+
9+
# Server must be up; gizmosql_client picks up GIZMOSQL_HOST/PORT/USER/PASSWORD
10+
# from the environment.
11+
gizmosql_client --file create.sql
12+
gizmosql_client --file load.sql
13+
14+
rm -f hits.parquet
15+
sync

gizmosql/query

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# Reads a SQL query from stdin, runs it via gizmosql_client.
3+
# Stdout: query result (empty in trash mode plus a row-count summary).
4+
# Stderr: query runtime in fractional seconds on the last line, parsed from
5+
# gizmosql_client's "Run Time: X.XXs" line emitted by .timer on.
6+
# Exit non-zero on error.
7+
set -e
8+
9+
. ./util.sh
10+
query=$(cat)
11+
12+
err_file=$(mktemp)
13+
trap 'rm -f "$err_file"' EXIT
14+
15+
# .timer on -> emits "Run Time: <seconds>s" to stderr after each statement.
16+
# .mode trash -> discards rows; we only care about the timing.
17+
out=$(printf '.timer on\n.mode trash\n%s\n' "$query" | gizmosql_client 2>"$err_file") \
18+
&& exit_code=0 || exit_code=$?
19+
20+
err=$(<"$err_file")
21+
clean_out=$(printf '%s\n' "$out" | tr -d '\r')
22+
clean_err=$(printf '%s\n' "$err" | tr -d '\r')
23+
24+
if [ "$exit_code" -ne 0 ] \
25+
|| printf '%s\n' "$clean_err" | grep -qiE 'error|exception|Killed|Segmentation'; then
26+
printf '%s\n' "$clean_out"
27+
printf '%s\n' "$clean_err" >&2
28+
exit 1
29+
fi
30+
31+
printf '%s\n' "$clean_out"
32+
33+
secs=$(printf '%s\n' "$clean_err" \
34+
| grep -oE 'Run Time: [0-9.]+s' \
35+
| tail -n1 \
36+
| sed -E 's/Run Time: ([0-9.]+)s/\1/')
37+
38+
if [ -z "$secs" ]; then
39+
echo "no Run Time in gizmosql_client output" >&2
40+
exit 1
41+
fi
42+
43+
awk -v s="$secs" 'BEGIN { printf "%.3f\n", s }' >&2

gizmosql/run.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

gizmosql/start

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
. ./util.sh
5+
6+
# Idempotent: if the server is already up, do nothing.
7+
if nc -z "${GIZMOSQL_HOST}" "${GIZMOSQL_PORT}" 2>/dev/null; then
8+
exit 0
9+
fi
10+
11+
start_gizmosql

gizmosql/stop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
. ./util.sh
4+
stop_gizmosql || true
5+
6+
# Belt-and-braces: kill any leftover gizmosql_server process.
7+
pkill -x gizmosql_server 2>/dev/null || true

gizmosql/util.sh

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
#!/bin/bash
22

3-
# Variables
4-
GIZMOSQL_SERVER_URI="jdbc:arrow-flight-sql://localhost:31337?useEncryption=false"
5-
GIZMOSQL_USERNAME=clickbench
6-
GIZMOSQL_PASSWORD=clickbench
7-
PID_FILE="/tmp/gizmosql_server_$$.pid"
3+
# Env-var names match what gizmosql_client recognizes natively, so the
4+
# query/load scripts can invoke gizmosql_client without explicit flags.
5+
# (The server's own username env var is GIZMOSQL_USERNAME — we pass it
6+
# explicitly via --username.)
7+
export GIZMOSQL_HOST=localhost
8+
export GIZMOSQL_PORT=31337
9+
export GIZMOSQL_USER=clickbench
10+
export GIZMOSQL_PASSWORD=clickbench
811

9-
# Function to start the GizmoSQL server
10-
start_gizmosql() {
11-
export GIZMOSQL_PASSWORD="${GIZMOSQL_PASSWORD}"
12+
# Stable PID path: start and stop run in different bash processes, so $$ won't
13+
# match between them.
14+
PID_FILE=/tmp/gizmosql_server.pid
1215

16+
start_gizmosql() {
1317
nohup gizmosql_server \
14-
--username ${GIZMOSQL_USERNAME} \
18+
--username "${GIZMOSQL_USER}" \
1519
--database-filename clickbench.db \
1620
--print-queries >> gizmosql_server.log 2>&1 &
1721

1822
echo $! > "${PID_FILE}"
1923

20-
# Wait for server to be ready
21-
echo "Waiting for gizmosql_server to start..."
22-
while ! nc -z localhost 31337 2>/dev/null; do
24+
echo "Waiting for gizmosql_server to start..." >&2
25+
while ! nc -z "${GIZMOSQL_HOST}" "${GIZMOSQL_PORT}" 2>/dev/null; do
2326
sleep 1
2427
done
25-
echo "gizmosql_server is ready (PID: $(cat ${PID_FILE}))"
28+
echo "gizmosql_server is ready (PID: $(cat ${PID_FILE}))" >&2
2629
}
2730

28-
# Function to stop the GizmoSQL server
2931
stop_gizmosql() {
3032
if [ -f "${PID_FILE}" ]; then
31-
local pid=$(cat "${PID_FILE}")
33+
local pid
34+
pid=$(cat "${PID_FILE}")
3235
if kill -0 "$pid" 2>/dev/null; then
33-
echo "Stopping gizmosql_server (PID: $pid)..."
36+
echo "Stopping gizmosql_server (PID: $pid)..." >&2
3437
kill "$pid"
35-
wait "$pid" 2>/dev/null
38+
wait "$pid" 2>/dev/null || true
3639
fi
3740
rm -f "${PID_FILE}"
3841
fi

0 commit comments

Comments
 (0)