-
Notifications
You must be signed in to change notification settings - Fork 3
/
send-presto-query.sh
executable file
·71 lines (62 loc) · 1.67 KB
/
send-presto-query.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
set -euo pipefail
function usage() {
CMDNAME="$(basename -- "$0")"
echo """
Usage: ${CMDNAME} <sql>
Sends a SQL query to the Presto cluster and waits for the result.
"""
}
if [[ ! "$#" -eq 1 ]]; then
echo "You must provide exactly one argument."
usage
exit 1
fi
function send_query {
SQL="${1}"
RESPONSE="$(docker-compose run --rm -e KRB5_TRACE=/dev/null machine-example-com bash -c "
kinit -k [email protected] &>/dev/null;
curl -X POST \
--insecure \
--negotiate \
-u : \
'https://presto-kerberos:7778/v1/statement' \
--data ${SQL@Q}
")"
echo "RESPONSE=${RESPONSE}"
NEXT_URL="$(echo "${RESPONSE}"| jq -r .nextUri)"
STATE="$(echo "${RESPONSE}" | jq -r .stats.state)"
echo "${RESPONSE}" | jq .
while [[ "${STATE}" == "QUEUED" ]]; do
RESPONSE="$(docker-compose run --rm -e KRB5_TRACE=/dev/null machine-example-com bash -c "
kinit -k [email protected] &>/dev/null;
curl -X GET \
--insecure \
--negotiate \
-u : \
${NEXT_URL@Q}
")"
STATE="$(echo "${RESPONSE}" | jq -r .stats.state)"
NEXT_URL="$(echo "${RESPONSE}" | jq -r .nextUri)"
echo "${RESPONSE}" | jq .
done;
if [[ "${STATE}" == "FAILED" ]]; then
exit 1
fi
while [[ ! "${NEXT_URL}" == "null" ]]; do
RESPONSE="$(docker-compose run --rm -e KRB5_TRACE=/dev/null machine-example-com bash -c "
kinit -k [email protected] &>/dev/null;
curl -X GET \
--insecure \
--negotiate \
-u : \
${NEXT_URL@Q}
")"
NEXT_URL="$(echo "${RESPONSE}" | jq -r .nextUri)"
echo "${RESPONSE}" | jq .
done;
if [[ "${STATE}" == "FAILED" ]]; then
exit 1
fi
}
send_query "${1}"