May 26, 2021 impala
The test operator in Impala is used to get unique values by removing duplicate values.
The following is the syntax of the test operator.
select distinct columns… from table_name;
Suppose we have a table called customers in Impala, which reads as follows -
[quickstart.cloudera:21000] > select distinct id, name, age, salary from customers; Query: select distinct id, name, age, salary from customers
Here you can observe the customer Ramesh and Chaitalli enter the salary twice, and using the test operator, we can select a unique value, as shown below.
[quickstart.cloudera:21000] > select distinct name, age, address from customers;
When executed, the above query gives the following output.
Query: select distinct id, name from customers +----------+-----+-----------+ | name | age | address | +----------+-----+-----------+ | Ramesh | 32 | Ahmedabad | | Khilan | 25 | Delhi | | kaushik | 23 | Kota | | Chaitali | 25 | Mumbai | | Hardik | 27 | Bhopal | | Komal | 22 | MP | +----------+-----+-----------+ Fetched 9 row(s) in 1.46s