Skip to main content
Column-to-row conversion is a common operation in ETL processing. Lateral is a special Join keyword that can associate a row with an internal subquery or table function. By using Lateral in conjunction with unnest(), you can expand one row into multiple rows. For more information, see unnest.

Limits

  • Currently, Lateral Join is only used with unnest() to achieve column-to-row conversion. Other table functions and UDTFs will be supported later.
  • Currently, Lateral Join does not support subqueries.

Use Lateral Join

Syntax:
Examples:
The second syntax here is a shortened version of the first one, where the Lateral keyword can be omitted using the UNNEST keyword. The UNNEST keyword is a table function that converts an array into multiple rows. Together with Lateral Join, it can implement common row expansion logic.
NOTE If you want to perform unnest on multiple columns, you must specify an alias for each column, for example, select v1, t1.unnest as v2, t2.unnest as v3 from lateral_test, unnest(v2) t1, unnest(v3) t2;.
The database supports type conversion among BITMAP, STRING, ARRAY, and Column. Some type conversions in Lateral Join

Usage examples

Together with unnest(), you can achieve the following column-to-row conversion features:

Expand a string into multiple rows

  1. Create a table and insert data into this table.
  2. Query data before expansion.
    Text
  3. Expand v2 into multiple rows.
    Text

Expand an array into multiple rows

From v2.5, unnest() can take multiple arrays of different types and lengths. For more information, see unnest().
  1. Create a table and insert data into this table.
  2. Query data before expansion.
    Text
  3. Expand v2 into multiple rows.
    Text

Expand Bitmap data

You can use Lateral Join with the unnest_bitmap function to expand Bitmap data.
  1. Create a table and insert data into this table.
  2. Query data before expansion.
    Text
  3. Insert a new row.
    Text
  4. Expand data in v2 into multiple rows.
    Text