Groennbeck commented on code in PR #1122:
URL: https://github.com/apache/datafusion-comet/pull/1122#discussion_r1859019918


##########
native/spark-expr/src/list.rs:
##########
@@ -708,6 +708,92 @@ impl PartialEq<dyn Any> for ArrayInsert {
     }
 }
 
+#[derive(Debug, Hash)]
+pub struct ArraySize {
+    src_array_expr: Arc<dyn PhysicalExpr>,
+}
+
+impl ArraySize {
+    pub fn new(src_array_expr: Arc<dyn PhysicalExpr>) -> Self {
+        Self { src_array_expr }
+    }
+}
+
+impl Display for ArraySize {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        write!(f, "ArraySize [array: {:?}]", self.src_array_expr)
+    }
+}
+
+impl PartialEq<dyn Any> for ArraySize {
+    fn eq(&self, other: &dyn Any) -> bool {
+        down_cast_any_ref(other)
+            .downcast_ref::<Self>()
+            .map(|x| self.src_array_expr.eq(&x.src_array_expr))
+            .unwrap_or(false)
+    }
+}
+
+impl PhysicalExpr for ArraySize {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn data_type(&self, _input_schema: &Schema) -> DataFusionResult<DataType> {
+        Ok(DataType::Int32)
+    }
+
+    fn nullable(&self, input_schema: &Schema) -> DataFusionResult<bool> {
+        // Only non-nullable if fail_on_error is enabled and the element is 
non-nullable
+        self.src_array_expr.nullable(input_schema)
+    }
+
+    fn evaluate(&self, batch: &RecordBatch) -> DataFusionResult<ColumnarValue> 
{
+        let array_value = self
+            .src_array_expr
+            .evaluate(batch)?
+            .into_array(batch.num_rows())?;
+        match array_value.data_type() {
+            DataType::List(_) => {
+                let list_array = as_list_array(&array_value)?;
+                let mut builder = Int32Array::builder(list_array.len());
+                for i in 0..list_array.len() {
+                    if list_array.is_null(i) {

Review Comment:
   Is there a more efficient way to do this?



##########
native/spark-expr/src/list.rs:
##########
@@ -708,6 +708,92 @@ impl PartialEq<dyn Any> for ArrayInsert {
     }
 }
 
+#[derive(Debug, Hash)]
+pub struct ArraySize {
+    src_array_expr: Arc<dyn PhysicalExpr>,
+}
+
+impl ArraySize {
+    pub fn new(src_array_expr: Arc<dyn PhysicalExpr>) -> Self {
+        Self { src_array_expr }
+    }
+}
+
+impl Display for ArraySize {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        write!(f, "ArraySize [array: {:?}]", self.src_array_expr)
+    }
+}
+
+impl PartialEq<dyn Any> for ArraySize {
+    fn eq(&self, other: &dyn Any) -> bool {
+        down_cast_any_ref(other)
+            .downcast_ref::<Self>()
+            .map(|x| self.src_array_expr.eq(&x.src_array_expr))
+            .unwrap_or(false)
+    }
+}
+
+impl PhysicalExpr for ArraySize {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn data_type(&self, _input_schema: &Schema) -> DataFusionResult<DataType> {
+        Ok(DataType::Int32)
+    }
+
+    fn nullable(&self, input_schema: &Schema) -> DataFusionResult<bool> {
+        // Only non-nullable if fail_on_error is enabled and the element is 
non-nullable
+        self.src_array_expr.nullable(input_schema)
+    }
+
+    fn evaluate(&self, batch: &RecordBatch) -> DataFusionResult<ColumnarValue> 
{
+        let array_value = self
+            .src_array_expr
+            .evaluate(batch)?
+            .into_array(batch.num_rows())?;
+        match array_value.data_type() {
+            DataType::List(_) => {
+                let list_array = as_list_array(&array_value)?;
+                let mut builder = Int32Array::builder(list_array.len());
+                for i in 0..list_array.len() {
+                    if list_array.is_null(i) {

Review Comment:
   Is there a more efficient way to do this?



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