Apache Drill > sqlline: how to run a sql script containing variable

3.3k Views Asked by At

I am a newbie of Apache Drill, and I need to run a SQL script through sqlline. In most SQL client, it is allowed to use some variables in sqlline, so hereby I would like to ask that is it possible to use variables in sqlline of Apache Drill?

2

There are 2 best solutions below

0
On

Someone asked a similar question on Drill user mailing list. Here is the answer from the same link:

You could achieve this by writing a wrapper script:

#!/bin/env bash
VARIABLE="testvalue"

SQL="SELECT '${VARIABLE}' from sys.version;"

sqlline -u jdbc:drill: -n cmatta -p xxxx <<< $SQL
0
On

Here's a real world example where I substitute all occurrences of the text 'staticLoadTime' in a drill file with the variable ${staticLoadTime} using sed and then pipe the result to sqlline. This avoids having to create a wrapper or other temporary file.

sed 's/staticLoadTime/${staticLoadTime}/g' ${Source}.drill | sqlline -u jdbc:drill:zk=local