Updated on 2024-08-16 GMT+08:00

Querying Impala Data

Function Description

This section describes how to use Impala SQL to query and analyze data. You can query and analyze data using the following methods:

  • Use common features of a SELECT query, such as JOIN.
  • Load data to a specified partition.
  • Use built-in functions of Impala.
  • Query and analyze data using user-defined functions. For details about how to create and define functions, see Developing User-Defined Impala Functions.

Sample Code

-- Query contact information of employees whose salaries are paid in USD.
SELECT  
a.name,  
b.tel_phone,  
b.email  
FROM employees_info a JOIN employees_contact b  ON(a.id = b.id) WHERE usd_flag='D'; 
 
-- Query the IDs and names of employees who were hired in 2014, and load the query results to the partition with the hire date of 2014 in the employees_info_extended table.
INSERT OVERWRITE TABLE employees_info_extended PARTITION (entrytime = '2014')  
SELECT  
a.id,  
a.name,  
a.usd_flag,  
a.salary,  
a.deductions,  
a.address, 
b.tel_phone, 
b.email  
FROM employees_info a JOIN employees_contact b ON (a.id = b.id) WHERE a.entrytime = '2014'; 
 
-- Use the existing function COUNT() in Impala to calculate the number of records in the employees_info table.
SELECT COUNT(*) FROM employees_info; 
 
-- Query information about employees whose email addresses end with "cn".
SELECT a.name, b.tel_phone FROM  employees_info a JOIN employees_contact b ON (a.id = b.id) WHERE b.email like '%cn'; 

Extended Applications

For details about user-defined functions, see Developing User-Defined Impala Functions.