You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/04/21 18:25:54 UTC

[arrow-datafusion] branch master updated: MINOR: beautify code with neat ident (#2295)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f7e093d0 MINOR: beautify code with neat ident (#2295)
8f7e093d0 is described below

commit 8f7e093d0b30b1e81877a1387e40eaa507d482d9
Author: DuRipeng <45...@qq.com>
AuthorDate: Fri Apr 22 02:25:50 2022 +0800

    MINOR: beautify code with neat ident (#2295)
---
 datafusion/common/src/scalar.rs | 232 +++++++++++++++++++---------------------
 1 file changed, 112 insertions(+), 120 deletions(-)

diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs
index 4a1dde18b..e6963db1b 100644
--- a/datafusion/common/src/scalar.rs
+++ b/datafusion/common/src/scalar.rs
@@ -702,142 +702,134 @@ impl ScalarValue {
         /// Creates an array of $ARRAY_TY by unpacking values of
         /// SCALAR_TY for primitive types
         macro_rules! build_array_primitive {
-      ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{
-        {
-          let array = scalars
-            .map(|sv| {
-              if let ScalarValue::$SCALAR_TY(v) = sv {
-                Ok(v)
-              } else {
-                Err(DataFusionError::Internal(format!(
-                  "Inconsistent types in ScalarValue::iter_to_array. \
-                                     Expected {:?}, got {:?}",
-                  data_type, sv
-                )))
-              }
-            })
-            .collect::<Result<$ARRAY_TY>>()?;
-
-          Arc::new(array)
+            ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{
+                {
+                    let array = scalars.map(|sv| {
+                        if let ScalarValue::$SCALAR_TY(v) = sv {
+                            Ok(v)
+                        } else {
+                            Err(DataFusionError::Internal(format!(
+                                "Inconsistent types in ScalarValue::iter_to_array. \
+                                    Expected {:?}, got {:?}",
+                                data_type, sv
+                            )))
+                        }
+                    })
+                    .collect::<Result<$ARRAY_TY>>()?;
+                    Arc::new(array)
+                }
+            }};
         }
-      }};
-    }
 
         macro_rules! build_array_primitive_tz {
-      ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{
-        {
-          let array = scalars
-            .map(|sv| {
-              if let ScalarValue::$SCALAR_TY(v, _) = sv {
-                Ok(v)
-              } else {
-                Err(DataFusionError::Internal(format!(
-                  "Inconsistent types in ScalarValue::iter_to_array. \
-                                     Expected {:?}, got {:?}",
-                  data_type, sv
-                )))
-              }
-            })
-            .collect::<Result<$ARRAY_TY>>()?;
-
-          Arc::new(array)
+            ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{
+                {
+                    let array = scalars.map(|sv| {
+                        if let ScalarValue::$SCALAR_TY(v, _) = sv {
+                            Ok(v)
+                        } else {
+                            Err(DataFusionError::Internal(format!(
+                                "Inconsistent types in ScalarValue::iter_to_array. \
+                                    Expected {:?}, got {:?}",
+                                data_type, sv
+                            )))
+                        }
+                    })
+                    .collect::<Result<$ARRAY_TY>>()?;
+                    Arc::new(array)
+                }
+            }};
         }
-      }};
-    }
 
         /// Creates an array of $ARRAY_TY by unpacking values of
         /// SCALAR_TY for "string-like" types.
         macro_rules! build_array_string {
-      ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{
-        {
-          let array = scalars
-            .map(|sv| {
-              if let ScalarValue::$SCALAR_TY(v) = sv {
-                Ok(v)
-              } else {
-                Err(DataFusionError::Internal(format!(
-                  "Inconsistent types in ScalarValue::iter_to_array. \
-                                     Expected {:?}, got {:?}",
-                  data_type, sv
-                )))
-              }
-            })
-            .collect::<Result<$ARRAY_TY>>()?;
-          Arc::new(array)
+            ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{
+                {
+                    let array = scalars.map(|sv| {
+                        if let ScalarValue::$SCALAR_TY(v) = sv {
+                            Ok(v)
+                        } else {
+                            Err(DataFusionError::Internal(format!(
+                                "Inconsistent types in ScalarValue::iter_to_array. \
+                                    Expected {:?}, got {:?}",
+                                data_type, sv
+                            )))
+                        }
+                    })
+                    .collect::<Result<$ARRAY_TY>>()?;
+                    Arc::new(array)
+                }
+            }};
         }
-      }};
-    }
 
         macro_rules! build_array_list_primitive {
-      ($ARRAY_TY:ident, $SCALAR_TY:ident, $NATIVE_TYPE:ident) => {{
-        Arc::new(ListArray::from_iter_primitive::<$ARRAY_TY, _, _>(
-          scalars.into_iter().map(|x| match x {
-            ScalarValue::List(xs, _) => xs.map(|x| {
-              x.iter()
-                .map(|x| match x {
-                  ScalarValue::$SCALAR_TY(i) => *i,
-                  sv => panic!(
-                    "Inconsistent types in ScalarValue::iter_to_array. \
-                                    Expected {:?}, got {:?}",
-                    data_type, sv
-                  ),
-                })
-                .collect::<Vec<Option<$NATIVE_TYPE>>>()
-            }),
-            sv => panic!(
-              "Inconsistent types in ScalarValue::iter_to_array. \
-                        Expected {:?}, got {:?}",
-              data_type, sv
-            ),
-          }),
-        ))
-      }};
-    }
+            ($ARRAY_TY:ident, $SCALAR_TY:ident, $NATIVE_TYPE:ident) => {{
+                Arc::new(ListArray::from_iter_primitive::<$ARRAY_TY, _, _>(
+                    scalars.into_iter().map(|x| match x {
+                        ScalarValue::List(xs, _) => xs.map(|x| {
+                            x.iter().map(|x| match x {
+                                ScalarValue::$SCALAR_TY(i) => *i,
+                                sv => panic!(
+                                    "Inconsistent types in ScalarValue::iter_to_array. \
+                                        Expected {:?}, got {:?}",
+                                    data_type, sv
+                                ),
+                            })
+                            .collect::<Vec<Option<$NATIVE_TYPE>>>()
+                        }),
+                        sv => panic!(
+                            "Inconsistent types in ScalarValue::iter_to_array. \
+                                Expected {:?}, got {:?}",
+                            data_type, sv
+                        ),
+                    }),
+                ))
+            }};
+        }
 
         macro_rules! build_array_list_string {
-      ($BUILDER:ident, $SCALAR_TY:ident) => {{
-        let mut builder = ListBuilder::new($BUILDER::new(0));
-
-        for scalar in scalars.into_iter() {
-          match scalar {
-            ScalarValue::List(Some(xs), _) => {
-              let xs = *xs;
-              for s in xs {
-                match s {
-                  ScalarValue::$SCALAR_TY(Some(val)) => {
-                    builder.values().append_value(val)?;
-                  }
-                  ScalarValue::$SCALAR_TY(None) => {
-                    builder.values().append_null()?;
-                  }
-                  sv => {
-                    return Err(DataFusionError::Internal(format!(
-                      "Inconsistent types in ScalarValue::iter_to_array. \
-                                         Expected Utf8, got {:?}",
-                      sv
-                    )))
-                  }
+            ($BUILDER:ident, $SCALAR_TY:ident) => {{
+                let mut builder = ListBuilder::new($BUILDER::new(0));
+                for scalar in scalars.into_iter() {
+                    match scalar {
+                        ScalarValue::List(Some(xs), _) => {
+                            let xs = *xs;
+                            for s in xs {
+                                match s {
+                                    ScalarValue::$SCALAR_TY(Some(val)) => {
+                                        builder.values().append_value(val)?;
+                                    }
+                                    ScalarValue::$SCALAR_TY(None) => {
+                                        builder.values().append_null()?;
+                                    }
+                                    sv => {
+                                        return Err(DataFusionError::Internal(format!(
+                                            "Inconsistent types in ScalarValue::iter_to_array. \
+                                                Expected Utf8, got {:?}",
+                                            sv
+                                        )))
+                                    }
+                                }
+                            }
+                            builder.append(true)?;
+                        }
+                        ScalarValue::List(None, _) => {
+                            builder.append(false)?;
+                        }
+                        sv => {
+                            return Err(DataFusionError::Internal(format!(
+                                "Inconsistent types in ScalarValue::iter_to_array. \
+                                    Expected List, got {:?}",
+                                sv
+                            )))
+                        }
+                    }
                 }
-              }
-              builder.append(true)?;
-            }
-            ScalarValue::List(None, _) => {
-              builder.append(false)?;
-            }
-            sv => {
-              return Err(DataFusionError::Internal(format!(
-                "Inconsistent types in ScalarValue::iter_to_array. \
-                             Expected List, got {:?}",
-                sv
-              )))
-            }
-          }
+                Arc::new(builder.finish())
+            }};
         }
 
-        Arc::new(builder.finish())
-      }};
-    }
-
         let array: ArrayRef = match &data_type {
             DataType::Decimal(precision, scale) => {
                 let decimal_array =