#!/usr/bin/env bash
# spark-sql — interactive SQL shell wrapper.
#
# Just exec's the Rust binary built by the spark-cli crate, with a
# fallback to debug build if release isn't available.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BIN="$ROOT/target/release/spark-sql"
if [[ ! -x "$BIN" ]]; then
    BIN="$ROOT/target/debug/spark-sql"
fi
if [[ ! -x "$BIN" ]]; then
    echo "==> building spark-sql (one-time, debug)" >&2
    (cd "$ROOT" && cargo build -q -p spark-cli --bin spark-sql) >&2
    BIN="$ROOT/target/debug/spark-sql"
fi
exec "$BIN" "$@"
