You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added limit parameter to Location.execute() in src/matchbox/client/locations.py
New optional limit: int | None = None parameter to restrict query results
Wraps SQL in a LIMIT subquery when limit is specified
Updated all overload signatures and implementation
Updated Source.fetch() and Source.sample() methods in src/matchbox/client/sources.py
Added limit parameter to all fetch() overloads and implementation
Fixed sample() method to properly respect the n parameter instead of using batch_size
Added input validation for n:
- Raises TypeError if n is not an integer (e.g., strings, floats)
- Raises ValueError if n is not positive (≤ 0)
Fixed return type annotation from None to QueryReturnClass
Added comprehensive tests in test/client/test_locations.py and test/client/test_sources.py
Test for limit parameter in execute()
New test_source_sample_validation() covering:
String input validation
Negative/zero value validation
Float input validation
Valid positive integer behavior
👀 Guidance to review
Key changes to focus on:
The LIMIT clause implementation in locations.py uses SQL subqueries to ensure portability across different database engines
Input validation in sample() now provides clear error messages for invalid inputs
The fix maintains backward compatibility for correct usage (positive integers)
🤖 AI declaration
Claude Opus (via VS Code) was used to:
I suggested the broader scope of changes (extending fix to locations.py in addition to sources.py)
It recommended and helped implement comprehensive test coverage
I ran pre-commit checks
The implementation and logic were reviewed manually to ensure correctness. Tests were added to validate the fix works as intended and catches invalid inputs.
✅ Checklist:
This is the smallest, simplest solution to the problem If you want me to remove the test, that would be simpler. Just let me know.
Thanks for your contribution, this is a clean looking PR.
After trying to reproduce the issue locally, with the help of your test, it seems that the sample function works even without your new limit parameter when we use the SQLAlchemy engines. The issue arose specifically when using ADBC as the client for that location. polars.read_database doesn't seem to forward a batch size to ADBC.
Trying to get batch_size to work as intended for ADBC would make this a much trickier issue to solve. However, perhaps your solution is still valid, though may I suggest at least adding a note to the docstring of Source.fetch(), where the batch_size parameter is described, to mention it might not be honoured depending on the location's client?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠️ Changes proposed in this pull request
- Raises TypeError if n is not an integer (e.g., strings, floats)
- Raises ValueError if n is not positive (≤ 0)
👀 Guidance to review
Key changes to focus on:
🤖 AI declaration
Claude Opus (via VS Code) was used to:
locations.pyin addition tosources.py)✅ Checklist:
If you want me to remove the test, that would be simpler. Just let me know.