LiaCastaneda commented on code in PR #21589:
URL: https://github.com/apache/datafusion/pull/21589#discussion_r3109218510


##########
datafusion/physical-plan/src/aggregates/group_values/single_group_by/dictionary.rs:
##########
@@ -0,0 +1,3491 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::aggregates::group_values::GroupValues;
+use crate::hash_utils::RandomState;
+use arrow::array::{
+    Array, ArrayRef, DictionaryArray, LargeStringArray, LargeStringBuilder, 
ListArray,
+    ListBuilder, PrimitiveArray, PrimitiveBuilder, StringArray, StringBuilder,
+    StringViewArray, StringViewBuilder, UInt64Array,
+};
+use arrow::datatypes::{ArrowDictionaryKeyType, ArrowNativeType, DataType};
+use datafusion_common::Result;
+use datafusion_common::hash_utils::create_hashes;
+use datafusion_expr::EmitTo;
+use std::borrow::Cow;
+use std::collections::HashMap;
+use std::marker::PhantomData;
+use std::sync::Arc;
+
+macro_rules! decode_list {
+    ($raw:expr, $builder_type:ty) => {{
+        let mut builder = ListBuilder::new(<$builder_type>::new());
+        for raw_bytes in $raw {
+            match raw_bytes {
+                None => builder.append_null(),
+                Some(raw_vector) => {
+                    let mut offset = 0;
+                    while offset < raw_vector.len() {
+                        let len = i32::from_ne_bytes(
+                            raw_vector[offset..offset + 4]
+                                .try_into()
+                                .expect("slice of length 4"),
+                        );
+                        offset += 4;
+                        if len == -1 {
+                            builder.values().append_null();
+                        } else {
+                            let s = std::str::from_utf8(
+                                &raw_vector[offset..offset + len as usize],
+                            )
+                            .map_err(|e| {
+                                
datafusion_common::DataFusionError::Internal(format!(
+                                    "Invalid utf8 in list element: {e}"
+                                ))
+                            })?;
+                            builder.values().append_value(s);
+                            offset += len as usize;
+                        }
+                    }
+                    builder.append(true);
+                }
+            }
+        }
+        Ok(Arc::new(builder.finish()) as ArrayRef)
+    }};
+}
+macro_rules! decode_scalar_string {
+    ($raw:expr, $builder_type:ty) => {{
+        let mut builder = <$builder_type>::new();
+        for raw_bytes in $raw {
+            match raw_bytes {
+                Some(raw_vector) => {
+                    let s = std::str::from_utf8(raw_vector).map_err(|e| {
+                        datafusion_common::DataFusionError::Internal(format!(
+                            "Invalid utf8 in GroupValuesDictionary: {e}"
+                        ))
+                    })?;
+                    builder.append_value(s);
+                }
+                None => builder.append_null(),
+            }
+        }
+        Ok(Arc::new(builder.finish()) as ArrayRef)
+    }};
+}
+type GroupEntry = (usize, Option<Vec<u8>>);
+pub struct GroupValuesDictionary<K: ArrowDictionaryKeyType + Send> {
+    // stores the order new unique elements are seen for self.emit()
+    seen_elements: Vec<Option<Vec<u8>>>, //  Box<dyn Builder> doesnt provide 
the flexibility of building partition arrays that wed need to support 
emit::First(N)

Review Comment:
   Looking at other implementations, I see for nulls they keep this in a 
separate field and use `MaybeNullBufferBuilder`



-- 
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]

Reply via email to