You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "cht42 (via GitHub)" <gi...@apache.org> on 2025/02/01 14:03:55 UTC
[PR] Fix `null` input in `map_keys/values` [datafusion]
cht42 opened a new pull request, #14401:
URL: https://github.com/apache/datafusion/pull/14401
## 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 #123` indicates that this PR will close issue #123.
-->
Closes #14400.
## Rationale for this change
<!--
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.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix `null` input in `map_keys/values` [datafusion]
Posted by "cht42 (via GitHub)" <gi...@apache.org>.
cht42 commented on code in PR #14401:
URL: https://github.com/apache/datafusion/pull/14401#discussion_r1939328534
##########
datafusion/functions-nested/src/map_keys.rs:
##########
@@ -126,9 +126,36 @@ fn map_keys_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
};
Ok(Arc::new(ListArray::new(
- Arc::new(Field::new_list_field(map_array.key_type().clone(), false)),
+ Arc::new(Field::new_list_field(map_array.key_type().clone(), true)),
map_array.offsets().clone(),
Arc::clone(map_array.keys()),
- None,
+ map_array.nulls().cloned(),
)))
}
+
+#[cfg(test)]
+mod test {
Review Comment:
sweet, will update
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix `null` input in `map_keys/values` [datafusion]
Posted by "cht42 (via GitHub)" <gi...@apache.org>.
cht42 commented on code in PR #14401:
URL: https://github.com/apache/datafusion/pull/14401#discussion_r1938281147
##########
datafusion/functions-nested/src/map_keys.rs:
##########
@@ -126,9 +126,36 @@ fn map_keys_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
};
Ok(Arc::new(ListArray::new(
- Arc::new(Field::new_list_field(map_array.key_type().clone(), false)),
+ Arc::new(Field::new_list_field(map_array.key_type().clone(), true)),
map_array.offsets().clone(),
Arc::clone(map_array.keys()),
- None,
+ map_array.nulls().cloned(),
)))
}
+
+#[cfg(test)]
+mod test {
Review Comment:
cannot use slt tests as we can't cast Map to nulls
see https://github.com/apache/arrow-rs/blob/a6648fe53bc386eb8f491e68dca3d2bdee6c549c/arrow-schema/src/datatype_parse.rs#L683
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix `null` input in `map_keys/values` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14401:
URL: https://github.com/apache/datafusion/pull/14401#discussion_r1939297553
##########
datafusion/functions-nested/src/map_keys.rs:
##########
@@ -126,9 +126,36 @@ fn map_keys_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
};
Ok(Arc::new(ListArray::new(
- Arc::new(Field::new_list_field(map_array.key_type().clone(), false)),
+ Arc::new(Field::new_list_field(map_array.key_type().clone(), true)),
map_array.offsets().clone(),
Arc::clone(map_array.keys()),
- None,
+ map_array.nulls().cloned(),
)))
}
+
+#[cfg(test)]
+mod test {
Review Comment:
I think you can test it using slt with this trick (create a column with non null value and then insert a `NULL` into it)
```sql
DataFusion CLI v44.0.0
> create table foo as values (MAP {'foo': 'bar'});
0 row(s) fetched.
Elapsed 0.037 seconds.
> insert into foo values (NULL);
+-------+
| count |
+-------+
| 1 |
+-------+
1 row(s) fetched.
Elapsed 0.016 seconds.
> select * from foo;
+------------+
| column1 |
+------------+
| {foo: bar} |
| NULL |
+------------+
2 row(s) fetched.
Elapsed 0.004 seconds.
> select column1, arrow_typeof(column1) from foo;
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| column1 | arrow_typeof(foo.column1) |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {foo: bar} | Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false) |
| NULL | Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false) |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 row(s) fetched.
Elapsed 0.006 seconds.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix `null` input in `map_keys/values` [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 merged PR #14401:
URL: https://github.com/apache/datafusion/pull/14401
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix `null` input in `map_keys/values` [datafusion]
Posted by "cht42 (via GitHub)" <gi...@apache.org>.
cht42 commented on code in PR #14401:
URL: https://github.com/apache/datafusion/pull/14401#discussion_r1938281147
##########
datafusion/functions-nested/src/map_keys.rs:
##########
@@ -126,9 +126,36 @@ fn map_keys_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
};
Ok(Arc::new(ListArray::new(
- Arc::new(Field::new_list_field(map_array.key_type().clone(), false)),
+ Arc::new(Field::new_list_field(map_array.key_type().clone(), true)),
map_array.offsets().clone(),
Arc::clone(map_array.keys()),
- None,
+ map_array.nulls().cloned(),
)))
}
+
+#[cfg(test)]
+mod test {
Review Comment:
cannot use slt tests as we can't cast `null` to `Map`
see https://github.com/apache/arrow-rs/blob/a6648fe53bc386eb8f491e68dca3d2bdee6c549c/arrow-schema/src/datatype_parse.rs#L683
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org