Skip to content

Conversation

@jizezhang
Copy link
Contributor

@jizezhang jizezhang commented Nov 4, 2025

Which issue does this PR close?

Rationale for this change

This PR is intended to fix return type mismatch of spark array when inner data type is LargeList, e.g.

query error
SELECT array(arrow_cast(array(1), 'LargeList(Int64)'))
----
DataFusion error: Internal error: Function 'array' returned value of type 'LargeList(Field { name: "element", data_type: LargeList(Field { data_type: Int64, nullable: true }), nullable: true })' while the following type was promised at planning time and expected: 'List(Field { name: "element", data_type: LargeList(Field { data_type: Int64, nullable: true }), nullable: true })'.
This issue was likely caused by a bug in DataFusion's code. Please help us to resolve this by filing a bug report in our issue tracker: https://github.com/apache/datafusion/issues

What changes are included in this PR?

  • Return List regardless of whether inner data type is LargeList or not. This aligns with the behavior of datafusion make_array function.
  • Remove return_field_from_args as return_type is already defined and is invoked internally.

Are these changes tested?

Yes

Are there any user-facing changes?

No.

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) spark labels Nov 4, 2025
Comment on lines 95 to 108
fn return_field_from_args(&self, args: ReturnFieldArgs) -> Result<FieldRef> {
let data_types = args
.arg_fields
.iter()
.map(|f| f.data_type())
.cloned()
.collect::<Vec<_>>();
let return_type = self.return_type(&data_types)?;
Ok(Arc::new(Field::new(
"this_field_name_is_irrelevant",
return_type,
false,
)))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm actually thinking maybe we keep this and just fold return_type logic into here; specifically because it returns false for the nullability whereas default implementation for return_field_from_args returns true for nullability.

  • We'd still need to implement return_type to satisfy trait, but we can have it return an internal err, see:

fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
internal_err!("return_field_from_args should be used instead")
}
fn return_field_from_args(
&self,
args: datafusion_expr::ReturnFieldArgs,
) -> Result<FieldRef> {
let [map_type] = take_function_args(self.name(), args.arg_fields)?;
Ok(Field::new(
self.name(),
DataType::List(get_map_values_field_as_list_field(map_type.data_type())?),
// Nullable if the map is nullable
args.arg_fields.iter().any(|x| x.is_nullable()),
)
.into())
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks for pointing it out, will raise a revision.

For my learning, make_array implements return_type but not return_field_from_args,

fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
which means it uses default implementation of return_field_from_args that has nullable set to true. How would nullability on the return field affect behavior of sql queries? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with the degree to which DataFusion uses the nullability information of a field, so I can't say what the impact would be. But I assume it's better to be more informative where possible, e.g. we know make array function can't ever return a null so it's good if we can preserve that information, especially since the Spark version already had it.

mkleen and others added 5 commits November 4, 2025 22:35
…8373)

## Which issue does this PR close?

- None, This is a follow-up for
apache#18298

## Rationale for this change

This moves the projection logic from `generate_series` out of the
generator into `LazyMemoryStream` as discussed in
apache#18298 (comment)
This makes the projection logic generic for all generators.

## What changes are included in this PR?

The projection logic is moved from `generate_series` into the
`LazyMemoryStream` and relevant tests, where `LazyMemoryStream` is used,
are adapted accordingly.

## Are these changes tested?

This is only a small refactoring; the changes are covered by the tests
from apache#18298

## Are there any user-facing changes?

There is a new parameter added to LazyMemoryExec::try_new method
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

- part of #apache#18142.

## Rationale for this change
As discussed in apache#18289 this PR
is for consolidating all the `flight` examples into a single example
binary. Then we can make sure we are agreed on the pattern and then we
can apply it to the remaining examples

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

## What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

## Are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

## Are there any user-facing changes?

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->

---------

Co-authored-by: Sergey Zhukov <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
…8389)

## Which issue does this PR close?

Addresses portions of apache#17379.

## Rationale for this change

Add support for aggregate and window UDFs in the same way as we did it
for scalar UDFs here: apache#18019

## Are these changes tested?

Yes

## Are there any user-facing changes?

Yes, the changes are user-facing, documented, purely additive and
non-breaking.
## Which issue does this PR close?
- Closes apache#18350.

## Rationale for this change
We want to be able to reverse a ListView.

## What changes are included in this PR?
- Downcast `&dyn Array` to `ListView`: `as_list_view_array`
- Downcast `&dyn Array` to `LargeListView`: `as_large_list_view_array`
- Branches in `array_reverse_inner` to reverse `ListView` and
`LargeListView`
- Main logic in `list_view_reverse` which materializes a new values
array using `take`

## Are these changes tested?
Yes
@github-actions github-actions bot added documentation Improvements or additions to documentation sql SQL Planner common Related to common crate proto Related to proto crate functions Changes to functions implementation physical-plan Changes to the physical-plan crate labels Nov 5, 2025
@github-actions github-actions bot removed documentation Improvements or additions to documentation sql SQL Planner common Related to common crate proto Related to proto crate functions Changes to functions implementation physical-plan Changes to the physical-plan crate labels Nov 5, 2025
@Jefffrey Jefffrey added this pull request to the merge queue Nov 5, 2025
Merged via the queue into apache:main with commit f7a9f24 Nov 5, 2025
28 checks passed
@Jefffrey
Copy link
Contributor

Jefffrey commented Nov 5, 2025

Thanks @jizezhang

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

Labels

spark sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants