Skip to content

Conversation

maiadegraaf
Copy link
Contributor

Fixes: #17008

This PR fixes an issue with type casting in lambda expressions used in the list_reduce function.

For example, in the following query:

select list_reduce([0], (x, y) -> x > 3, 3.1)

The lambda expression was incorrectly bound as:

CAST((x > CAST(3 AS INTEGER)) AS DECIMAL(11,1))

Now proper type casting is implemented to match the max logical type of both the list child type and the initial value type:

CAST((x > CAST(3 AS DECIMAL(11,1))) AS DECIMAL(11,1))

Test Cases

Added tests to verify the correct casting behaviour

@maiadegraaf maiadegraaf requested a review from taniabogatsch May 21, 2025 11:57
Copy link
Contributor

@taniabogatsch taniabogatsch left a comment

Choose a reason for hiding this comment

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

Hi @maiadegraaf - thanks! I left a few comments, mostly nits around code structure and some names. :))

@duckdb-draftbot duckdb-draftbot marked this pull request as draft May 22, 2025 09:42
@maiadegraaf maiadegraaf force-pushed the list_reduce_initial_internal_error branch from 0da4d31 to 4e59c16 Compare May 22, 2025 09:42
@maiadegraaf maiadegraaf marked this pull request as ready for review May 22, 2025 09:42
@duckdb-draftbot duckdb-draftbot marked this pull request as draft May 22, 2025 10:56
@maiadegraaf maiadegraaf marked this pull request as ready for review May 22, 2025 12:51
Copy link
Contributor

@taniabogatsch taniabogatsch left a comment

Choose a reason for hiding this comment

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

Left a few more comments. :)

@duckdb-draftbot duckdb-draftbot marked this pull request as draft May 27, 2025 16:12
@maiadegraaf maiadegraaf marked this pull request as ready for review May 28, 2025 07:16
@Mytherin
Copy link
Collaborator

Thanks for the PR! LGTM - should we retarget this to v1.3 or keep this targeted towards main?

@maiadegraaf maiadegraaf changed the base branch from main to v1.3-ossivalis June 3, 2025 07:15
@maiadegraaf maiadegraaf changed the base branch from v1.3-ossivalis to main June 3, 2025 07:15
…ype handling

Now the lambda function columns match the max logical type of the list child and initial value.
@maiadegraaf maiadegraaf force-pushed the list_reduce_initial_internal_error branch from 377d2e2 to 0cf0a88 Compare June 3, 2025 07:39
@maiadegraaf maiadegraaf force-pushed the list_reduce_initial_internal_error branch from 0cf0a88 to 74d7bd9 Compare June 3, 2025 07:40
@maiadegraaf maiadegraaf changed the base branch from main to v1.3-ossivalis June 3, 2025 07:40
@maiadegraaf
Copy link
Contributor Author

I think retargeting to v1.3 is best. I've rebased the branch, so it should be gtg now!

@Mytherin Mytherin merged commit f270019 into duckdb:v1.3-ossivalis Jun 4, 2025
2 checks passed
@Mytherin
Copy link
Collaborator

Mytherin commented Jun 4, 2025

Thanks!

@maiadegraaf maiadegraaf deleted the list_reduce_initial_internal_error branch June 4, 2025 07:43
github-actions bot pushed a commit to duckdb/duckdb-r that referenced this pull request Jun 5, 2025
[Nested] Fix incorrect type casting in list_reduce lambda expressions (duckdb/duckdb#17581)
Pop up ICU errors to the csv sniffer (duckdb/duckdb#17719)
github-actions bot added a commit to duckdb/duckdb-r that referenced this pull request Jun 5, 2025
[Nested] Fix incorrect type casting in list_reduce lambda expressions (duckdb/duckdb#17581)
Pop up ICU errors to the csv sniffer (duckdb/duckdb#17719)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal error with list_reduce(..., initial)
3 participants