-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathquery
More file actions
executable file
·28 lines (22 loc) · 865 Bytes
/
query
File metadata and controls
executable file
·28 lines (22 loc) · 865 Bytes
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
#!/bin/bash
# Reads a SQL query from stdin, runs it via datafusion-cli using create.sql
# to define the hits view, then the query.
# Stdout: query result.
# Stderr: query runtime in fractional seconds on the last line.
# Exit non-zero on error.
set -e
DF=arrow-datafusion/target/release/datafusion-cli
query=$(cat)
tmp=$(mktemp /tmp/datafusion.XXXXXX.sql)
trap 'rm -f "$tmp"' EXIT
printf '%s\n' "$query" > "$tmp"
out=$("$DF" -f create.sql "$tmp" 2>&1) && status=0 || status=$?
if [ "$status" -ne 0 ]; then
printf '%s\n' "$out" >&2
exit "$status"
fi
# Print everything that's not an "Elapsed" timing line as the result.
printf '%s\n' "$out" | grep -v 'Elapsed' || true
# datafusion-cli prints `... Elapsed X.YYY seconds.` for each statement; the
# last one is for the actual query.
printf '%s\n' "$out" | awk '/Elapsed/ { e = $2 } END { print e }' >&2