alamb commented on code in PR #10148:
URL: https://github.com/apache/datafusion/pull/10148#discussion_r1581818211
##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -107,29 +109,55 @@ impl ScalarUDFImpl for GetFieldFunc {
);
}
};
+
match (array.data_type(), name) {
- (DataType::Map(_, _), ScalarValue::Utf8(Some(k))) => {
- let map_array = as_map_array(array.as_ref())?;
- let key_scalar =
Scalar::new(StringArray::from(vec![k.clone()]));
- let keys = arrow::compute::kernels::cmp::eq(&key_scalar,
map_array.keys())?;
- let entries = arrow::compute::filter(map_array.entries(),
&keys)?;
Review Comment:
I would expect the result of evaluating `col[b]` on
```
{ a: 1, b: 2, c: 100}
{ a: 1, b: 2}
{ a: 3, b: 4, c: 200}
```
to be:
```
{ c: 100 }
null
{ c: 200 }
```
For example, in duckdb:
```sql
D create table foo as values (MAP {'a':1, 'b':2, 'c':100}), (MAP{ 'a':1,
'b':2}), (MAP {'a':1, 'b':2, 'c':200});
D select * from foo;
┌───────────────────────┐
│ col0 │
│ map(varchar, integer) │
├───────────────────────┤
│ {a=1, b=2, c=100} │
│ {a=1, b=2} │
│ {a=1, b=2, c=200} │
└───────────────────────┘
D select col0['c'] from foo;
┌───────────┐
│ col0['c'] │
│ int32[] │
├───────────┤
│ [100] │
│ [] │
│ [200] │
└───────────┘
```
Basically a scalar function has the invarant that each input row produces
exactly 1 output row
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]