Github user daveoshinsky commented on a diff in the pull request:
https://github.com/apache/drill/pull/570#discussion_r161066659
--- Diff:
exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalVarchar.java ---
@@ -150,6 +150,14 @@ public void setup() {
public void eval() {
+<#if type.from.contains("VarDecimal")>
+ java.math.BigDecimal bigDecimal =
org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDrillBuf(in.buffer,
in.start, in.end - in.start, in.scale);
+ String str = bigDecimal.toString();
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = Math.min((int)len.value, str.length());
+ out.buffer.setBytes(0, str.getBytes());
--- End diff --
The Math.min use here ensures that we don't overrun the output buffer. It
the string doesn't fit, it's truncated to the length available in the output
buffer. Your change makes the code harder to understand than what I had, and
your change is not necessary (the Math.min again). I am forced to manually
remerge quite a few of my changes because of the way git rebase didn't merge to
master the way I had wished, so am now working on this file. Leaving the line
as I had it for now...
---