aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec/src
diff options
context:
space:
mode:
authorMehant Baid <mehantr@gmail.com>2014-08-27 14:27:31 -0700
committerJacques Nadeau <jacques@apache.org>2014-08-27 18:44:02 -0700
commitd8a770fd98be1c1cd4629da98f7dfcb5a775e0ba (patch)
tree61598b5d784604405a2f0fa9c9b5d572bbd041c8 /exec/java-exec/src
parent528308c325efd7804572e6d34819d8b3da7ff3b4 (diff)
DRILL-1353: Fix decimal regressions
Diffstat (limited to 'exec/java-exec/src')
-rw-r--r--exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java2
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java52
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DrillByteArray.java6
3 files changed, 52 insertions, 8 deletions
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java
index 8c46b4959..cd2c39090 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java
@@ -83,7 +83,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{
if (in.scale != out.scale) {
org.apache.drill.exec.util.DecimalUtility.roundDecimal(out.buffer, out.start, out.nDecimalDigits, out.scale, in.scale);
}
- out.setSign(sign, in.start, in.buffer);
+ out.setSign(sign, out.start, out.buffer);
}
}
</#if> <#-- type.major -->
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
index b5241395e..cbb87bbae 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
@@ -26,6 +26,17 @@ import org.apache.drill.exec.util.DecimalUtility;
public class ByteFunctionHelpers {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ByteFunctionHelpers.class);
+ /**
+ * Helper function to check for equality of bytes in two DrillBuffers
+ *
+ * @param laddr start address of the DrillBuf
+ * @param lStart start offset in the buffer
+ * @param lEnd end offset in the buffer
+ * @param raddr start address of the DrillBuf
+ * @param rStart start offset in the buffer
+ * @param rEnd end offset in the buffer
+ * @return 1 if left input is greater, -1 if left input is smaller, 0 otherwise
+ */
public static final int equal(final long laddr, int lStart, int lEnd, final long raddr, int rStart,
final int rEnd) {
@@ -59,6 +70,17 @@ public class ByteFunctionHelpers {
}
}
+ /**
+ * Helper function to compare a set of bytes in two DrillBuffers
+ *
+ * @param laddr start address of the DrillBuf
+ * @param lStart start offset in the buffer
+ * @param lEnd end offset in the buffer
+ * @param raddr start address of the DrillBuf
+ * @param rStart start offset in the buffer
+ * @param rEnd end offset in the buffer
+ * @return 1 if left input is greater, -1 if left input is smaller, 0 otherwise
+ */
public static final int compare(final long laddr, int lStart, int lEnd, final long raddr, int rStart, final int rEnd) {
int lLen = lEnd - lStart;
int rLen = rEnd - rStart;
@@ -93,6 +115,17 @@ public class ByteFunctionHelpers {
}
+ /**
+ * Helper function to compare a set of bytes in DrillBuf to a ByteArray.
+ *
+ * @param laddr start address of the DrillBuf
+ * @param lStart start offset in the buffer
+ * @param lEnd end offset in the buffer
+ * @param right second input to be compared
+ * @param rStart start offset in the byte array
+ * @param rEnd end offset in the byte array
+ * @return 1 if left input is greater, -1 if left input is smaller, 0 otherwise
+ */
public static final int compare(final long laddr, int lStart, int lEnd, final byte[] right, int rStart, final int rEnd) {
int lLen = lEnd - lStart;
int rLen = rEnd - rStart;
@@ -117,11 +150,20 @@ public class ByteFunctionHelpers {
return lLen > rLen ? 1 : -1;
}
- // Get the big endian integer
+
+ /*
+ * Following are helper functions to interact with sparse decimal represented in a byte array.
+ */
+
+ // Get the integer ignore the sign
public static int getInteger(byte[] b, int index) {
+ return getInteger(b, index, true);
+ }
+ // Get the integer, ignore the sign
+ public static int getInteger(byte[] b, int index, boolean ignoreSign) {
int startIndex = index * DecimalUtility.integerSize;
- if (index == 0) {
+ if (index == 0 && ignoreSign == true) {
return (b[startIndex + 3] & 0xFF) |
(b[startIndex + 2] & 0xFF) << 8 |
(b[startIndex + 1] & 0xFF) << 16 |
@@ -133,9 +175,9 @@ public class ByteFunctionHelpers {
(b[startIndex + 1] & 0xFF) << 16 |
(b[startIndex] & 0xFF) << 24);
- }
+ }
- // Set the big endian bytes for the input integer
+ // Set integer in the byte array
public static void setInteger(byte[] b, int index, int value) {
int startIndex = index * DecimalUtility.integerSize;
b[startIndex] = (byte) ((value >> 24) & 0xFF);
@@ -156,6 +198,6 @@ public class ByteFunctionHelpers {
// Get the sign
public static boolean getSign(byte[] b) {
- return ((b[0] & 0x80) > 0);
+ return ((getInteger(b, 0, false) & 0x80000000) != 0);
}
}
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DrillByteArray.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DrillByteArray.java
index 507db6746..d1c67ef5d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DrillByteArray.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DrillByteArray.java
@@ -17,8 +17,10 @@
*/
package org.apache.drill.exec.expr.fn.impl;
-import io.netty.buffer.ByteBuf;
-
+/**
+ * Thin wrapper around byte array. This class is used by aggregate functions which
+ * consume decimal, variable width vectors as inputs.
+ */
public class DrillByteArray {
private byte[] bytes;
private int length;