viirya commented on code in PR #1871:
URL: https://github.com/apache/arrow-rs/pull/1871#discussion_r898665800


##########
arrow/src/util/decimal.rs:
##########
@@ -0,0 +1,150 @@
+// 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.
+
+//! Decimal related utils
+
+use std::cmp::Ordering;
+
+/// Represents a decimal value with precision and scale.
+/// The decimal value is represented by a signed 128-bit integer.
+#[derive(Debug)]
+pub struct Decimal128 {
+    #[allow(dead_code)]
+    precision: usize,
+    scale: usize,
+    value: i128,
+}
+
+impl PartialOrd for Decimal128 {
+    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+        assert_eq!(
+            self.scale, other.scale,
+            "Cannot compare two Decimal128 with different scale: {}, {}",
+            self.scale, other.scale
+        );
+        self.value.partial_cmp(&other.value)
+    }
+}
+
+impl Ord for Decimal128 {
+    fn cmp(&self, other: &Self) -> Ordering {
+        assert_eq!(
+            self.scale, other.scale,
+            "Cannot compare two Decimal128 with different scale: {}, {}",
+            self.scale, other.scale
+        );
+        self.value.cmp(&other.value)
+    }
+}
+
+impl PartialEq<Self> for Decimal128 {
+    fn eq(&self, other: &Self) -> bool {
+        assert_eq!(
+            self.scale, other.scale,
+            "Cannot compare two Decimal128 with different scale: {}, {}",
+            self.scale, other.scale
+        );
+        self.value.eq(&other.value)
+    }
+}
+
+impl Eq for Decimal128 {}
+
+impl Decimal128 {

Review Comment:
   `Decimal(p, s)`? We can have it. Because it is easy to add API but harder to 
remove. The API starts from minimalism. Currently I keep it as less as possible 
only to be on par with existing functionality.



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

Reply via email to