SET Statement

Specifies values for query options that control the runtime behavior of other statements within the same session.

In Impala 2.5 and higher, SET also defines user-specified substitution variables for the impala-shell interpreter. This feature uses the SET command built into impala-shell instead of the SQL SET statement. Therefore the substitution mechanism only works with queries processed by impala-shell, not with queries submitted through JDBC or ODBC.

Important:

In Impala 2.11 and higher, the output of the SET statement changes in some important ways:

  • The options are divided into groups: Regular Query Options, Advanced Query Options, Development Query Options, and Deprecated Query Options.

  • The advanced options are intended for use in specific kinds of performance tuning and debugging scenarios. The development options are related to internal development of Impala or features that are not yet finalized; these options might be changed or removed without notice. The deprecated options are related to features that are removed or changed so that the options no longer have any purpose; these options might be removed in future versions.

  • By default, only the first two groups (regular and advanced) are displayed by the SET command. Use the syntax SET ALL to see all groups of options.

  • impala-shell options and user-specified variables are always displayed at the end of the list of query options, after all appropriate option groups.

  • When the SET command is run through the JDBC or ODBC interfaces, the result set has a new third column, level, indicating which group each option belongs to. The same distinction of SET returning the regular and advanced options, and SET ALL returning all option groups, applies to JDBC and ODBC also.

Syntax:

  1. SET [query_option=option_value]
  2. SET ALL

SET and SET ALL with no arguments return a result set consisting of all the applicable query options and their current values.

The query option name and any string argument values are case-insensitive.

Each query option has a specific allowed notation for its arguments. Boolean options can be enabled and disabled by assigning values of either true and false, or 1 and 0. Some numeric options accept a final character signifying the unit, such as 2g for 2 gigabytes or 100m for 100 megabytes. See Query Options for the SET Statement for the details of each query option.

Setting query options during impala-shell invocation:

In Impala 2.11 and higher, you can use one or more command-line options of the form --query_option=option=value when running the impala-shell command. The corresponding query option settings take effect for that impala-shell session.

User-specified substitution variables:

In Impala 2.5 and higher, you can specify your own names and string substitution values within the impala-shell interpreter. Once a substitution variable is set up, its value is inserted into any SQL statement in that same impala-shell session that contains the notation ${var:varname}. Using SET in an interactive impala-shell session overrides any value for that same variable passed in through the --var=varname=value command-line option.

For example, to set up some default parameters for report queries, but then override those default within an impala-shell session, you might issue commands and statements such as the following:

  1. -- Initial setup for this example.
  2. create table staging_table (s string);
  3. insert into staging_table values ('foo'), ('bar'), ('bletch');
  4. create table production_table (s string);
  5. insert into production_table values ('North America'), ('EMEA'), ('Asia');
  6. quit;
  7. -- Start impala-shell with user-specified substitution variables,
  8. -- run a query, then override the variables with SET and run the query again.
  9. $ impala-shell --var=table_name=staging_table --var=cutoff=2
  10. ... banner message ...
  11. [localhost:21000] > select s from ${var:table_name} order by s limit ${var:cutoff};
  12. Query: select s from staging_table order by s limit 2
  13. +--------+
  14. | s |
  15. +--------+
  16. | bar |
  17. | bletch |
  18. +--------+
  19. Fetched 2 row(s) in 1.06s
  20. [localhost:21000] > set var:table_name=production_table;
  21. Variable TABLE_NAME set to production_table
  22. [localhost:21000] > set var:cutoff=3;
  23. Variable CUTOFF set to 3
  24. [localhost:21000] > select s from ${var:table_name} order by s limit ${var:cutoff};
  25. Query: select s from production_table order by s limit 3
  26. +---------------+
  27. | s |
  28. +---------------+
  29. | Asia |
  30. | EMEA |
  31. | North America |
  32. +---------------+

The following example shows how SET ALL with no parameters displays all user-specified substitution variables, and how UNSET removes the substitution variable entirely:

  1. [localhost:21000] > set all;
  2. Query options (defaults shown in []):
  3. ABORT_ON_ERROR: [0]
  4. COMPRESSION_CODEC: []
  5. DISABLE_CODEGEN: [0]
  6. ...
  7. Advanced Query Options:
  8. APPX_COUNT_DISTINCT: [0]
  9. BUFFER_POOL_LIMIT: []
  10. DEFAULT_JOIN_DISTRIBUTION_MODE: [0]
  11. ...
  12. Development Query Options:
  13. BATCH_SIZE: [0]
  14. DEBUG_ACTION: []
  15. DECIMAL_V2: [0]
  16. ...
  17. Deprecated Query Options:
  18. ABORT_ON_DEFAULT_LIMIT_EXCEEDED: [0]
  19. ALLOW_UNSUPPORTED_FORMATS: [0]
  20. DEFAULT_ORDER_BY_LIMIT: [-1]
  21. ...
  22. Shell Options
  23. LIVE_PROGRESS: False
  24. LIVE_SUMMARY: False
  25. Variables:
  26. CUTOFF: 3
  27. TABLE_NAME: staging_table
  28. [localhost:21000] > unset var:cutoff;
  29. Unsetting variable CUTOFF
  30. [localhost:21000] > select s from ${var:table_name} order by s limit ${var:cutoff};
  31. Error: Unknown variable CUTOFF

See Running Commands and SQL Statements in impala-shell for more examples of using the --var, SET, and ${var:varname} substitution technique in impala-shell.

Usage notes:

MEM_LIMIT is probably the most commonly used query option. You can specify a high value to allow a resource-intensive query to complete. For testing how queries would work on memory-constrained systems, you might specify an artificially low value.

Complex type considerations:

Examples:

The following example sets some numeric and some Boolean query options to control usage of memory, disk space, and timeout periods, then runs a query whose success could depend on the options in effect:

  1. set mem_limit=64g;
  2. set DISABLE_UNSAFE_SPILLS=true;
  3. set parquet_file_size=400m;
  4. set RESERVATION_REQUEST_TIMEOUT=900000;
  5. insert overwrite parquet_table select c1, c2, count(c3) from text_table group by c1, c2, c3;

Added in: Impala 2.0.0

SET has always been available as an impala-shell command. Promoting it to a SQL statement lets you use this feature in client applications through the JDBC and ODBC APIs.

Cancellation: Cannot be cancelled.

HDFS permissions: This statement does not touch any HDFS files or directories, therefore no HDFS permissions are required.

Related information:

See Query Options for the SET Statement for the query options you can adjust using this statement.

Parent topic: Impala SQL Statements