Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 333
Rui Avatar asked Sep 15 '25 07:09

Rui


2 Answers

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
like image 178
adeneche Avatar answered Sep 18 '25 10:09

adeneche


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

like image 29
Victor Maywood Avatar answered Sep 18 '25 08:09

Victor Maywood