AdamGS commented on code in PR #23631:
URL: https://github.com/apache/datafusion/pull/23631#discussion_r3602037403


##########
datafusion/common/src/scalar/consts.rs:
##########
@@ -54,3 +57,60 @@ pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F32: f32 =
 // Next f64 value below -π/2 (lower bound)
 pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F64: f64 =
     (-std::f64::consts::FRAC_PI_2).next_down();
+
+// Generate lookup table for 1 values of decimals (1, 10, 100, etc.)
+macro_rules! decimal_ones_lut {
+    () => {{
+        let mut values = [1; _];
+        let mut i = 1;
+        while i < values.len() {
+            values[i] = values[i - 1] * 10;
+            i += 1;
+        }
+        values
+    }};
+}
+
+// 1, 10, 100 values meant to be indexed by scale. We omit handling for 
MAX_SCALE
+// itself (we don't go to MAX_SCALE + 1) since we can't represent a 1 value at
+// that scale.
+pub(super) const DECIMAL32_ONES: [i32; Decimal32Type::MAX_SCALE as usize] =
+    decimal_ones_lut!();
+pub(super) const DECIMAL64_ONES: [i64; Decimal64Type::MAX_SCALE as usize] =
+    decimal_ones_lut!();
+pub(super) const DECIMAL128_ONES: [i128; Decimal128Type::MAX_SCALE as usize] =
+    decimal_ones_lut!();
+pub(super) const DECIMAL256_ONES: [i256; Decimal256Type::MAX_SCALE as usize] = 
{
+    // This code was generated by codex and frankly I don't know how it works,
+    // but the test below verifies it outputs the correct values so ¯\_(ツ)_/¯
+    //
+    // This is mainly a shortcut for not needing to manually list out each 
value
+    // anyway.
+    let mut values = [i256::ONE; _];

Review Comment:
   I think this is basically const mul? I also ran into that recently 
elsewhere, so figured I'll make a PR - 
https://github.com/apache/arrow-rs/pull/10363



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