ctubbsii commented on a change in pull request #2535:
URL: https://github.com/apache/accumulo/pull/2535#discussion_r819155895



##########
File path: 
core/src/main/java/org/apache/accumulo/core/client/lexicoder/BigDecimalLexicoder.java
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+package org.apache.accumulo.core.client.lexicoder;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import 
org.apache.accumulo.core.clientImpl.lexicoder.FixedByteArrayOutputStream;
+
+/**
+ * A lexicoder to encode/decode a BigDecimal to/from bytes that maintain its 
native Java sort order.
+ *

Review comment:
       I'm not sure either are strictly necessary. What matters is that the 
lexical ordering of the encoded form by this Lexicoder is deterministic, in 
numerical order first, then in lexical order by precision. So, `new 
BigDecimal(new BigInteger("203"), 2)` should sort lexically prior to `new 
BigDecimal(new BigInteger("2030"), 3)`, for example.
   
   The main reason a Comparator is needed is to test that the ordering is 
preserved in both directions. So at the very least, a better comparator will be 
needed for testing. It may be sufficient to use 
`Comparator.naturalOrder().thenComparingInt(BigDecimal::precision)`, but I 
don't know if there are any edge cases where this breaks.
   
   As for the javadoc, rather than stating that we're maintaining its native 
Java sort order, we should specify that we're maintaining its numerical order 
and precision, so that numerically equivalent values, the ones with the least 
precision are ordered first. When this lexicoder is reversed, the opposite 
should be true.




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