How-to: Use Impala with Kudu

Categories: How-to Impala Kudu

Learn the details about using Impala alongside Kudu.

Kudu (currently in beta), the new storage layer for the Apache Hadoop ecosystem, is tightly integrated with Impala, allowing you to insert, query, update, and delete data from Kudu tablets using Impala’s SQL syntax, as an alternative to using the Kudu APIs to build a custom Kudu application. In addition, you can use JDBC or ODBC to connect existing or new applications written in any language, framework, or business intelligence tool to your Kudu data, using Impala as the broker. This integration relies on features that released versions of Impala do not have yet, as of Impala 2.3, which is expected to ship in CDH 5.5. In the interim, you need to install a fork of Impala called Impala_Kudu.

In this post, you will learn about the various ways to create and partition tables as well as currently supported SQL operators. This post assumes a successful install of the Impala_Kudu package via Cloudera Manager or command line; see the docs for instructions. Note these prerequisites:

  • Impala_Kudu depends upon CDH 5.4 or later. To use Cloudera Manager with Impala_Kudu, you need Cloudera Manager 5.4.3 or later. Cloudera Manager 5.4.7 is recommended, as it adds support for collecting metrics from Kudu.
  • If you have an existing Impala instance on your cluster, you can install Impala_Kudu alongside the existing Impala instance if you use parcels. The new instance does not share configurations with the existing instance and is completely independent. A script is provided to automate this type of installation.
  • It is especially important that the cluster has adequate unreserved RAM for the Impala_Kudu instance.
  • Consider shutting down the original Impala service when testing Impala_Kudu if you want to be sure it is not impacted.
  • Before installing Impala_Kudu, you must have already installed and configured services for HDFS, Apache Hive, and Kudu. You may need Apache HBase, YARN, Apache Sentry, and Apache ZooKeeper services as well.

Using Impala with Kudu

Neither Kudu nor Impala need special configuration for you to use the Impala Shell or the Impala API to insert, update, delete, or query Kudu data using Impala. However, you do need to create a mapping between the Impala and Kudu tables. Kudu provides the Impala query to map to an existing Kudu table in the web UI.

  • Be sure you are using the impala-shell binary provided by the Impala_Kudu package, rather than the default CDH Impala binary. The following shows how to verify this using the alternatives command on a RHEL 6 host. Do not copy and paste the alternatives --set command directly, because the file names are likely to differ.
  • Start Impala Shell using the impala-shell command. By default, impala-shell attempts to connect to the Impala daemon on localhost on port 21000. To connect to a different host, use the -i <host:port> option. To automatically connect to a specific Impala database, use the -d <database> option. For instance, if all your Kudu tables are in Impala in the database impala_kudu, use -d impala_kudu to use this database.
  • To quit the Impala Shell, use the following command: quit;

Internal and External Impala Tables

When creating a new Kudu table using Impala, you can create the table as an internal table or an external table.

  • Internal: An internal table (created by CREATE TABLE) is managed by Impala, and can be dropped by Impala. When you create a new table using Impala, it is generally a internal table.
  • External: An external table (created by CREATE EXTERNAL TABLE) is not managed by Impala, and dropping such a table does not drop the table from its source location (here, Kudu). Instead, it only removes the mapping between Impala and Kudu. This is the mode used in the syntax provided by Kudu for mapping an existing table to Impala.

See the Impala documentation for more information about internal and external tables.

Querying an Existing Kudu Table In Impala

  1. Go to, where is the address of your Kudu master.
  2. Click the table ID link for the relevant table.
  3. Scroll to the bottom of the page, or search for the text Impala CREATE TABLE statement. Copy the entire statement.
  4. Paste the statement into Impala Shell. Impala now has a mapping to your Kudu table.

Creating a New Kudu Table From Impala

Creating a new table in Kudu from Impala is similar to mapping an existing Kudu table to an Impala table, except that you need to write the CREATE statement yourself. Use the following example as a guideline. Impala first creates the table, then creates the mapping.

This example does not use a partitioning schema. However, you will almost always want to define a schema to pre-split your table.

In the CREATE TABLE statement, the columns that comprise the primary key must be listed first. Additionally, primary key columns are implicitly marked NOT NULL.

