Impala Miscellaneous Functions
Impala supports the following utility functions that do not operate on a particular column or data type:
- CURREN_DATABASE()
- Purpose: Returns the database that the session is currently using, either default if no database has been selected, or
whatever database the session switched to through a USE statement or the impalad-d option.
Return type: STRING
- EFFECTIVE_USER()
- Purpose: Typically returns the same value as USER(), except if delegation is enabled, in which case it returns the ID of
the delegated user.
Return type: STRING
Added in: CDH 5.4.5 / Impala 2.2.5
- PID()
- Purpose: Returns the process ID of the impalad daemon that the session is connected to. You can use it during
low-level debugging, to issue Linux commands that trace, show the arguments, and so on the impalad process.
Return type: INT
- SLEEP(INT ms)
- Purpose: Pauses the query for a specified number of milliseconds. For slowing down queries with small result sets enough to monitor runtime execution,
memory usage, or other factors that otherwise would be difficult to capture during the brief interval of query execution. When used in the SELECT list, it is called
once for each row in the result set; adjust the number of milliseconds accordingly. For example, a query SELECT *, sleep(5) FROM table_with_1000_rows would take at
least 5 seconds to complete (5 milliseconds * 1000 rows in result set). To avoid an excessive number of concurrent queries, use this function for troubleshooting on test and development systems, not
for production queries.
Return type: N/A
- USER()
- Purpose: Returns the username of the Linux user who is connected to the impalad daemon. Typically called a single
time, in a query without any FROM clause, to understand how authorization settings apply in a security context; once you know the logged-in username, you can check
which groups that user belongs to, and from the list of groups you can check which roles are available to those groups through the authorization policy file.
Impala 2.0 and later, USER() returns the full Kerberos principal string, such as user@example.com, in a Kerberized environment.
When delegation is enabled, consider calling the effective_user() function instead.
Return type: STRING
- UUID()
- Purpose: Returns a universal unique identifier, a 128-bit value encoded as a string with groups of hexadecimal digits separated by dashes.
Return type: STRING
Added in: CDH 5.7.0 / Impala 2.5.0
Usage notes:
Ascending numeric sequences of type BIGINT are often used as identifiers within a table, and as join keys across multiple tables. The uuid() value is a convenient alternative that does not require storing or querying the highest sequence number. For example, you can use it to quickly construct new unique identifiers during a data import job, or to combine data from different tables without the likelihood of ID collisions.
Examples:
-- Each call to uuid() produces a new arbitrary value. select uuid(); +--------------------------------------+ | uuid() | +--------------------------------------+ | c7013e25-1455-457f-bf74-a2046e58caea | +--------------------------------------+ -- If you get a UUID for each row of a result set, you can use it as a -- unique identifier within a table, or even a unique ID across tables. select uuid() from four_row_table; +--------------------------------------+ | uuid() | +--------------------------------------+ | 51d3c540-85e5-4cb9-9110-604e53999e2e | | 0bb40071-92f6-4a59-a6a4-60d46e9703e2 | | 5e9d7c36-9842-4a96-862d-c13cd0457c02 | | cae29095-0cc0-4053-a5ea-7fcd3c780861 | +--------------------------------------+
- VERSION()
- Purpose: Returns information such as the precise version number and build date for the impalad daemon that you are
currently connected to. Typically used to confirm that you are connected to the expected level of Impala to use a particular feature, or to connect to several nodes and confirm they are all running
the same level of impalad.
Return type: STRING (with one or more embedded newlines)