Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

impala restrictions


May 26, 2021 impala


Table of contents


The limit clause in Impala is used to limit the number of rows in the result set to the required number, that is, the result set of the query does not contain records that exceed the specified limit.

Grammar

The following is the syntax of the Limit clause in Impala.

select * from table_name order by id limit numerical_expression;

Cases

Suppose we have my_db table called customers in the database database, which reads as follows -

[quickstart.cloudera:21000] > select * from customers; 
Query: select * from customers 
+----+----------+-----+-----------+--------+ 
| id | name     | age | address   | salary | 
+----+----------+-----+-----------+--------+ 
| 3  | kaushik  | 23  | Kota      | 30000  | 
| 6  | Komal    | 22  | MP        | 32000  | 
| 1  | Ramesh   | 32  | Ahmedabad | 20000  | 
| 5  | Hardik   | 27  | Bhopal    | 40000  | 
| 2  | Khilan   | 25  | Delhi     | 15000  | 
| 8  | ram      | 22  | vizag     | 31000  | 
| 9  | robert   | 23  | banglore  | 28000  | 
| 7  | ram      | 25  | chennai   | 23000  | 
| 4  | Chaitali | 25  | Mumbai    | 35000  | 
+----+----------+-----+-----------+--------+ 
Fetched 9 row(s) in 0.51s

You can use the order by clause to rank records in the ascending list of ids, as shown below.

[quickstart.cloudera:21000] > select * from customers order by id; 
Query: select * from customers order by id 
+----+----------+-----+-----------+--------+ 
| id | name     | age | address   | salary | 
+----+----------+-----+-----------+--------+ 
| 1  | Ramesh   | 32  | Ahmedabad | 20000  | 
| 2  | Khilan   | 25  | Delhi     | 15000  | 
| 3  | kaushik  | 23  | Kota      | 30000  | 
| 4  | Chaitali | 25  | Mumbai    | 35000  | 
| 5  | Hardik   | 27  | Bhopal    | 40000  | 
| 6  | Komal    | 22  | MP        | 32000  | 
| 7  | ram      | 25  | chennai   | 23000  | 
| 8  | ram      | 22  | vizag     | 31000  |
| 9  | robert   | 23  | banglore  | 28000  | 
+----+----------+-----+-----------+--------+ 
Fetched 9 row(s) in 0.54s

Now, with the limit clause, you can limit the number of records that are output to 4, as shown below with the limit clause.

[quickstart.cloudera:21000] > select * from customers order by id limit 4;

When executed, the above query gives the following output.

Query: select * from customers order by id limit 4 
+----+----------+-----+-----------+--------+ 
| id | name     | age | address   | salary | 
+----+----------+-----+-----------+--------+ 
| 1  | Ramesh   | 32  | Ahmedabad | 20000  | 
| 2  | Khilan   | 25  | Delhi     | 15000  |
| 3  | kaushik  | 23  | Kota      | 30000  | 
| 4  | Chaitali | 25  | Mumbai    | 35000  | 
+----+----------+-----+-----------+--------+ 
Fetched 4 row(s) in 0.64s