The following table properties are required, and the kudu.key_columns property must contain at least one column.

  • storage_handler: the mechanism used by Impala to determine the type of data source. For Kudu tables, this must be com.cloudera.kudu.hive.KuduStorageHandler.
  • kudu.table_name: the name of the table that Impala will create (or map to) in Kudu
  • kudu.master_addresses: the list of Kudu masters with which Impala should communicate
  • kudu.key_columns: the comma-separated list of primary key columns, whose contents should not be nullable

CREATE TABLE AS SELECT. You can create a table by querying any other table or tables in Impala, using a CREATE TABLE AS SELECT query.

The following example imports all rows from an existing table old_table into a Kudu table new_table. The columns in new_table will have the same names and types as the columns in old_table, but you need to populate the kudu.key_columns property. In this example, the primary key columns are ts and name.

You can refine the SELECT statement to only match the rows and columns you want to be inserted into the new table. You can also rename the columns by using syntax like SELECT name as new_name.

Partitioning Tables

Tables are partitioned into tablets according to a partition schema on the primary key columns. Each tablet is served by at least one tablet server. Ideally, a table should be split into tablets that are distributed across a number of tablet servers to maximize parallel operations. The details of the partitioning schema you use will depend entirely on the type of data you store and how you access it.

Kudu currently has no mechanism for splitting or merging tablets after the table has been created. Until this feature has been implemented, you must provide a partition schema for your table when you create it. When designing your tables, consider using primary keys that will allow you to partition your table into tablets which grow at similar rates

You can partition your table using Impala’s DISTRIBUTE BY keyword, which supports distribution by RANGE or HASH. The partition scheme can contain zero or more HASH definitions, followed by an optional RANGE definition. The RANGE definition can refer to one or more primary key columns. Examples of basic and advanced partitioning are shown below. Note: Impala keywords, such as group, are enclosed by back-tick characters when they are used as identifiers, rather than as keywords.

Basic Partitioning

DISTRIBUTE BY RANGE. You can specify split rows for one or more primary key columns that contain integer or string values. Range partitioning in Kudu allows splitting a table based on the lexicographic order of its primary keys. This allows you to balance parallelism in writes with scan efficiency.

The split row does not need to exist. It defines an exclusive bound in the form of:

In other words, the split row, if it exists, is included in the tablet after the split point. For instance, if you specify a split row abc, a row abca would be in the second tablet, while a row abb would be in the first.

Suppose you have a table that has columns state, name, and purchase_count. The following example creates 50 tablets, one per US state. Note:  If you partition by range on a column whose values are monotonically increasing, the last tablet will grow much larger than the others. Additionally, all data being inserted will be written to a single tablet at a time, limiting the scalability of data ingest. In that case, consider distributing by HASH instead of, or in addition to, RANGE.

DISTRIBUTE BY HASH. Instead of distributing by an explicit range, or in combination with range distribution, you can distribute into a specific number of “buckets” by hash. You specify the primary key columns you want to partition by, and the number of buckets you want to use. Rows are distributed by hashing the specified key columns. Assuming that the values being hashed do not themselves exhibit significant skew, this will serve to distribute the data evenly across buckets.

You can specify multiple definitions, and you can specify definitions which use compound primary keys. However, one column cannot be mentioned in multiple hash definitions. Consider two columns, a and b:

  • HASH(a), HASH(b) — will succeed
  • HASH(a,b) — will succeed
  • HASH(a), HASH(a,b) — will fail

NoteDISTRIBUTE BY HASH with no column specified is a shortcut to create the desired number of buckets by hashing all primary key columns.

Hash partitioning is a reasonable approach if primary key values are evenly distributed in their domain and no data skew is apparent, such as timestamps or serial IDs.

The following example creates 16 tablets by hashing the id column. A maximum of 16 tablets can be written to in parallel. In this example, a query for a range of sku values is likely to need to read from all 16 tablets, so this may not be the optimum schema for this table. See Advanced Partitioning for an extended example.

Advanced Partitioning

