fix: return empty DataSet instead of EmptyData for zero-row queries#38
Open
maltesander wants to merge 1 commit into
Open
fix: return empty DataSet instead of EmptyData for zero-row queries#38maltesander wants to merge 1 commit into
maltesander wants to merge 1 commit into
Conversation
get_all() was returning Err(EmptyData) when a query completed with valid column metadata but zero rows (e.g. WHERE 1=0). Replace the empty-check guard with an unconditional build_dataset() call, which already handles empty Vec<T> correctly. Add tests/get_all_empty.rs to cover both Row and derived Trino struct types using a wiremock server simulating the QUEUED → FINISHED flow.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi all, i stumbled over a possible bug in the getData() call.
Problem
In
client.rsget_all(), the first response from Trino is almost always in QUEUED or PLANNING state withdata: null, routing execution into the None arm of the match. The code then polls subsequent pages, accumulating rows. When the query produces no rows, the page loop ends with an empty accumulator and the following code was reached:Err(EmptyData) is the wrong outcome here in my opinion. An empty result set is not an error, it is a valid query result with a known schema and zero rows.
Fix
Replace the guard with an unconditional
build_datasetcall.build_datasetalready handles an emptyVec<T>correctly for both dynamic Row and derived#[derive(Trino)]types:Test
I let Claude add two tests for this problem, but i am unsure if that really fits the test pattern here. It uses the "MockServer" and async calls to verify the fix.
tests/get_all_empty.rs adds two #[tokio::test] cases backed by a wiremock server simulating the real Trino two-page lifecycle (QUEUED → FINISHED with columns, no data):
test_get_all_empty_result_set_row_type — exercises the TrinoTy::Unknown / Row code path in build_dataset
test_get_all_empty_result_set_derived_type — exercises the DataSet::new / T::ty() path for a #[derive(Trino)] struct
The page-2 fixture reuses tests/data/models/query_result_empty (already present in the repo).
cargo test --test get_all_emptyFeedback on how to improve/adapt that would be appreciated.