mirror of
https://github.com/apache/impala.git
synced 2025-12-25 11:04:13 -05:00
The SET command has been extended with the following syntax, to allow setting of variables in the Impala Shell: SET VAR:<variable_name>=<value> The UNSET command has also been modified to allow: UNSET VAR:<variable_name> This patch builds on the changes in IMPALA-2179. The main change for this patch was to ensure that all SET commands are processed by the shell, rather than being send to the front end as a query. For this I had to modify the command sanitization function to remove comments that happen in front of a SET command. Comments can be a can of worms to parse, so I tried to be as strict as possible to avoid collateral effects. Comments are only removed if they happen right at the beginning of the line AND before a SET command. NO other comments are touched, including comments before, after or within queries. Change-Id: I87e07385122187ab8d324346499896a3dfbbafe6 Reviewed-on: http://gerrit.cloudera.org:8080/679 Reviewed-by: Casey Ching <casey@cloudera.com> Tested-by: Internal Jenkins
41 lines
1.1 KiB
SQL
41 lines
1.1 KiB
SQL
-- Test substitution of command line argument
|
|
SELECT 'foo_number=' as name, 123${var:foo} as result;
|
|
SELECT 'foo_string=${var:foo}' as result;
|
|
-- Show set variables
|
|
SET;
|
|
-- Invalid variable reference
|
|
SELECT 'invalid_ref=${random_name}' as result;
|
|
-- Set variable
|
|
SET Var:myvar=foo123;
|
|
-- Use variable
|
|
SELECT 'var_test=${VAR:MYVAR}' as result;
|
|
-- Reference non-existing variables and options
|
|
SELECT 'missing_var_test=${var:foo1}${VAR:foo2}' as result;
|
|
-- Multiple replacements of the same variable
|
|
SELECT 'multi_test=${hivevar:BAR}_${var:Foo}_${var:BaR}_${HIVEvar:FOO}' as result;
|
|
-- Escaping variable substitution
|
|
SELECT 'This should be not replaced: \${VAR:foo} \${HIVEVAR:bar}';
|
|
-- Show set variables
|
|
SET;
|
|
-- Unset variables
|
|
UNSET VAR:foo;
|
|
UNSET VAR:BAR;
|
|
UNSET VAR:MyVar;
|
|
UNSET VAR:NonExistent;
|
|
-- Verify that all variables were unset
|
|
SET;
|
|
-- Test dash-dash comment removal
|
|
-- Multiple comments
|
|
-- multiple lines
|
|
SET var:comment_type1=ok;
|
|
/* Test removal
|
|
of this type of
|
|
comments */ SET var:comment_type2=ok;
|
|
-- Test the
|
|
/* -- removal */ -- of
|
|
-- multiple comments */
|
|
set var:comment_type3=ok;
|
|
-- Check values
|
|
SET;
|
|
quit;
|