You can use zero or more HASH definitions, followed by zero or one RANGE definitions to partition a table. Each definition can encompass one or more columns. While every possible distribution schema is out of the scope of this document, a few demonstrations follow.

DISTRIBUTE BY RANGE Using Compound Split Rows. This example creates 100 tablets, two for each US state. Per state, the first tablet holds names starting with characters before m, and the second tablet holds names starting with m-z. At least 50 tablets (and up to 100) can be written to in parallel. A query for a range of names in a given state is likely to only need to read from one tablet, while a query for a range of names across every state will likely only read from 50 tablets.

DISTRIBUTE BY HASH and RANGE. Let’s go back to the hashing example above. If you often query for a range of sku values, you can optimize the example by combining hash partitioning with range partitioning. The following example still creates 16 tablets, by first hashing the id column into 4 buckets, and then applying range partitioning to split each bucket into four tablets, based upon the value of the skustring. At least four tablets (and possibly up to 16) can be written to in parallel, and when you query for a contiguous range of sku values, you have a good chance of only needing to read from 1/4 of the tablets to fulfill the query.

Multiple DISTRIBUTE BY HASH Definitions. Again expanding the example above, suppose that the query pattern will be unpredictable, but you want to maximize parallelism of writes. You can achieve even distribution across the entire primary key by hashing on both primary key columns.

The example creates 16 buckets. You could also use HASH (id, sku) INTO 16 BUCKETS. However, a scan for sku values would almost always impact all 16 buckets, rather than possibly being limited to 4.

Impala Database Containment Model

Impala uses a database containment model. You can create a table within a specific scope, referred to as a database. To create the database, use a CREATE DATABASE statement. To use the database for further Impala operations such as CREATE TABLE, use the USE statement. For example, to create a table in a database called impala_kudu, use the following statements:

The my_first_table table is created within the impala_kudu database. To refer to this database in the future, without using a specific USE statement, you can refer to the table using<database>:<table> syntax. For example, to specify the my_first_table table in database impala_kudu, as opposed to any other table with the same name in another database, refer to the table as impala_kudu:my_first_table. This also applies to INSERT, UPDATE, DELETE, and DROP statements.

(Warning: Currently, Kudu does not encode the Impala database into the table name in any way. This means that even though you can create Kudu tables within Impala databases, the actual Kudu tables need to be unique within Kudu. For example, if you create database_1:my_kudu_table and database_2:my_kudu_table, you will have a naming collision within Kudu, even though this would not cause a problem in Impala.)

Impala Keywords Not Support for Kudu Tables

The following Impala keywords are not supported for Kudu tables:


Understanding SQL Operators and Kudu

If your query includes the operators =, <=, or >=, Kudu evaluates the condition directly and only returns the relevant results. Kudu does not yet support <, >, !=, or any other operator not listed.

For these unsupported operations, Kudu returns all results regardless of the condition, and Impala performs the filtering. Since Impala must receive a larger amount of data from Kudu, these operations are less efficient. In some cases, creating and periodically updating materialized views may be the right solution to work around these inefficiencies.

Inserting a Row

The syntax for inserting one or more rows using Impala is shown below.

The primary key must not be null.

Inserting in Bulk

When insert in bulk, there are at least three common choices. Each may have advantages and disadvantages, depending on your data and circumstances.

  • Multiple Single INSERT statements: This approach has the advantage of being easy to understand and implement. This approach is likely to be inefficient because Impala has a high query start-up cost compared to Kudu’s insertion performance. This will lead to relatively high latency and poor throughput.
  • Single INSERT statement with multiple VALUES subclauses: If you include more than 1024 VALUES statements, Impala batches them into groups of 1024 (or the value of batch_size) before sending the requests to Kudu. This approach may perform slightly better than multiple sequential INSERT statements by amortizing the query start-up penalties on the Impala side. To set the batch size for the current Impala Shell session, use this syntax: set batch_size=10000;.(Note: Increasing the Impala batch size causes Impala to use more memory. You should verify the impact on your cluster and tune accordingly.)The “batch insert’ approach that usually performs best, from the standpoint of both Impala and Kudu, is usually to import the data using a SELECT FROM subclause in Impala.
    • If your data is not already in Impala, one strategy is to import it from a text file, such as a TSV or CSV file.
    • Create the Kudu table, being mindful that the columns designated as primary keys cannot have null values.
    • Insert values into the Kudu table by querying the table containing the original data, as in the following example:
    • Ingest using the C++ or Java API: In many cases, the appropriate ingest path is to use the C++ or Java API to insert directly into Kudu tables. Unlike other Impala tables, data inserted into Kudu tables via the API becomes available for query in Impala without the need for any INVALIDATE METADATA statements or other statements needed for other Impala storage types.
