Skip to content

Conversation

@joshuaFordyce
Copy link

@joshuaFordyce joshuaFordyce commented Oct 21, 2025

Description

This PR introduces a new TrinoReader (Data Loader) for the LlamaINdex ecosystem, built around the native trino-python-client. This implementation is designed. to solve common production instability issues when querying Trino's distributed sql engine

Fixes #20126 20126

  • Prevents connection leaks, which commonly lead to resource exhaustion on the Trino coordinator
  • Addresses the poor retrieval accuracy problem inherent in generic SQL Loaders
  • The transformation logic explicitly serializes data into a high-density key:value format and embeds this context into the Document's text and metadata. This significantly improves semantic search precision
  • Removes reliance on fragile, generic ODBC/JDBC wrappers

New Package?

Yes

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation

  • I have added Google Colab support for the newly added notebooks.

  • My changes generate no new warnings

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes

  • I ran uv run make format; uv run make lint to appease the lint gods

@joshuaFordyce joshuaFordyce marked this pull request as ready for review October 21, 2025 16:00
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Oct 21, 2025
Copy link
Member

@AstraBert AstraBert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, but in order to get this PR approved you should change the location of the scripts as detailed in the first comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want the package to be published correctly, the scripts should be moved under llama_index/readers/trino

"schema": schema,
}

def configureConnection(self) -> Tuple[trino.dbapi.Connection, trino.dbapi.Cursor]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, better to use snake_case

Comment on lines 91 to 94
cur.execute(query)

rows = cur.fetchall()
return [rows, cur.description]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use the cursor and connection available within the class?

Comment on lines 46 to 47
# CRITICAL: Add the native Trino Python client as a dependency
# Note: We use the llama-index-core version from the source template
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to commit these comments? 😅

exclude = ["_static", "build", "examples", "notebooks", "venv"]
ignore_missing_imports = true
python_version = "3.8"
python_version = "3.9" # Updated to align with your project's min Python version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using 3.10 since 3.9 has reached its EOF at the beginning of October... Also, I would get rid of the comment :)

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Oct 27, 2025
Copy link
Member

@AstraBert AstraBert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change requested as detailed below 👇

Copy link
Member

@AstraBert AstraBert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should change the test import pattern, otherwise tests will fail

from unittest import mock
from llama_index.core.readers.base import BaseReader
import inspect
from llama_index.base import TrinoReader
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have overseen this, but this module does not exist. If you want to import TrinoReader, you should do: from llama_index.readers.trino.base import TrinoReader. This is causing test failures

Suggested change
from llama_index.base import TrinoReader
from llama_index.readers.trino.base import TrinoReader

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi thanks for that. fixed it and looked over the feature to make sure everything else made sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be __init__.py. This is breaking package building

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Sorry about that fixed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: New Data Loader - Native Trino Reader

2 participants