-
Notifications
You must be signed in to change notification settings - Fork 750
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
Fix generate_unions_case for Rust case #1677
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,6 +499,52 @@ impl DataType { | |
)) | ||
} | ||
} | ||
Some(s) if s == "union" => { | ||
if let Some(Value::String(mode)) = map.get("mode") { | ||
let union_mode = if mode == "SPARSE" { | ||
UnionMode::Sparse | ||
} else if mode == "DENSE" { | ||
UnionMode::Dense | ||
} else { | ||
return Err(ArrowError::ParseError(format!( | ||
"Unknown union mode {:?} for union", | ||
mode | ||
))); | ||
}; | ||
if let Some(type_ids) = map.get("typeIds") { | ||
let type_ids = type_ids | ||
.as_array() | ||
.unwrap() | ||
.iter() | ||
.map(|t| t.as_i64().unwrap()) | ||
.collect::<Vec<_>>(); | ||
|
||
let default_fields = type_ids | ||
.iter() | ||
.map(|t| { | ||
Field::new("", DataType::Boolean, true).with_metadata( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it cool to have a field without a name 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only a placeholder, as above other nested types (list, map, etc) do. The actual fields will replace them ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation |
||
Some( | ||
[("type_id".to_string(), t.to_string())] | ||
.iter() | ||
.cloned() | ||
.collect(), | ||
), | ||
) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok(DataType::Union(default_fields, union_mode)) | ||
} else { | ||
Err(ArrowError::ParseError( | ||
"Expecting a typeIds for union ".to_string(), | ||
)) | ||
} | ||
} else { | ||
Err(ArrowError::ParseError( | ||
"Expecting a mode for union".to_string(), | ||
)) | ||
} | ||
} | ||
Some(other) => Err(ArrowError::ParseError(format!( | ||
"invalid or unsupported type name: {} in {:?}", | ||
other, json | ||
|
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 don't parse union type from json before.