You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/16 18:28:22 UTC

[arrow-rs] branch master updated: Clippy parquet fixes (#3124)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e55b95e8d Clippy parquet fixes (#3124)
e55b95e8d is described below

commit e55b95e8db04bd792e2f4702b926bbb0cfc8a3df
Author: Vrishabh <ps...@gmail.com>
AuthorDate: Wed Nov 16 23:58:15 2022 +0530

    Clippy parquet fixes (#3124)
    
    * Minor paruqet code cleanup
    
    * Minor arrow-json code cleanup
---
 arrow-json/src/reader.rs          |  2 --
 parquet/src/data_type.rs          | 24 ------------------------
 parquet/src/encodings/decoding.rs | 15 ++++++++-------
 parquet/src/record/api.rs         | 11 ++++++-----
 4 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/arrow-json/src/reader.rs b/arrow-json/src/reader.rs
index b3af909ef..860e6b58c 100644
--- a/arrow-json/src/reader.rs
+++ b/arrow-json/src/reader.rs
@@ -909,7 +909,6 @@ impl Decoder {
     }
 
     #[inline(always)]
-    #[allow(clippy::unnecessary_wraps)]
     fn build_string_dictionary_builder<T>(
         &self,
         row_len: usize,
@@ -983,7 +982,6 @@ impl Decoder {
         Ok(Arc::new(builder.finish()))
     }
 
-    #[allow(clippy::unnecessary_wraps)]
     fn build_primitive_array<T: ArrowPrimitiveType + Parser>(
         &self,
         rows: &[Value],
diff --git a/parquet/src/data_type.rs b/parquet/src/data_type.rs
index 9cd36cf43..3e423a415 100644
--- a/parquet/src/data_type.rs
+++ b/parquet/src/data_type.rs
@@ -1291,35 +1291,11 @@ macro_rules! ensure_phys_ty {
 }
 
 #[cfg(test)]
-#[allow(clippy::float_cmp, clippy::approx_constant)]
 mod tests {
     use super::*;
 
     #[test]
-    #[allow(clippy::string_lit_as_bytes)]
     fn test_as_bytes() {
-        assert_eq!(false.as_bytes(), &[0]);
-        assert_eq!(true.as_bytes(), &[1]);
-        assert_eq!(7_i32.as_bytes(), &[7, 0, 0, 0]);
-        assert_eq!(555_i32.as_bytes(), &[43, 2, 0, 0]);
-        assert_eq!(555_u32.as_bytes(), &[43, 2, 0, 0]);
-        assert_eq!(i32::max_value().as_bytes(), &[255, 255, 255, 127]);
-        assert_eq!(i32::min_value().as_bytes(), &[0, 0, 0, 128]);
-        assert_eq!(7_i64.as_bytes(), &[7, 0, 0, 0, 0, 0, 0, 0]);
-        assert_eq!(555_i64.as_bytes(), &[43, 2, 0, 0, 0, 0, 0, 0]);
-        assert_eq!(
-            (i64::max_value()).as_bytes(),
-            &[255, 255, 255, 255, 255, 255, 255, 127]
-        );
-        assert_eq!((i64::min_value()).as_bytes(), &[0, 0, 0, 0, 0, 0, 0, 128]);
-        assert_eq!(3.14_f32.as_bytes(), &[195, 245, 72, 64]);
-        assert_eq!(3.14_f64.as_bytes(), &[31, 133, 235, 81, 184, 30, 9, 64]);
-        assert_eq!("hello".as_bytes(), &[b'h', b'e', b'l', b'l', b'o']);
-        assert_eq!(
-            Vec::from("hello".as_bytes()).as_bytes(),
-            &[b'h', b'e', b'l', b'l', b'o']
-        );
-
         // Test Int96
         let i96 = Int96::from(vec![1, 2, 3]);
         assert_eq!(i96.as_bytes(), &[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]);
diff --git a/parquet/src/encodings/decoding.rs b/parquet/src/encodings/decoding.rs
index 86941ffe0..bbc119c36 100644
--- a/parquet/src/encodings/decoding.rs
+++ b/parquet/src/encodings/decoding.rs
@@ -1069,10 +1069,11 @@ impl<T: DataType> Decoder<T> for DeltaByteArrayDecoder<T> {
 }
 
 #[cfg(test)]
-#[allow(clippy::approx_constant)]
 mod tests {
     use super::{super::encoding::*, *};
 
+    use std::f32::consts::PI as PI_f32;
+    use std::f64::consts::PI as PI_f64;
     use std::sync::Arc;
 
     use crate::schema::types::{
@@ -1214,7 +1215,7 @@ mod tests {
 
     #[test]
     fn test_plain_decode_float() {
-        let data = vec![3.14, 2.414, 12.51];
+        let data = vec![PI_f32, 2.414, 12.51];
         let data_bytes = FloatType::to_byte_array(&data[..]);
         let mut buffer = vec![0.0; 3];
         test_plain_decode::<FloatType>(
@@ -1228,7 +1229,7 @@ mod tests {
 
     #[test]
     fn test_plain_skip_float() {
-        let data = vec![3.14, 2.414, 12.51];
+        let data = vec![PI_f32, 2.414, 12.51];
         let data_bytes = FloatType::to_byte_array(&data[..]);
         test_plain_skip::<FloatType>(
             ByteBufferPtr::new(data_bytes),
@@ -1241,14 +1242,14 @@ mod tests {
 
     #[test]
     fn test_plain_skip_all_float() {
-        let data = vec![3.14, 2.414, 12.51];
+        let data = vec![PI_f32, 2.414, 12.51];
         let data_bytes = FloatType::to_byte_array(&data[..]);
         test_plain_skip::<FloatType>(ByteBufferPtr::new(data_bytes), 3, 4, -1, &[]);
     }
 
     #[test]
     fn test_plain_skip_double() {
-        let data = vec![3.14f64, 2.414f64, 12.51f64];
+        let data = vec![PI_f64, 2.414f64, 12.51f64];
         let data_bytes = DoubleType::to_byte_array(&data[..]);
         test_plain_skip::<DoubleType>(
             ByteBufferPtr::new(data_bytes),
@@ -1261,14 +1262,14 @@ mod tests {
 
     #[test]
     fn test_plain_skip_all_double() {
-        let data = vec![3.14f64, 2.414f64, 12.51f64];
+        let data = vec![PI_f64, 2.414f64, 12.51f64];
         let data_bytes = DoubleType::to_byte_array(&data[..]);
         test_plain_skip::<DoubleType>(ByteBufferPtr::new(data_bytes), 3, 5, -1, &[]);
     }
 
     #[test]
     fn test_plain_decode_double() {
-        let data = vec![3.14f64, 2.414f64, 12.51f64];
+        let data = vec![PI_f64, 2.414f64, 12.51f64];
         let data_bytes = DoubleType::to_byte_array(&data[..]);
         let mut buffer = vec![0.0f64; 3];
         test_plain_decode::<DoubleType>(
diff --git a/parquet/src/record/api.rs b/parquet/src/record/api.rs
index 02cb94765..b64ff51ee 100644
--- a/parquet/src/record/api.rs
+++ b/parquet/src/record/api.rs
@@ -859,10 +859,11 @@ fn convert_decimal_to_string(decimal: &Decimal) -> String {
 }
 
 #[cfg(test)]
-#[allow(clippy::approx_constant, clippy::many_single_char_names)]
+#[allow(clippy::many_single_char_names)]
 mod tests {
     use super::*;
 
+    use std::f64::consts::PI;
     use std::sync::Arc;
 
     use crate::schema::types::{ColumnDescriptor, ColumnPath, PrimitiveTypeBuilder};
@@ -1581,8 +1582,8 @@ mod tests {
         ]);
         assert!((10.3 - list.get_float(2).unwrap()).abs() < f32::EPSILON);
 
-        let list = make_list(vec![Field::Double(3.1415)]);
-        assert!((3.1415 - list.get_double(0).unwrap()).abs() < f64::EPSILON);
+        let list = make_list(vec![Field::Double(PI)]);
+        assert!((PI - list.get_double(0).unwrap()).abs() < f64::EPSILON);
 
         let list = make_list(vec![Field::Str("abc".to_string())]);
         assert_eq!(&"abc".to_string(), list.get_string(0).unwrap());
@@ -1631,7 +1632,7 @@ mod tests {
         ]);
         assert!(list.get_double(2).is_err());
 
-        let list = make_list(vec![Field::Double(3.1415)]);
+        let list = make_list(vec![Field::Double(PI)]);
         assert!(list.get_string(0).is_err());
 
         let list = make_list(vec![Field::Str("abc".to_string())]);
@@ -1832,7 +1833,7 @@ mod tests {
 }
 
 #[cfg(test)]
-#[allow(clippy::approx_constant, clippy::many_single_char_names)]
+#[allow(clippy::many_single_char_names)]
 mod api_tests {
     use super::{make_list, make_map, make_row};
     use crate::record::Field;