INSERT and the IGNORE Keyword

Normally, if you try to insert a row that has already been inserted, the insertion will fail because the primary key would be duplicated (see “Failures During INSERT, UPDATE, and DELETE Operations”.) If an insert fails part of the way through, you can re-run the insert, using the IGNORE keyword, which will ignore only those errors returned from Kudu indicating a duplicate key.

The first example will cause an error if a row with the primary key 99 already exists. The second example will still not insert the row, but will ignore any error and continue on to the next SQL statement.

Updating a Row

The syntax for updating one or more rows using Impala is shown below.

You cannot change or null the primary key value. (Important: The UPDATE statement only works in Impala when the underlying data source is Kudu.)

Updating in Bulk

You can update in bulk using the same approaches outlined in “Inserting in Bulk” above.

UPDATE and the IGNORE Keyword

Similar to INSERT and the IGNORE Keyword, you can use the IGNORE operation to ignore an UPDATE which would otherwise fail. For instance, a row may be deleted while you are attempting to update it. In Impala, this would cause an error. The IGNORE keyword causes the error to be ignored.

Deleting a Row

You can delete Kudu rows in near real time using Impala. You can even use more complex joins when deleting.

Important: The DELETE statement only works in Impala when the underlying data source is Kudu.

Deleting in Bulk

You can delete in bulk using the same approaches outlined in “Inserting in Bulk” above.

DELETE and the IGNORE Keyword

Similar to INSERT and the IGNORE Keyword, you can use the IGNORE operation to ignore an DELETE which would otherwise fail. For instance, a row may be deleted by another process while you are attempting to delete it. In Impala, this would cause an error. The IGNORE keyword causes the error to be ignored.

Failures During INSERT, UPDATE, and DELETE Operations

INSERTUPDATE, and DELETE statements cannot be considered transactional as a whole. If one of these operations fails part of the way through, the keys may have already been created (in the case of INSERT) or the records may have already been modified or removed by another process (in the case of UPDATE or DELETE). You should design your application with this in mind. See INSERT and the IGNORE Keyword.

Altering Table Properties

You can change Impala’s metadata relating to a given Kudu table by altering the table’s properties. These properties include the table name, the list of Kudu master addresses, and whether the table is managed by Impala (internal) or externally. You cannot modify a table’s split rows after table creation. (Important: Altering table properties only changes Impala’s metadata about the table, not the underlying table itself. These statements do not modify any Kudu data.)

Rename a Table

Change the Kudu Master Addresses

Change an Internally-Managed Table to External

Dropping a Table

If the table was created as an internal table in Impala, using CREATE TABLE, the standard DROP TABLE syntax drops the underlying Kudu table and all its data. If the table was created as an external table, using CREATE EXTERNAL TABLE, the mapping between Impala and Kudu is dropped, but the Kudu table is left intact, with all its data. To change an external table to internal, or vice versa, see Altering Table Properties.

Next Steps

The examples above have only explored a fraction of what you can do with Impala Shell. Read about Impala internals or learn how to contribute to Impala on the Impala Wiki.

Misty Stanley-Jones is a Technical Writer at Cloudera, and an Apache HBase committer.

If you’re interested in learning about Impala’s roadmap with respect to Kudu and other things, join this webinar on Tues., Nov. 3 at 10am PT.


