siddharthteotia commented on a change in pull request #6053:
URL: https://github.com/apache/incubator-pinot/pull/6053#discussion_r494758942



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.common.function.scalar;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import org.apache.pinot.common.function.annotations.ScalarFunction;
+
+
+public class DataTypeConversionFunctions {
+  private DataTypeConversionFunctions() {
+
+  }
+
+  @ScalarFunction
+  public static byte[] bigDecimalToBytes(BigDecimal number) {
+    int scale = number.scale();
+    BigInteger unscaled = number.unscaledValue();
+    byte[] value = unscaled.toByteArray();
+    byte[] bigDecimalBytesArray = new byte[value.length + 4];
+    for (int i = 0; i < 4; i++) {
+      bigDecimalBytesArray[i] = (byte) (scale >>> (8 * (3 - i)));
+    }
+    System.arraycopy(value, 0, bigDecimalBytesArray, 4, value.length);
+    return bigDecimalBytesArray;
+  }
+
+  @ScalarFunction
+  public static String bytesToBigDecimal(byte[] bytes) {
+    int scale = 0;
+    for (int i = 0; i < 4; i++) {
+      scale += (((int) bytes[i]) << (8 * (3 - i)));
+    }
+    byte[] vals = new byte[bytes.length - 4];

Review comment:
       This should be in BIG ENDIAN byte order

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.common.function.scalar;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import org.apache.pinot.common.function.annotations.ScalarFunction;
+
+
+public class DataTypeConversionFunctions {
+  private DataTypeConversionFunctions() {
+
+  }
+
+  @ScalarFunction

Review comment:
       - What is the format here? Are we saying that byte array is the 2's 
complement representation of the underlying unscaled value. 
   - How is scale represented in the byte array?
   - Do we have to take care of endianness here? The unscaled values is going 
to be BIG-ENDIAN. How's it working without swapping bytes?

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/AggregationFunctionType.java
##########
@@ -30,6 +30,7 @@
   MIN("min"),
   MAX("max"),
   SUM("sum"),
+  SUMPRECISION("sumPrecision"),

Review comment:
       Why not allow both precision and scale? 




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to