This guide shows you how to use Presto (now Trino) to run a single analytical SQL query that joins data from multiple sources—like a MySQL database, a CSV file in S3, and a Kafka stream—without moving or copying the data. You’ll learn the core steps, common pitfalls, and how to fix issues when they arise.
What You’ll Need
- A running Presto/Trino cluster (single-node works for testing) with coordinator and workers accessible.
- Access to the data sources you want to query (database credentials, file paths, or stream endpoints).
- The Presto CLI or a SQL client (like DBeaver) configured to connect to your Presto coordinator.
- Basic familiarity with SQL (JOIN, SELECT, GROUP BY).
Step-by-Step
- Start Presto and verify it’s running. If you installed it locally, run
bin/launcher startand check the log atvar/log/server.logfor “SERVER STARTED”. For Docker, usedocker run -p 8080:8080 trinodb/trino. - Connect to Presto. Use the CLI:
./presto --server localhost:8080 --catalog mysql --schema yourdb. You should see thepresto:yourdb>prompt. - Configure connectors. Presto uses connectors to talk to different data sources. Each connector has a catalog name. For example, to query MySQL, create
etc/catalog/mysql.propertieswith:connector.name=mysql connection-url=jdbc:mysql://localhost:3306 connection-user=root connection-password=secret
For Hive (for files in S3/HDFS), create
hive.propertieswith your metastore URI. For Kafka, createkafka.propertieswith broker addresses. - Verify each catalog is visible. Run
SHOW CATALOGS;in the CLI. You should seemysql,hive,kafka, andsystem. If a catalog is missing, check the connector properties file and restart Presto. - Explore the tables in each catalog. Run
SHOW TABLES FROM mysql.yourdb;andSHOW TABLES FROM hive.default;to confirm the tables you need are accessible. - Write a cross-catalog query. Use the fully qualified table name:
catalog.schema.table. For example:SELECT u.id, u.name, o.total FROM mysql.yourdb.users u JOIN hive.default.orders o ON u.id = o.user_id;
Presto will push down filters and aggregations where possible, but the join happens in Presto’s engine.
- Run the query. Execute it in the CLI. Presto will plan the query, assign tasks to workers, and return results. Watch the output for row counts and execution time.
- Optimize for performance. If the query is slow, check if you can push down more work. Use
EXPLAINto see the plan. For large data, consider usingWITHclauses to pre-aggregate each side before joining.
Common Mistakes
- Forgetting the catalog prefix. In Presto, you must always use
catalog.schema.table. Using justschema.tablewill fail. - Mixing case sensitivity. Presto is case-sensitive for table and column names. If your MySQL table uses lowercase, but Hive uses uppercase, you must quote them with double quotes.
- Assuming pushdown happens. Not all connectors support pushdown of joins or aggregations. If you join two huge tables, Presto will pull all data to its workers, which can be slow.
- Ignoring type mismatches. Joining a VARCHAR column to an INT column will fail. Use
CASTto convert types.
Tips
- Use
EXPLAINto understand how Presto executes your query. Look forremote exchangeto see where data is shuffled. - For repetitive queries, create a view in Presto:
CREATE VIEW my_view AS SELECT ...to hide the catalog complexity. - If you only need a few columns, select only those—Presto will push down column pruning to many connectors.
- Use the
--catalogflag in the CLI to set a default catalog, so you can writeschema.tablefor that catalog. - Test with a small
LIMITfirst to verify the query works before running it on the full dataset.
Troubleshooting
- “Catalog does not exist” error. Check that the connector properties file is in
etc/catalogwith a.propertiesextension. Restart Presto after adding a catalog. - Connection refused to data source. Verify the data source is reachable from the Presto coordinator and workers. Test with a simple query like
SELECT * FROM mysql.yourdb.table LIMIT 1. - Query hangs or is extremely slow. Check if the data source is under load. For Hive, ensure the metastore is running. For Kafka, check consumer group offsets. Try a simpler query to isolate the issue.
- Type mismatch errors. Use
CASTto convert types. For example,CAST(u.id AS VARCHAR)to join with a string column. - “Table not found” despite it existing. Confirm the schema name. In Hive, the default schema is often
default. In MySQL, it’s the database name. RunSHOW SCHEMAS FROM catalog;to list schemas.
Frequently Asked Questions
Can Presto query data from a CSV file without Hive?
Yes, you can use the memory connector to load a CSV into memory, but for production use the Hive connector with a metastore, or the file connector for local files (though it’s limited).
Do I need to move data to Presto?
No, Presto queries data in place. It does not store data itself; it only reads from the source systems.
Is Presto the same as Trino?
Presto was renamed to Trino in 2020. The original Presto project continues as PrestoDB. This guide applies to both, but check your version’s documentation for any differences.
Can I write to the data sources?
Presto is primarily for analytics; write support is limited. Some connectors (like MySQL) support INSERT, but it’s not recommended for heavy writes.
How do I secure cross-source queries?
Use Presto’s authentication and authorization features. Each connector can have its own credentials, and you can restrict access via views and grants.
What if my data source doesn’t have a connector?
You can write a custom connector using the Presto SPI, or use the generic JDBC connector if your source provides a JDBC driver.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Gmail Gemini Privacy: Data Access & Limit Settings
- Fix Outlook Inbox Corruption with DISM in Windows
- How to Set Up Apple Pay on iPhone
- How to Choose a Refurbished iPhone With Years of Support
- Turn Off Message Notifications on Mac
- Spotting Outside Windows: Step-by-Step Guide