8 responses on “How-to: Use Impala with Kudu

  1. Ruslan

    Thank you for the great article. Impala is already an “in-memory” technology. What are the main benefits of having two “in-memory” products to work on the same dataset? I see this as a disadvantage as now we will have to separate memory between the two additional management.

    1. Justin Kestelyn Post author


      Not really; Impala and Kudu sit at two different layers of a modern analytic database architecture for Hadoop. Kudu is a storage engine that enables fast analytics with in-place inserts, updates, deletes. Impala is a SQL query engine that provides interactive queries, but does not store data itself as it relies on HDFS, HBase, and now Kudu as its storage managers. The combination of both provides the ability to perform interactive SQL queries on Hadoop with fast scan performance as well as updatability.

      1. Ruslan

        Good points. Thanks for prompt response. Would Impala be able eat up some of Kudu’s memory? I’m thinking YARN or some other mechanism could allow to use memory more granularly when Kudu or Impala has a surge in how much they need memory. Thanks again.

        1. Justin Kestelyn Post author

          No, memory contention between Impala and Kudu should not be an issue any more than contention between Impala and HBase or HDFS should be an issue.

        2. Mike Percy

          Hi Ruslan,
          Kudu currently only supports setting the memory limit at startup — you can’t change it without restarting the process (as of the time of this writing). In response to your original question, I agree with Justin, and here are a couple reasons. One reason why sharing memory between Kudu and Impala might not help that much is because Impala is often accessing remote data, i.e. from HDFS or a different Kudu node, and as your cluster grows in size, data locality gets harder and harder to achieve for complex queries, so you get diminishing returns. Secondly, as a standalone storage layer, Kudu may be serving requests to not only Impala but multiple other types of client systems, including Spark, MapReduce, or others, that makes it beneficial for Kudu to manage its own caches and harder to get right if it’s trying to special-case one particular type of access.

          All that said, we have been nibbling at the edges of this, for example there has been some work by David Alves on implementing zero-copy in Impala for RPC responses from Kudu ( ) which has a working implementation but hasn’t been merged yet. This could be extended in the future to use shared memory instead of TCP/IP for large transfers of data between processes on a single node, which not only has memory usage benefits but also potentially big performance benefits for certain types of queries.

          By the way, not picking on you, I just wanted to point out that Kudu isn’t an in-memory data store — it can store data sets much larger than total RAM on the cluster (a.k.a. big data) and it’s optimized to store data on disk in a way that makes reads (especially large reads) very efficient..

          Hope this helps, happy to answer more questions here, but you’ll get a more reliable (and likely faster) response on the kudu-user mailing list or the Kudu Slack chat room. Feel free to join. You can find the links to those at

  2. Ruslan

    Thank you for detailed response, Mike. KUDU-1059 looks exciting; David: “saw up to 4x speedups on the micro bench”. A couple more questions:
    1. How would you compare performance of Kudu storage layout compared to BI type queries of Impala on Parquet tables? Is Kudu’s storage layout “columnar”, does it support predicate pushdowns, bloom filters, columnar compression etc?
    2. We are also looking at Hive on HBase and Impala on Hbase as possible options for our “Data Vault” tier (a historical tier before we puish data to a DWH in Oracle). E.g. – how would you compare Impala/Hive on HBase against Impala/Hive on Kudu? Both options have updatability.

    1. Mike Percy

      Hi Ruslan,
      Kudu is very comparable to Parquet on HDFS in terms of on-disk layout and performance. Of course, it’s also mutable (i.e. you can use SQL UPDATE and DELETE commands with Kudu). The internal cfile representation used by Kudu is actually “almost Parquet” but with some relatively minor changes, including additional indexes added to support random access. It has predictate pushdown, bloom filters, and the whole nine yards. You can find more technical details about Kudu and some initial performance results in this white paper:

      You will get much better scan performance on Kudu vs. HBase, since HBase is more optimized for write throughput and random read latencies, while Kudu is more optimized for analytical workloads. Also, depending on your queries, if you are only accessing a subset of columns then Kudu, being a purely columnar data store, will only do IO for those columns, whereas HBase can only skip doing IO on specific columns if it can skip the whole column family (it has a more hybrid row/column orientation model).

      That said, Kudu is currently in Beta, so please keep in mind that we are still doing heavy development on it and it’s not as stable as current versions of HBase or Parquet on HDFS. It’s still too early to run it in production as of version 0.5.

Leave a Reply

Your email address will not be published. Required fields are marked *