Dreamware / Work / Just Ask Trino: Text-to-SQL as a Native Table Function
Just Ask Trino: Text-to-SQL as a Native Table Function
Open-source Trino plugin for natural language to SQL conversion. Get composable table functions with JOINs, WHERE clauses, and subqueries - all in standard SQL.
The Challenge
Trino is a distributed SQL query engine used across the industry for querying data at scale — across data lakes, warehouses, and operational databases. But writing correct SQL against complex schemas is a skill barrier. Business analysts know what they want to ask but struggle with the syntax, table relationships, and query patterns required to get answers.
The typical solution is a separate natural-language-to-SQL layer — a standalone application that sits between the user and the database. These work, but they break composability. You can't JOIN the output of a natural language query with another table. You can't filter the results with a WHERE clause. You can't use it as a subquery. The natural language interface becomes an island, disconnected from the rest of the SQL ecosystem.
Our Approach
Dreamware built Just Ask Trino as a native Trino plugin that exposes natural language queries as standard table functions. Two functions do the work: query() returns the generated SQL as text, and ask() generates and executes the SQL, returning the actual result set. Both work as first-class Trino table functions — composable with JOINs, WHERE clauses, subqueries, and anything else Trino supports.
The plugin operates as an LLM agent loop. When a user calls ask('How many customers are in each market segment?', 'tpch'), the system loads a prompt template, includes catalog-specific documentation, and enters an agent loop where the LLM can call a read_doc tool to fetch additional schema documentation before generating SQL. This means catalog documentation can cover dozens of tables without bloating every request — the LLM reads only what's relevant to the question.
The architecture is deliberately provider-agnostic. The llm.endpoint configuration accepts any OpenAI-compatible API — OpenAI, Azure OpenAI, Ollama, vLLM — so organisations can use their preferred model, including local models for sensitive data environments. Written in Java as a native Trino connector plugin.
The Outcome
Just Ask Trino is open source and works against any Trino catalog. The repo includes complete documentation for Trino's built-in TPC-H connector as a reference implementation — covering all 8 tables, business term mappings, date handling guides, and example queries.
The composability is what sets it apart. Because ask() returns a standard result set, you can write queries like:
SELECT * FROM TABLE(justask.system.ask('top 5 nations by order count', 'tpch'))
WHERE order_count > 50000;
Or JOIN natural language results with other tables:
SELECT a.*, r.name AS region_name
FROM TABLE(justask.system.ask('top 5 nations by order count', 'tpch')) a
JOIN tpch.sf1.region r ON a.regionkey = r.regionkey;
This means natural language SQL isn't a separate tool — it's part of the query language itself. Analysts can mix natural language questions with precise SQL in the same query, using each where it's strongest.
Key result
Open source, native Trino plugin, composable table functions, provider-agnostic LLM
Tech Stack
Related Services
Interested in similar work?
Tell us about your project. We'll have an honest conversation about what's possible, what it costs, and how we'd approach it.