ch-sc commented on code in PR #7833:
URL: https://github.com/apache/arrow-datafusion/pull/7833#discussion_r1363543733
##########
datafusion/optimizer/src/push_down_projection.rs:
##########
@@ -423,7 +426,93 @@ pub fn collect_projection_expr(projection: &Projection) ->
HashMap<String, Expr>
.collect::<HashMap<_, _>>()
}
-// Get the projection exprs from columns in the order of the schema
+/// Accumulate the memory size of a data type measured in bits.
+///
+/// Nested types are traversed and increment `nesting` on every level.
+fn nested_size(data_type: &DataType, nesting: &mut usize) -> usize {
+ use DataType::*;
+ if data_type.is_primitive() {
+ return data_type.primitive_width().unwrap_or(1) * 8;
+ }
+
+ if data_type.is_nested() {
+ *nesting += 1;
+ }
+
+ match data_type {
+ Null => 0,
+ Boolean => 1,
+ Binary | Utf8 => 128,
+ LargeBinary | LargeUtf8 => 256,
+ FixedSizeBinary(bytes) => (*bytes * 8) as usize,
+ // primitive types
+ Int8
+ | Int16
+ | Int32
+ | Int64
+ | UInt8
+ | UInt16
+ | UInt32
+ | UInt64
+ | Float16
+ | Float32
+ | Float64
+ | Timestamp(_, _)
+ | Date32
+ | Date64
+ | Time32(_)
+ | Time64(_)
+ | Duration(_)
+ | Interval(_)
+ | Dictionary(_, _)
+ | Decimal128(_, _)
+ | Decimal256(_, _) => data_type.primitive_width().unwrap_or(1) * 8,
+ // nested types
+ List(f) => nested_size(f.data_type(), nesting),
+ FixedSizeList(_, s) => (s * 8) as usize,
+ LargeList(f) => nested_size(f.data_type(), nesting),
+ Struct(fields) => fields
+ .iter()
+ .map(|f| nested_size(f.data_type(), nesting))
Review Comment:
Good idea, I will play around with this idea. Though it sounds like a rare
edge case to me where no other "smaller" type would be present in the schema!?
--
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]