-
Notifications
You must be signed in to change notification settings - Fork 1k
[Variant] feat: add support for casting MapArray to VariantArray #8177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Weijun-H -- I have some questions
let variant1 = result.value(0); | ||
let item = variant1.as_list().unwrap().get(0).unwrap(); | ||
assert_eq!( | ||
item.as_object().unwrap().get("keys").unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to have created something like
[{
"keys": "key1",
"values": 1
}]
I expect the result to be
{ "key1": 1 }
Questions:
- where did the list come from?
- I am not sure about the "keys" and "values" fields 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no data type in Variant
that can directly represent a map,
I converted the map into the following structure:
[
{
"keys": "key1",
"values": 1
},
{
"keys": "key2",
"values": 2
}
]
Using an object might be a better idea, but the keys can only be strings. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think object is the more expected result
Maybe you can all the keys of the MapArray
into strings using the cast_to_variant
kernel ?
7dd5aaa
to
85eabb0
Compare
38a0b4e
to
60c56ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Weijun-H -- this is looking good
DataType::Map(field, _) => match field.data_type() { | ||
DataType::Struct(_) => { | ||
let map_array = input.as_map(); | ||
let keys = cast_to_variant(map_array.keys())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also potentially cast this directly to a string aray here, somethin glike
let keys = cast_to_variant(map_array.keys())?; | |
let keys = cast(map_array.keys(), DataType::Utf8)?; |
And then you wouldn't have to worry about dealing with Variants
I think what you have here, other than the unwrap, is looks good to me
5fc2ef2
to
e85a41d
Compare
e85a41d
to
ff5f64e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Weijun-H
I merged up to resolve a conflict |
Thanks. again @Weijun-H |
Which issue does this PR close?
DataType::Map
support forcast_to_variant
kernel #8063Rationale for this change
Maps are now cast to
Variant::Object
sWhat changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?