EMR Trino provides a standalone Delta connector that supports comprehensive data lake features on E-MapReduce clusters.
Background information
Delta Lake is a data lake solution from Databricks that provides data-centric features for managing the data lifecycle. For more information, see Overview of Delta Lake.
Prerequisites
You have created one of the following cluster types: a DataLake or Custom cluster with the Trino service, or a Hadoop cluster with the Presto service. For more information, see Create a cluster.
Limitations
The Delta connector is supported on DataLake clusters, Custom clusters, and Hadoop clusters that run EMR-3.39.1 or later, or EMR-5.5.0 or later.
Basic usage
Modify connector configuration
To modify the Delta connector configuration, see Modify the configurations of a built-in connector.
Default connector configuration
In the EMR console, go to the
|
Parameter |
Description |
|
hive.metastore.uri |
The URI for connecting to the Hive metastore using the Thrift protocol. The default format is thrift://master-1-1.cluster-24****:9083. |
|
hive.config.resources |
The location of the resource files used by the Hive metastore. |
Example
Trino cannot create or modify a Delta Lake table. Use Spark SQL for these operations instead. For more information, see Basic usage.
-
Generate data.
-
Run the following command to enter the Spark SQL command line.
spark-sql -
Run the following statement to create a Delta Lake table.
CREATE TABLE delta_table (id INT) USING delta; -
Run the following statement to write data to the table.
INSERT INTO delta_table VALUES 0,1,2,3,4;
-
-
Query the data.
-
Access the Trino command line. For more information, see Access Trino using a command-line interface.
-
Run the following statement to query the table.
SELECT * FROM delta_table;The following output is returned.
id ---- 0 1 2 3 4 (5 rows)
-
Advanced usage
The following features are supported on EMR-3.39.1 or later, or EMR-5.5.0 or later.
Time travel
The time travel feature lets you query a table's historical data.
EMR Trino supports time travel for Delta Lake tables. The syntax is FOR xxx AS OF, where xxx can be VERSION or TIMESTAMP, specifying whether to query by version number or timestamp.
Compared to the Spark SQL syntax for Delta Lake, Trino's time travel syntax adds the FOR keyword.
Example:
-
Run the following command to enter the Spark SQL command line.
spark-sql -
Run the following statement to overwrite the data.
INSERT OVERWRITE TABLE delta_table VALUES 5,6,7,8,9; -
Query the data.
-
Access the Trino command line. For more information, see Access Trino using a command-line interface.
-
Run the following statement to query the table.
SELECT * FROM delta_table;The following output is returned.
id ---- 5 6 7 8 9 (5 rows)
-
-
Use time travel to query historical data.
Run the following statement to query data by version number. The version number is a monotonically increasing integer. By default, the version number is 1 after the first INSERT operation and increments by 1 with each modification.
SELECT * FROM delta_table FOR VERSION AS OF 1;The following output is returned.
id ---- 2 1 3 4 0 (5 rows)You can also query data by timestamp. Three timestamp types are supported: DATE, TIMESTAMP, and TIMESTAMP WITH TIME ZONE.
-
DATE: Queries data at 00:00:00 UTC on the specified date.
-
TIMESTAMP: Queries data at the specified timestamp in UTC.
For example, run the following statement to query data at 20:00:00 on February 15, 2022, in Beijing time (UTC+08:00), using the TIMESTAMP type.
SELECT * FROM delta_table FOR TIMESTAMP AS OF TIMESTAMP '2022-02-15 12:00:00';NoteIn this statement, the first TIMESTAMP keyword sets the time travel mode to timestamp (not the version number mode). The second TIMESTAMP keyword casts the string literal to the TIMESTAMP data type (not the DATE type).
The following output is returned.
id ---- 2 0 3 4 1 (5 rows) -
TIMESTAMP WITH TIME ZONE: Querying with TIMESTAMP WITH TIME ZONE requires a type cast.
For example, to query data at 20:00:00 on February 15, 2022, in Beijing time (UTC+08:00), use the following statement.
SELECT * FROM delta_table FOR TIMESTAMP AS OF CAST('2022-02-15 20:00:00 +0800' AS TIMESTAMP WITH TIME ZONE);
-
Z-order
Trino uses Z-Ordering to optimize queries on Delta Lake tables by leveraging Parquet's native optimizations and data skipping. After optimization, Delta Lake collects file-level statistics such as minimum and maximum values for each column, which the Delta connector uses to filter data files directly.
For Delta Lake tables optimized with the OPTIMIZE and ZORDER BY commands, properly configured Z-Ordering columns can make Trino queries dozens of times faster.
Trino supports Z-Ordering for the following data types: Int, Long, Double, Float, Binary, Boolean, String, and Array.
Trino supports the following predicates for Z-Ordering data skipping: =, <, <=, >, and >=.
Trino does not currently support predicates such as like and in. However, due to the locality-preserving nature of Z-Ordering, queries that use these predicates may still run faster after Z-Ordering optimization.
For example, consider a table named conn_zorder with four columns: src_ip, src_port, dst_ip, and dst_port.
First, run the following optimization statement in Spark:
OPTIMIZE conn_zorder ZORDER BY (src_ip, src_port, dst_ip, dst_port);
The order of columns in the parentheses defines the Z-Ordering.
The OPTIMIZE operation may take some time depending on the data volume. After optimization, all queries that use these filter conditions will run faster.
-
Querying a subset of the Z-Ordered columns improves performance. For example:
SELECT COUNT(*) FROM conn_zorder WHERE src_ip > '64.'; -
Querying based on the Z-Ordering sequence significantly improves query speed. For example:
SELECT COUNT(*) FROM conn_zorder WHERE src_ip >= '64.' AND dst_ip < '192.' AND src_port < 1000 AND dst_port > 50000;