Querying data using Trino
Query data in Apache Kudu using Trino with or without schema emulation.
Apache Kudu does not support namespaces or schemas for tables. The Cloudera Trino Kudu connector manages schemas in Apache Kudu clusters by providing optional schema emulation through table naming conventions.
Default behavior without schema emulation
Schema emulation is disabled by default, placing all Apache Kudu tables in the
default schema. The following query rules apply when working in this mode:
- Query an Apache Kudu table named
ordersin Trino by runningSELECT * FROM example.default.ordersorSELECT * FROM ordersif your active catalog and schema are set tokuduanddefault. - Enclose table names in double quotes if they contain special characters, for example,
SELECT * FROM example.default."special.table!"
The following examples show how to create a table, inspect the table structure, insert data, and query the results in the default schema:
Create the users table:
CREATE TABLE example.default.users (
user_id int WITH (primary_key = true),
first_name VARCHAR,
last_name VARCHAR
) WITH (
partition_by_hash_columns = ARRAY['user_id'],
partition_by_hash_buckets = 2
);
Describe the table structure:
DESCRIBE example.default.users;
The query returns the following column metadata:
| Column | Type | Extra |
|---|---|---|
user_id |
integer |
primary_key, encoding=auto, compression=default |
first_name |
varchar |
nullable, encoding=auto, compression=default |
last_name |
varchar |
nullable, encoding=auto, compression=default |
Insert data into the table:
INSERT INTO example.default.users VALUES (1, 'Donald', 'Duck'), (2, 'Mickey', 'Mouse');
Query the inserted data:
SELECT * FROM example.default.users;
Behavior with schema emulation
When schema emulation is enabled in the catalog configuration file, for example, etc/catalog/example.properties, the connector maps Apache Kudu table names to Trino schemas.
When kudu.schema-emulation.enabledis true and the
kudu.schema-emulation.prefix property is empty, the connector uses the
following mappings and creates a special table named $schemas to manage
schemas:
| Kudu table name | Trino qualified name |
|---|---|
orders |
kudu.default.orders |
part1.part2 |
kudu.part1.part2 |
x.y.z |
kudu.x."y.z" |
When kudu.schema-emulation.enabled is true and
kudu.schema-emulation.prefix is presto::, the connector
uses the following mappings and creates a special table named presto::$schemas
to manage schemas:
| Kudu table name | Trino qualified name |
|---|---|
orders |
kudu.default.orders |
part1.part2 |
kudu.default."part1.part2" |
x.y.z |
kudu.default."x.y.z" |
presto::part1.part2 |
kudu.part1.part2 |
presto::x.y.z |
kudu.x."y.z" |
