http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java b/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java index df60650..12f45b2 100644 --- a/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java @@ -53,27 +53,7 @@ outside:{ </#if> <#if mode == "var"> - - for (int l = left.start, r = right.start; l < left.end && r < right.end; l++, r++) { - byte leftByte = left.buffer.getByte(l); - byte rightByte = right.buffer.getByte(r); - if (leftByte != rightByte) { - ${output} = ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1; - break outside; - } - } - - int l = (left.end - left.start) - (right.end - right.start); - if (l > 0) { - ${output} = 1; - break outside; - } else if (l == 0) { - ${output} = 0; - break outside; - } else { - ${output} = -1; - break outside; - } + ${output} = org.apache.drill.exec.expr.fn.impl.ByteFunctionHelpers.compare(left.buffer.memoryAddress(), left.start, left.end, right.buffer.memoryAddress(), right.start, right.end); <#elseif mode == "fixed"> ${output} = left.value < right.value ? -1 : ((left.value == right.value)? 0 : 1); </#if> @@ -99,8 +79,11 @@ import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.fn.impl.ByteFunctionHelpers; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; +import javax.inject.Inject; +import io.netty.buffer.DrillBuf; @SuppressWarnings("unused") public class GCompare${left}${right}{ @@ -219,27 +202,8 @@ public class GCompare${left}${right}{ public void setup(RecordBatch b) {} public void eval() { - <#if type.mode == "var" > -outside: - { - if (left.end - left.start == right.end - right.start) { - int n = left.end - left.start; - int l = left.start; - int r = right.start; - while (n-- !=0) { - byte leftByte = left.buffer.getByte(l++); - byte rightByte = right.buffer.getByte(r++); - if (leftByte != rightByte) { - out.value = 0; - break outside; - } - } - out.value = 1; - } else { - out.value = 0; - } - } + out.value = org.apache.drill.exec.expr.fn.impl.ByteFunctionHelpers.equal(left.buffer.memoryAddress(), left.start, left.end, right.buffer.memoryAddress(), right.start, right.end); <#else> out.value = left.value == right.value ? 1 : 0; </#if>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/ConvertToNullableHolder.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/ConvertToNullableHolder.java b/exec/java-exec/src/main/codegen/templates/ConvertToNullableHolder.java index 0d2be65..89a400d 100644 --- a/exec/java-exec/src/main/codegen/templates/ConvertToNullableHolder.java +++ b/exec/java-exec/src/main/codegen/templates/ConvertToNullableHolder.java @@ -49,15 +49,15 @@ public class ${className} implements DrillSimpleFunc { <#elseif (minor.class == "Interval")> output.months = input.months; output.days = input.days; - output.milliSeconds = input.milliSeconds; + output.milliseconds = input.milliseconds; <#elseif (minor.class == "IntervalDay")> output.days = input.days; - output.milliSeconds = input.milliSeconds; + output.milliseconds = input.milliseconds; <#elseif minor.class.startsWith("Decimal")> output.scale = input.scale; output.precision = input.precision; <#if minor.class.startsWith("Decimal28") || minor.class.startsWith("Decimal38")> - output.setSign(input.getSign()); + output.setSign(input.getSign(input.start, input.buffer), output.start, output.buffer); output.start = input.start; output.buffer = input.buffer; <#else> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java b/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java index 701e992..1c9b76f 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java @@ -60,10 +60,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu <#if type.runningType == "Interval"> value.months = ${type.initialValue}; value.days= ${type.initialValue}; - value.milliSeconds = ${type.initialValue}; + value.milliseconds = ${type.initialValue}; <#elseif type.runningType == "IntervalDay"> value.days= ${type.initialValue}; - value.milliSeconds = ${type.initialValue}; + value.milliseconds = ${type.initialValue}; <#else> value.value = ${type.initialValue}; </#if> @@ -90,13 +90,13 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu long inMS = (long) in.months * org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis+ in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) + - in.milliSeconds; + in.milliseconds; value.value = Math.min(value.value, inMS); <#elseif type.outputType == "IntervalDay"> long inMS = (long) in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) + - in.milliSeconds; + in.milliseconds; value.value = Math.min(value.value, inMS); @@ -113,12 +113,12 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu <#elseif type.outputType == "Interval"> long inMS = (long) in.months * org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis+ in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) + - in.milliSeconds; + in.milliseconds; value.value = Math.max(value.value, inMS); <#elseif type.outputType == "IntervalDay"> long inMS = (long) in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) + - in.milliSeconds; + in.milliseconds; value.value = Math.max(value.value, inMS); <#else> @@ -129,10 +129,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu <#if type.outputType == "Interval"> value.days += in.days; value.months += in.months; - value.milliSeconds += in.milliSeconds; + value.milliseconds += in.milliseconds; <#elseif type.outputType == "IntervalDay"> value.days += in.days; - value.milliSeconds += in.milliSeconds; + value.milliseconds += in.milliseconds; <#else> value.value += in.value; </#if> @@ -154,10 +154,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu out.months = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis); value.value = value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis; out.days = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); - out.milliSeconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); + out.milliseconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); <#elseif type.outputType == "IntervalDay"> out.days = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); - out.milliSeconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); + out.milliseconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); <#else> out.value = value.value; </#if> @@ -165,10 +165,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu <#if type.outputType == "Interval"> out.months = value.months; out.days = value.days; - out.milliSeconds = value.milliSeconds; + out.milliseconds = value.milliseconds; <#elseif type.outputType == "IntervalDay"> out.days = value.days; - out.milliSeconds = value.milliSeconds; + out.milliseconds = value.milliseconds; <#else> out.value = value.value; </#if> @@ -180,10 +180,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu <#if type.runningType == "Interval"> value.months = ${type.initialValue}; value.days= ${type.initialValue}; - value.milliSeconds = ${type.initialValue}; + value.milliseconds = ${type.initialValue}; <#elseif type.runningType == "IntervalDay"> value.days= ${type.initialValue}; - value.milliSeconds = ${type.initialValue}; + value.milliseconds = ${type.initialValue}; <#else> value.value = ${type.initialValue}; </#if> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateDateArithmeticFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateDateArithmeticFunctions.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateDateArithmeticFunctions.java index 0074c7c..e119958 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateDateArithmeticFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateDateArithmeticFunctions.java @@ -55,12 +55,12 @@ public static class G${type}Difference implements DrillSimpleFunc { public void eval() { <#if type == "Time"> - out.milliSeconds = left.value - right.value; + out.milliseconds = left.value - right.value; <#elseif type == "Date"> out.days = (int) ((left.value - right.value) / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); <#elseif type == "TimeStamp"> long difference = (left.value - right.value); - out.milliSeconds = (int) (difference % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); + out.milliseconds = (int) (difference % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); out.days = (int) (difference / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); <#elseif type == "TimeStampTZ"> if (left.index != right.index) { @@ -70,7 +70,7 @@ public static class G${type}Difference implements DrillSimpleFunc { left.value = (leftInput.withZone(org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.timezoneList[right.index]))).getMillis(); } long difference = (left.value - right.value); - out.milliSeconds = (int) (difference % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); + out.milliseconds = (int) (difference % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); out.days = (int) (difference / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); </#if> } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java index 6fc78eb..349b7bf 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateIntervalArithmeticFunctions.java @@ -63,12 +63,12 @@ public class ${datetype}${intervaltype}Functions { <#if intervaltype == "Interval"> ${temp}.addMonths(${right}.months <#if op == '-'> * -1 </#if>); ${temp}.addDays(${right}.days <#if op == '-'> * -1 </#if>); - ${temp}.add(${right}.milliSeconds <#if op == '-'> * -1 </#if>); + ${temp}.add(${right}.milliseconds <#if op == '-'> * -1 </#if>); <#elseif intervaltype == "IntervalYear"> ${temp}.addMonths(${right}.value <#if op == '-'> * -1 </#if>); <#elseif intervaltype == "IntervalDay"> ${temp}.addDays(${right}.days <#if op == '-'> * -1 </#if>); - ${temp}.add(${right}.milliSeconds <#if op == '-'> * -1 </#if>); + ${temp}.add(${right}.milliseconds <#if op == '-'> * -1 </#if>); <#elseif intervaltype == "Int" || intervaltype == "BigInt"> ${temp}.addDays((int) ${right}.value <#if op == '-'> * -1 </#if>); </#if> @@ -184,7 +184,7 @@ public class ${datetype}${intervaltype}Functions { // Needn't add anything to time from interval year data type. Output is same as input ${output} = ${left}.value; <#else> - ${output} = ${left}.value ${op} ${right}.milliSeconds; + ${output} = ${left}.value ${op} ${right}.milliseconds; // Wrap around 24 hour clock if we exceeded it while adding the time component ${output} = ${output} % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis; </#if> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateToCharFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateToCharFunctions.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateToCharFunctions.java index 326b1df..695cfcf 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateToCharFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/DateToCharFunctions.java @@ -28,6 +28,8 @@ import org.apache.drill.exec.expr.annotations.Workspace; package org.apache.drill.exec.expr.fn.impl; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -38,6 +40,7 @@ import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; @SuppressWarnings("unused") @FunctionTemplate(name = "to_char", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) @@ -45,14 +48,14 @@ public class G${type}ToChar implements DrillSimpleFunc { @Param ${type}Holder left; @Param VarCharHolder right; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Workspace org.joda.time.MutableDateTime temp; @Workspace org.joda.time.format.DateTimeFormatter format; @Output VarCharHolder out; public void setup(RecordBatch b) { temp = new org.joda.time.MutableDateTime(0, org.joda.time.DateTimeZone.UTC); - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[100]); + buffer = buffer.reallocIfNeeded(100); // Get the desired output format and create a DateTimeFormatter byte[] buf = new byte[right.end - right.start]; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java index 6dae417..0858c3f 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/Extract.java @@ -98,12 +98,12 @@ public class ${className} { <#elseif toUnit == "Day"> out.value = in.days; <#elseif toUnit == "Hour"> - out.value = in.milliSeconds/(org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); + out.value = in.milliseconds/(org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); <#elseif toUnit == "Minute"> - int millis = in.milliSeconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); + int millis = in.milliseconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); out.value = millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis); <#elseif toUnit == "Second"> - long millis = in.milliSeconds % org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis; + long millis = in.milliseconds % org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis; out.value = (double) millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.secondsToMillis); </#if> <#elseif fromUnit == "IntervalDay"> @@ -112,12 +112,12 @@ public class ${className} { <#elseif toUnit == "Day"> out.value = in.days; <#elseif toUnit == "Hour"> - out.value = in.milliSeconds/(org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); + out.value = in.milliseconds/(org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); <#elseif toUnit == "Minute"> - int millis = in.milliSeconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); + int millis = in.milliseconds % (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); out.value = millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis); <#elseif toUnit == "Second"> - long millis = in.milliSeconds % org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis; + long millis = in.milliseconds % org.apache.drill.exec.expr.fn.impl.DateUtility.minutesToMillis; out.value = (double) millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.secondsToMillis); </#if> <#else> <#-- IntervalYear type --> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalIntervalArithmetic.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalIntervalArithmetic.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalIntervalArithmetic.java index ad769e1..484c8f4 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalIntervalArithmetic.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalIntervalArithmetic.java @@ -58,12 +58,12 @@ public class ${intervaltype}Functions { <#if intervaltype == "Interval"> out.months = left.months + right.months; out.days = left.days + right.days; - out.milliSeconds = left.milliSeconds + right.milliSeconds; + out.milliseconds = left.milliseconds + right.milliseconds; <#elseif intervaltype == "IntervalYear"> out.value = left.value + right.value; <#elseif intervaltype == "IntervalDay"> out.days = left.days + right.days; - out.milliSeconds = left.milliSeconds + right.milliSeconds; + out.milliseconds = left.milliseconds + right.milliseconds; </#if> } } @@ -82,12 +82,12 @@ public class ${intervaltype}Functions { <#if intervaltype == "Interval"> out.months = left.months - right.months; out.days = left.days - right.days; - out.milliSeconds = left.milliSeconds - right.milliSeconds; + out.milliseconds = left.milliseconds - right.milliseconds; <#elseif intervaltype == "IntervalYear"> out.value = left.value - right.value; <#elseif intervaltype == "IntervalDay"> out.days = left.days - right.days; - out.milliSeconds = left.milliSeconds - right.milliSeconds; + out.milliseconds = left.milliseconds - right.milliseconds; </#if> } } @@ -104,12 +104,12 @@ public class ${intervaltype}Functions { <#if intervaltype == "Interval"> out.months = -left.months; out.days = -left.days; - out.milliSeconds = -left.milliSeconds; + out.milliseconds = -left.milliseconds; <#elseif intervaltype == "IntervalYear"> out.value = -left.value; <#elseif intervaltype == "IntervalDay"> out.days = -left.days; - out.milliSeconds = -left.milliSeconds; + out.milliseconds = -left.milliseconds; </#if> } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalNumericArithmetic.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalNumericArithmetic.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalNumericArithmetic.java index 9a56c1b..ce73f74 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalNumericArithmetic.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/IntervalNumericArithmetic.java @@ -49,12 +49,12 @@ public class ${intervaltype}${numerictype}Functions { <#if intervaltype == "Interval"> ${out}.months = (int) (${left}.months * ${right}.value); ${out}.days = (int) (${left}.days * ${right}.value); - ${out}.milliSeconds = (int) (${left}.milliSeconds * ${right}.value); + ${out}.milliseconds = (int) (${left}.milliseconds * ${right}.value); <#elseif intervaltype == "IntervalYear"> ${out}.months = (int) (${left}.value * ${right}.value); <#elseif intervaltype == "IntervalDay"> ${out}.days = (int) (${left}.days * ${right}.value); - ${out}.milliSeconds = (int) (${left}.milliSeconds * ${right}.value); + ${out}.milliseconds = (int) (${left}.milliseconds * ${right}.value); </#if> </#macro> @@ -67,12 +67,12 @@ public class ${intervaltype}${numerictype}Functions { <#if intervaltype == "Interval"> fractionalMonths = (${left}.months ${op} (double) ${right}.value); fractionalDays = (${left}.days ${op} (double) ${right}.value); - fractionalMillis = (${left}.milliSeconds ${op} (double) ${right}.value); + fractionalMillis = (${left}.milliseconds ${op} (double) ${right}.value); <#elseif intervaltype == "IntervalYear"> fractionalMonths = (${left}.value ${op} (double) ${right}.value); <#elseif intervaltype == "IntervalDay"> fractionalDays = (${left}.days ${op} ${right}.value); - fractionalMillis = (${left}.milliSeconds ${op} (double) ${right}.value); + fractionalMillis = (${left}.milliseconds ${op} (double) ${right}.value); </#if> ${out}.months = (int) fractionalMonths; @@ -86,7 +86,7 @@ public class ${intervaltype}${numerictype}Functions { fractionalDays = fractionalDays - (long) fractionalDays; fractionalMillis += fractionalDays * org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis; - ${out}.milliSeconds = (int) fractionalMillis; + ${out}.milliseconds = (int) fractionalMillis; </#macro> @SuppressWarnings("unused") http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/ToTimeStampFunction.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/ToTimeStampFunction.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/ToTimeStampFunction.java index 9195891..4fd619f 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/ToTimeStampFunction.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/ToTimeStampFunction.java @@ -64,7 +64,7 @@ public class G${numerics}ToTimeStamp implements DrillSimpleFunc { value = value.multiply(millisConstant); inputMillis = (new java.math.BigDecimal(value, left.scale)).longValue(); <#elseif (numerics == "Decimal28Sparse") || (numerics == "Decimal38Sparse")> - java.math.BigDecimal input = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(left.buffer, left.start, left.nDecimalDigits, left.scale); + java.math.BigDecimal input = org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromSparse(left.buffer, left.start, left.nDecimalDigits, left.scale); inputMillis = input.multiply(new java.math.BigDecimal(1000)).longValue(); </#if> <#else> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java index b518c44..8fe13bb 100644 --- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java @@ -213,9 +213,9 @@ public class GCompare${type.name}Functions { public void eval() { <#if type.name == "Interval"> - <@intervalCompareBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliSeconds" output="out.value"/> + <@intervalCompareBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliseconds" output="out.value"/> <#else> - <@intervalCompareBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliSeconds" output="out.value"/> + <@intervalCompareBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliseconds" output="out.value"/> </#if> } @@ -234,9 +234,9 @@ public class GCompare${type.name}Functions { public void eval() { <#if type.name == "Interval"> - <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliseconds"/> <#else> - <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliseconds"/> </#if> out.value = leftMS < rightMS ? 1 : 0; @@ -256,9 +256,9 @@ public class GCompare${type.name}Functions { public void eval() { <#if type.name == "Interval"> - <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliseconds"/> <#else> - <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliseconds"/> </#if> out.value = leftMS <= rightMS ? 1 : 0; @@ -278,9 +278,9 @@ public class GCompare${type.name}Functions { public void eval() { <#if type.name == "Interval"> - <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliseconds"/> <#else> - <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliseconds"/> </#if> out.value = leftMS > rightMS ? 1 : 0; @@ -300,9 +300,9 @@ public class GCompare${type.name}Functions { public void eval() { <#if type.name == "Interval"> - <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliseconds"/> <#else> - <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliseconds"/> </#if> out.value = leftMS >= rightMS ? 1 : 0; @@ -321,9 +321,9 @@ public class GCompare${type.name}Functions { public void eval() { <#if type.name == "Interval"> - <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliseconds"/> <#else> - <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliseconds"/> </#if> out.value = leftMS == rightMS ? 1 : 0; @@ -342,9 +342,9 @@ public class GCompare${type.name}Functions { public void eval() { <#if type.name == "Interval"> - <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="left.months" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="right.months" rightDays="right.days" rightMillis="right.milliseconds"/> <#else> - <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliSeconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliSeconds"/> + <@intervalConvertBlock left="left" right="right" leftMonths="0" leftDays="left.days" leftMillis="left.milliseconds" rightMonths="0" rightDays="right.days" rightMillis="right.milliseconds"/> </#if> out.value = leftMS != rightMS ? 1 : 0; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalDenseDecimalSparse.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalDenseDecimalSparse.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalDenseDecimalSparse.java index e9c03c8..cb0dc58 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalDenseDecimalSparse.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalDenseDecimalSparse.java @@ -26,6 +26,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -34,7 +36,10 @@ import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -42,15 +47,14 @@ import java.nio.ByteBuffer; public class Cast${type.from}${type.to} implements DrillSimpleFunc{ @Param ${type.from}Holder in; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Param BigIntHolder precision; @Param BigIntHolder scale; @Output ${type.to}Holder out; public void setup(RecordBatch incoming) { - int size = (${type.arraySize} * (org.apache.drill.common.util.DecimalUtility.integerSize)); - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[size]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + int size = (${type.arraySize} * (org.apache.drill.exec.util.DecimalUtility.integerSize)); + buffer = buffer.reallocIfNeeded(size); } public void eval() { @@ -59,11 +63,11 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ // Re initialize the buffer everytime for (int i = 0; i < ${type.arraySize}; i++) { - out.setInteger(i, 0); + out.setInteger(i, 0, out.start, out.buffer); } out.scale = (int) scale.value; out.precision = (int) precision.value; - out.setSign(in.getSign()); + out.setSign(in.getSign(in.start, in.buffer), out.start, out.buffer); /* We store base 1 Billion integers in our representation, which requires * 30 bits, but a typical integer requires 32 bits. In our dense representation @@ -71,7 +75,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ * representation rearrange the bits so that we use 32 bits represent the digits. */ - byte[] intermediateBytes = new byte[(in.nDecimalDigits * org.apache.drill.common.util.DecimalUtility.integerSize) + 1]; + byte[] intermediateBytes = new byte[(in.nDecimalDigits * org.apache.drill.exec.util.DecimalUtility.integerSize) + 1]; int[] mask = {0x03, 0x0F, 0x3F, 0xFF}; int[] reverseMask = {0xFC, 0xF0, 0xC0, 0x00}; @@ -100,7 +104,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ inputIndex++; intermediateIndex++; - if (((intermediateIndex - 1) % org.apache.drill.common.util.DecimalUtility.integerSize) == 0) { + if (((intermediateIndex - 1) % org.apache.drill.exec.util.DecimalUtility.integerSize) == 0) { shiftBits = (byte) ((shiftBits & 0xFF) >>> 2); maskIndex++; shiftOrder -= 2; @@ -115,7 +119,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ * Now we transfer the bytes into a integer array and separate out the scale and * integer part of the decimal. Also pad the scale part with zeroes if needed */ - int[] intermediate = new int[(intermediateBytes.length/org.apache.drill.common.util.DecimalUtility.integerSize) + 1]; + int[] intermediate = new int[(intermediateBytes.length/org.apache.drill.exec.util.DecimalUtility.integerSize) + 1]; java.nio.ByteBuffer wrapper = java.nio.ByteBuffer.wrap(intermediateBytes); intermediate[0] = wrapper.get(0); @@ -132,27 +136,27 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ int dstIndex = out.nDecimalDigits - 1; // break the scale and integer part and pad zeroes - if (in.scale > 0 && (actualDigits = (in.scale % org.apache.drill.common.util.DecimalUtility.MAX_DIGITS)) > 0) { + if (in.scale > 0 && (actualDigits = (in.scale % org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS)) > 0) { - int paddedDigits = org.apache.drill.common.util.DecimalUtility.MAX_DIGITS - actualDigits; + int paddedDigits = org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS - actualDigits; int padding = (int) (Math.pow(10, paddedDigits)); int transferDigitMask = (int) (Math.pow(10, actualDigits)); /* copy the remaining scale over to the last deciml digit */ - out.setInteger(dstIndex, ((intermediate[srcIndex] % transferDigitMask) * (padding))); + out.setInteger(dstIndex, ((intermediate[srcIndex] % transferDigitMask) * (padding)), out.start, out.buffer); dstIndex--; while (srcIndex > 0) { - out.setInteger(dstIndex, ((intermediate[srcIndex]/transferDigitMask) + ((intermediate[srcIndex - 1] % transferDigitMask) * padding))); + out.setInteger(dstIndex, ((intermediate[srcIndex]/transferDigitMask) + ((intermediate[srcIndex - 1] % transferDigitMask) * padding)), out.start, out.buffer); dstIndex--; srcIndex--; } - out.setInteger(dstIndex, (intermediate[0]/transferDigitMask)); + out.setInteger(dstIndex, (intermediate[0]/transferDigitMask), out.start, out.buffer); } else { for (; srcIndex >= 0; srcIndex--, dstIndex--) - out.setInteger(dstIndex, intermediate[srcIndex]); + out.setInteger(dstIndex, intermediate[srcIndex], out.start, out.buffer); } } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalFloat.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalFloat.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalFloat.java index 92cd576..4d8d1a5 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalFloat.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalFloat.java @@ -34,7 +34,7 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; import io.netty.buffer.ByteBuf; import java.nio.ByteBuffer; @@ -52,7 +52,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { public void eval() { // Divide the decimal with the scale to get the floating point value - out.value = ((${type.javatype}) (in.value)) / (org.apache.drill.common.util.DecimalUtility.getPowerOfTen((int) in.scale)); + out.value = ((${type.javatype}) (in.value)) / (org.apache.drill.exec.util.DecimalUtility.getPowerOfTen((int) in.scale)); } } <#elseif type.major == "DecimalComplexFloat" || type.major == "DecimalComplexDouble"> <#-- Cast function template for conversion from Decimal9, Decimal18 to Float4 --> @@ -63,6 +63,8 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -70,7 +72,7 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; import io.netty.buffer.ByteBuf; import java.nio.ByteBuffer; @@ -88,9 +90,9 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { public void eval() { <#if type.from == "Decimal28Dense" || type.from == "Decimal38Dense"> - java.math.BigDecimal bigDecimal = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromDense(in.buffer, in.start, in.nDecimalDigits, in.scale, in.maxPrecision, in.WIDTH); + java.math.BigDecimal bigDecimal = org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDense(in.buffer, in.start, in.nDecimalDigits, in.scale, in.maxPrecision, in.WIDTH); <#else> - java.math.BigDecimal bigDecimal = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromByteBuf(in.buffer, in.start, in.nDecimalDigits, in.scale, true); + java.math.BigDecimal bigDecimal = org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDrillBuf(in.buffer, in.start, in.nDecimalDigits, in.scale, true); </#if> out.value = bigDecimal.${type.javatype}Value(); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalInt.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalInt.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalInt.java index 57c38a1..c435f6d 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalInt.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalInt.java @@ -28,6 +28,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -35,7 +37,7 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; import io.netty.buffer.ByteBuf; import java.nio.ByteBuffer; @@ -52,9 +54,9 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { public void eval() { - int carry = (org.apache.drill.common.util.DecimalUtility.getFirstFractionalDigit(in.value, in.scale) > 4) ? 1 : 0; + int carry = (org.apache.drill.exec.util.DecimalUtility.getFirstFractionalDigit(in.value, in.scale) > 4) ? 1 : 0; // Assign the integer part of the decimal to the output holder - out.value = java.lang.Math.abs((${type.javatype}) (org.apache.drill.common.util.DecimalUtility.adjustScaleDivide(in.value, (int) in.scale))) + carry; + out.value = java.lang.Math.abs((${type.javatype}) (org.apache.drill.exec.util.DecimalUtility.adjustScaleDivide(in.value, (int) in.scale))) + carry; if (in.value < 0) { out.value *= -1; } @@ -75,7 +77,7 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; import io.netty.buffer.ByteBuf; import java.nio.ByteBuffer; @@ -92,19 +94,19 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { public void eval() { - int carry = (org.apache.drill.common.util.DecimalUtility.getFirstFractionalDigit(in.buffer, in.scale, in.start, in.nDecimalDigits) > 4) ? 1 : 0; + int carry = (org.apache.drill.exec.util.DecimalUtility.getFirstFractionalDigit(in.buffer, in.scale, in.start, in.nDecimalDigits) > 4) ? 1 : 0; // Get the index, where the integer part of the decimal ends - int integerEndIndex = in.nDecimalDigits - org.apache.drill.common.util.DecimalUtility.roundUp(in.scale); + int integerEndIndex = in.nDecimalDigits - org.apache.drill.exec.util.DecimalUtility.roundUp(in.scale); for (int i = 0 ; i < integerEndIndex; i++) { // We store values as base 1 billion integers, use this to compute the output (we don't care about overflows) - out.value = (${type.javatype}) ((out.value * org.apache.drill.common.util.DecimalUtility.DIGITS_BASE) + in.getInteger(i)); + out.value = (${type.javatype}) ((out.value * org.apache.drill.exec.util.DecimalUtility.DIGITS_BASE) + in.getInteger(i, in.start, in.buffer)); } out.value += carry; - if (in.getSign() == true) { + if (in.getSign(in.start, in.buffer) == true) { out.value *= -1; } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java ---------------------------------------------------------------------- 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 9a2d3e5..8c46b49 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSimilar.java @@ -28,6 +28,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -36,7 +38,10 @@ import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -44,15 +49,14 @@ import java.nio.ByteBuffer; public class Cast${type.from}${type.to} implements DrillSimpleFunc{ @Param ${type.from}Holder in; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Param BigIntHolder precision; @Param BigIntHolder scale; @Output ${type.to}Holder out; public void setup(RecordBatch incoming) { - int size = (${type.arraySize} * (org.apache.drill.common.util.DecimalUtility.integerSize)); - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[size]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + int size = (${type.arraySize} * (org.apache.drill.exec.util.DecimalUtility.integerSize)); + buffer = buffer.reallocIfNeeded(size); } public void eval() { @@ -61,25 +65,25 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ out.start = 0; out.scale = (int) scale.value; out.precision = (int) precision.value; - boolean sign = (in.getSign()); + boolean sign = (in.getSign(in.start, in.buffer)); // Re initialize the buffer everytime for (int i = 0; i < ${type.arraySize}; i++) { - out.setInteger(i, 0); + out.setInteger(i, 0, out.start, out.buffer); } int inputIdx = in.nDecimalDigits - 1; int outputIdx = out.nDecimalDigits - 1; for (; inputIdx >= 0; inputIdx--, outputIdx--) { - out.setInteger(outputIdx, in.getInteger(inputIdx)); + out.setInteger(outputIdx, in.getInteger(inputIdx, in.start, in.buffer), out.start, out.buffer); } // round up or down the scale if (in.scale != out.scale) { - org.apache.drill.common.util.DecimalUtility.roundDecimal(out.buffer, out.start, out.nDecimalDigits, out.scale, in.scale); + org.apache.drill.exec.util.DecimalUtility.roundDecimal(out.buffer, out.start, out.nDecimalDigits, out.scale, in.scale); } - out.setSign(sign); + out.setSign(sign, in.start, in.buffer); } } </#if> <#-- type.major --> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSparseDecimalDense.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSparseDecimalDense.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSparseDecimalDense.java index e9e9711..0f8790f 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSparseDecimalDense.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalSparseDecimalDense.java @@ -26,6 +26,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -34,7 +36,10 @@ import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -42,15 +47,14 @@ import java.nio.ByteBuffer; public class Cast${type.from}${type.to} implements DrillSimpleFunc{ @Param ${type.from}Holder in; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Param BigIntHolder precision; @Param BigIntHolder scale; @Output ${type.to}Holder out; public void setup(RecordBatch incoming) { - int size = (${type.arraySize} * (org.apache.drill.common.util.DecimalUtility.integerSize)); - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[size]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + int size = (${type.arraySize} * (org.apache.drill.exec.util.DecimalUtility.integerSize)); + buffer = buffer.reallocIfNeeded(size); } public void eval() { @@ -60,7 +64,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ // Re initialize the buffer everytime for (int i = 0; i < ${type.arraySize}; i++) { - out.setInteger(i, 0); + out.setInteger(i, 0, out.start, out.buffer); } out.scale = (int) scale.value; @@ -78,9 +82,9 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ int index = in.nDecimalDigits - 1; int actualDigits; - if (in.scale > 0 && (actualDigits = (in.scale % org.apache.drill.common.util.DecimalUtility.MAX_DIGITS)) > 0) { + if (in.scale > 0 && (actualDigits = (in.scale % org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS)) > 0) { - int paddedDigits = org.apache.drill.common.util.DecimalUtility.MAX_DIGITS - actualDigits; + int paddedDigits = org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS - actualDigits; int paddedMask = (int) Math.pow(10, paddedDigits); @@ -88,16 +92,16 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ * digit, so we have padded zeroes to it for ease of arithmetic * Truncate the extra zeroes added and move the digits to the right */ - int temp = (in.getInteger(index)/paddedMask); + int temp = (in.getInteger(index, in.start, in.buffer)/paddedMask); index--; while(index >= 0) { - int transferDigits = (in.getInteger(index) % (paddedMask)); + int transferDigits = (in.getInteger(index, in.start, in.buffer) % (paddedMask)); intermediate[index] = (int) (temp + (Math.pow(10, actualDigits) * transferDigits)); - temp = (in.getInteger(index)/(paddedMask)); + temp = (in.getInteger(index, in.start, in.buffer)/(paddedMask)); index--; } @@ -108,7 +112,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ * need only 5 decimal digit to be stored, simply copy over the integers */ for (int i = 1; i < in.nDecimalDigits; i++) - intermediate[i - 1] = in.getInteger(i); + intermediate[i - 1] = in.getInteger(i, in.start, in.buffer); } @@ -120,14 +124,14 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ */ /* Allocate a byte array */ - int size = (((intermediate.length - 1) * org.apache.drill.common.util.DecimalUtility.integerSize) + 1); + int size = (((intermediate.length - 1) * org.apache.drill.exec.util.DecimalUtility.integerSize) + 1); byte[] intermediateBytes = new byte[size]; java.nio.ByteBuffer wrapper = java.nio.ByteBuffer.wrap(intermediateBytes); wrapper.put((byte) intermediate[0]); for (int i = 1; i < intermediate.length; i++) { - wrapper.put(java.nio.ByteBuffer.allocate(org.apache.drill.common.util.DecimalUtility.integerSize).putInt(intermediate[i]).array()); + wrapper.put(java.nio.ByteBuffer.allocate(org.apache.drill.exec.util.DecimalUtility.integerSize).putInt(intermediate[i]).array()); } final int[] mask = {0x03, 0x0F, 0x3F, 0xFF}; @@ -135,21 +139,21 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ int shiftOrder = 2; // Start just after the last integer and shift bits to the right - index = size - (org.apache.drill.common.util.DecimalUtility.integerSize+ 1); + index = size - (org.apache.drill.exec.util.DecimalUtility.integerSize+ 1); while (index >= 0) { /* get the last bits that need to shifted to the next byte */ byte shiftBits = (byte) ((intermediateBytes[index] & mask[maskIndex]) << (8 - shiftOrder)); - int shiftOrder1 = ((index % org.apache.drill.common.util.DecimalUtility.integerSize) == 0) ? shiftOrder - 2 : shiftOrder; + int shiftOrder1 = ((index % org.apache.drill.exec.util.DecimalUtility.integerSize) == 0) ? shiftOrder - 2 : shiftOrder; /* transfer the bits from the left to the right */ intermediateBytes[index + 1] = (byte) (((intermediateBytes[index + 1] & 0xFF) >>> (shiftOrder1)) | shiftBits); index--; - if ((index % org.apache.drill.common.util.DecimalUtility.integerSize) == 0) { + if ((index % org.apache.drill.exec.util.DecimalUtility.integerSize) == 0) { /* We are on a border */ shiftOrder += 2; maskIndex++; @@ -167,7 +171,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ // Set the bytes in the buffer out.buffer.setBytes(dstIndex, intermediateBytes, 1, (size - 1)); - out.setSign(in.getSign()); + out.setSign(in.getSign(in.start, in.buffer), out.start, out.buffer); } } </#if> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalVarchar.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalVarchar.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalVarchar.java index dc8eca5..ed62444 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalVarchar.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDecimalVarchar.java @@ -28,6 +28,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -35,10 +37,13 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; import io.netty.buffer.SwappedByteBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -47,12 +52,11 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { @Param ${type.from}Holder in; @Param BigIntHolder len; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Output ${type.to}Holder out; public void setup(RecordBatch incoming) { - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[${type.bufferSize}]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + buffer = buffer.reallocIfNeeded(${type.bufferSize}); } public void eval() { @@ -67,7 +71,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { in.value *= -1; } - ${type.javatype} separator = (${type.javatype}) org.apache.drill.common.util.DecimalUtility.getPowerOfTen((int) in.scale); + ${type.javatype} separator = (${type.javatype}) org.apache.drill.exec.util.DecimalUtility.getPowerOfTen((int) in.scale); str.append(in.value / separator); @@ -90,7 +94,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { * * We missed the initial zeroes in the fractional part. Below logic accounts for this case */ - str.append(org.apache.drill.common.util.DecimalUtility.toStringWithZeroes((in.value % separator), in.scale)); + str.append(org.apache.drill.exec.util.DecimalUtility.toStringWithZeroes((in.value % separator), in.scale)); } out.buffer = buffer; @@ -107,6 +111,8 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -114,9 +120,11 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -125,28 +133,27 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { @Param ${type.from}Holder in; @Param BigIntHolder len; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Output ${type.to}Holder out; public void setup(RecordBatch incoming) { - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[${type.bufferSize}]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + buffer = buffer.reallocIfNeeded((int) len.value); } public void eval() { StringBuilder str = new StringBuilder(); int index = 0; - int fractionalStartIndex = ${type.arraySize} - org.apache.drill.common.util.DecimalUtility.roundUp(in.scale); + int fractionalStartIndex = ${type.arraySize} - org.apache.drill.exec.util.DecimalUtility.roundUp(in.scale); // Find the first non-zero value in the integer part of the decimal - while (index < fractionalStartIndex && in.getInteger(index) == 0) { + while (index < fractionalStartIndex && in.getInteger(index, in.start, in.buffer) == 0) { index++; } // If we have valid digits print '-' sign - if ((in.getSign() == true) && index < ${type.arraySize}) { + if ((in.getSign(in.start, in.buffer) == true) && index < ${type.arraySize}) { str.append("-"); } @@ -159,10 +166,10 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { // convert the integer part while (index < fractionalStartIndex) { - int value = in.getInteger(index++); + int value = in.getInteger(index++, in.start, in.buffer); if (fillZeroes == true) { - str.append(org.apache.drill.common.util.DecimalUtility.toStringWithZeroes(value, org.apache.drill.common.util.DecimalUtility.MAX_DIGITS)); + str.append(org.apache.drill.exec.util.DecimalUtility.toStringWithZeroes(value, org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS)); } else { str.append(value); fillZeroes = true; @@ -178,25 +185,25 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { * as it might have padding that needs to be stripped */ while (fractionalStartIndex < ${type.arraySize} - 1) { - int value = in.getInteger(fractionalStartIndex++); + int value = in.getInteger(fractionalStartIndex++, in.start, in.buffer); // Fill zeroes at the beginning of the decimal digit - str.append(org.apache.drill.common.util.DecimalUtility.toStringWithZeroes(value, org.apache.drill.common.util.DecimalUtility.MAX_DIGITS)); + str.append(org.apache.drill.exec.util.DecimalUtility.toStringWithZeroes(value, org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS)); } // Last decimal digit, strip the extra zeroes we may have padded - int actualDigits = in.scale % org.apache.drill.common.util.DecimalUtility.MAX_DIGITS; + int actualDigits = in.scale % org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS; - int lastFractionalDigit = in.getInteger(${type.arraySize} - 1); + int lastFractionalDigit = in.getInteger(${type.arraySize} - 1, in.start, in.buffer); if (actualDigits != 0) { // Strip padded zeroes at the end that is not part of the scale - lastFractionalDigit /= (int) (org.apache.drill.common.util.DecimalUtility.getPowerOfTen((int) (org.apache.drill.common.util.DecimalUtility.MAX_DIGITS - actualDigits))); - str.append(org.apache.drill.common.util.DecimalUtility.toStringWithZeroes(lastFractionalDigit, actualDigits)); + lastFractionalDigit /= (int) (org.apache.drill.exec.util.DecimalUtility.getPowerOfTen((int) (org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS - actualDigits))); + str.append(org.apache.drill.exec.util.DecimalUtility.toStringWithZeroes(lastFractionalDigit, actualDigits)); } else { // Last digit does not have any padding print as is - str.append(org.apache.drill.common.util.DecimalUtility.toStringWithZeroes(lastFractionalDigit, org.apache.drill.common.util.DecimalUtility.MAX_DIGITS)); + str.append(org.apache.drill.exec.util.DecimalUtility.toStringWithZeroes(lastFractionalDigit, org.apache.drill.exec.util.DecimalUtility.MAX_DIGITS)); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastDownwardDecimal.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastDownwardDecimal.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastDownwardDecimal.java index 516ec82..bd86819 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastDownwardDecimal.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastDownwardDecimal.java @@ -26,6 +26,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -33,9 +35,12 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -56,12 +61,12 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { out.value = (int) in.value; // Check if we need to truncate or round up if (out.scale > in.scale) { - out.value *= (int) org.apache.drill.common.util.DecimalUtility.getPowerOfTen(out.scale - in.scale); + out.value *= (int) org.apache.drill.exec.util.DecimalUtility.getPowerOfTen(out.scale - in.scale); } else if (out.scale < in.scale) { // need to round up since we are truncating fractional part - int scaleFactor = (int) (org.apache.drill.common.util.DecimalUtility.getPowerOfTen((int) in.scale)); - int newScaleFactor = (int) (org.apache.drill.common.util.DecimalUtility.getPowerOfTen((int) scale.value)); - int truncScaleFactor = (int) (org.apache.drill.common.util.DecimalUtility.getPowerOfTen( (int) (Math.abs(in.scale - scale.value)))); + int scaleFactor = (int) (org.apache.drill.exec.util.DecimalUtility.getPowerOfTen((int) in.scale)); + int newScaleFactor = (int) (org.apache.drill.exec.util.DecimalUtility.getPowerOfTen((int) scale.value)); + int truncScaleFactor = (int) (org.apache.drill.exec.util.DecimalUtility.getPowerOfTen( (int) (Math.abs(in.scale - scale.value)))); int truncFactor = (int) (in.scale - scale.value); // Assign the integer part @@ -71,11 +76,11 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { int fractionalPart = (int) (in.value % scaleFactor); // From the entire fractional part extract the digits upto which rounding is needed - int newFractionalPart = (int) (org.apache.drill.common.util.DecimalUtility.adjustScaleDivide(fractionalPart, truncFactor)); + int newFractionalPart = (int) (org.apache.drill.exec.util.DecimalUtility.adjustScaleDivide(fractionalPart, truncFactor)); int truncatedFraction = fractionalPart % truncScaleFactor; // Get the truncated fractional part and extract the first digit to see if we need to add 1 - int digit = Math.abs((int) org.apache.drill.common.util.DecimalUtility.adjustScaleDivide(truncatedFraction, truncFactor - 1)); + int digit = Math.abs((int) org.apache.drill.exec.util.DecimalUtility.adjustScaleDivide(truncatedFraction, truncFactor - 1)); if (digit > 4) { if (in.value > 0) { @@ -95,6 +100,8 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -102,9 +109,11 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -120,7 +129,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { } public void eval() { - java.math.BigDecimal temp = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(in.buffer, in.start, in.nDecimalDigits, in.scale); + java.math.BigDecimal temp = org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromSparse(in.buffer, in.start, in.nDecimalDigits, in.scale); temp = temp.setScale((int) scale.value, java.math.BigDecimal.ROUND_HALF_UP); out.value = temp.unscaledValue().${type.javatype}Value(); out.precision = (int) precision.value; @@ -134,6 +143,8 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -141,9 +152,11 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -153,23 +166,22 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { @Param ${type.from}Holder in; @Param BigIntHolder precision; @Param BigIntHolder scale; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Output ${type.to}Holder out; public void setup(RecordBatch incoming) { - int size = (${type.arraySize} * (org.apache.drill.common.util.DecimalUtility.integerSize)); - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[size]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + int size = (${type.arraySize} * (org.apache.drill.exec.util.DecimalUtility.integerSize)); + buffer = buffer.reallocIfNeeded(size); } public void eval() { - java.math.BigDecimal temp = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(in.buffer, in.start, in.nDecimalDigits, in.scale); + java.math.BigDecimal temp = org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromSparse(in.buffer, in.start, in.nDecimalDigits, in.scale); temp = temp.setScale((int) scale.value, java.math.BigDecimal.ROUND_HALF_UP); out.precision = (int) precision.value; out.scale = (int) scale.value; out.buffer = buffer; out.start = 0; - org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(temp, out.buffer, out.start, out.scale, out.precision, out.nDecimalDigits); + org.apache.drill.exec.util.DecimalUtility.getSparseFromBigDecimal(temp, out.buffer, out.start, out.scale, out.precision, out.nDecimalDigits); } } </#if> <#-- type.major --> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java index f4a5c77..c05b2e5 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java @@ -29,6 +29,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -36,9 +38,12 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -47,7 +52,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { @Param ${type.from}Holder in; <#if type.major == "FloatDecimalComplex" || type.major == "DoubleDecimalComplex"> -@Workspace ByteBuf buffer; +@Inject DrillBuf buffer; </#if> @Param BigIntHolder precision; @Param BigIntHolder scale; @@ -55,9 +60,8 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { public void setup(RecordBatch incoming) { <#if type.major == "FloatDecimalComplex" || type.major == "DoubleDecimalComplex"> - int size = ${type.arraySize} * (org.apache.drill.common.util.DecimalUtility.integerSize); - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[size]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + int size = ${type.arraySize} * (org.apache.drill.exec.util.DecimalUtility.integerSize); + buffer = buffer.reallocIfNeeded(size); </#if> } @@ -71,12 +75,12 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { out.buffer = buffer; // Assign the integer part of the decimal to the output holder - org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(new java.math.BigDecimal(String.valueOf(in.value)), out.buffer, out.start, out.scale, out.precision, out.nDecimalDigits); + org.apache.drill.exec.util.DecimalUtility.getSparseFromBigDecimal(new java.math.BigDecimal(String.valueOf(in.value)), out.buffer, out.start, out.scale, out.precision, out.nDecimalDigits); <#elseif type.to.endsWith("Decimal9")> - out.value = org.apache.drill.common.util.DecimalUtility.getDecimal9FromBigDecimal(new java.math.BigDecimal(String.valueOf(in.value)), out.scale, out.precision); + out.value = org.apache.drill.exec.util.DecimalUtility.getDecimal9FromBigDecimal(new java.math.BigDecimal(String.valueOf(in.value)), out.scale, out.precision); <#elseif type.to.endsWith("Decimal18")> - out.value = org.apache.drill.common.util.DecimalUtility.getDecimal18FromBigDecimal(new java.math.BigDecimal(String.valueOf(in.value)), out.scale, out.precision); + out.value = org.apache.drill.exec.util.DecimalUtility.getDecimal18FromBigDecimal(new java.math.BigDecimal(String.valueOf(in.value)), out.scale, out.precision); </#if> } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java index 78bde2e..139fff8 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java @@ -25,6 +25,8 @@ package org.apache.drill.exec.expr.fn.impl.gcast; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillSimpleFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; @@ -32,9 +34,12 @@ import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.expr.annotations.Workspace; + import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; + import java.nio.ByteBuffer; @SuppressWarnings("unused") @@ -43,7 +48,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { @Param ${type.from}Holder in; <#if type.to.startsWith("Decimal28") || type.to.startsWith("Decimal38")> - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; </#if> @Param BigIntHolder precision; @Param BigIntHolder scale; @@ -51,9 +56,8 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { public void setup(RecordBatch incoming) { <#if type.to.startsWith("Decimal28") || type.to.startsWith("Decimal38")> - int size = ${type.arraySize} * (org.apache.drill.common.util.DecimalUtility.integerSize); - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[size]); - buffer = new io.netty.buffer.SwappedByteBuf(buffer); + int size = ${type.arraySize} * (org.apache.drill.exec.util.DecimalUtility.integerSize); + buffer = buffer.reallocIfNeeded(size); </#if> } @@ -66,7 +70,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { out.value = (${type.javatype}) in.value; // converting from integer to decimal, pad zeroes if scale is non zero - out.value = (${type.javatype}) org.apache.drill.common.util.DecimalUtility.adjustScaleMultiply(out.value, (int) scale.value); + out.value = (${type.javatype}) org.apache.drill.exec.util.DecimalUtility.adjustScaleMultiply(out.value, (int) scale.value); <#else> out.start = 0; @@ -74,21 +78,21 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { // Initialize the buffer for (int i = 0; i < ${type.arraySize}; i++) { - out.setInteger(i, 0); + out.setInteger(i, 0, out.start, out.buffer); } // check if input is a negative number and store the sign if (in.value < 0) { - out.setSign(true); + out.setSign(true, out.start, out.buffer); } // Figure out how many array positions to be left for the scale part - int scaleSize = org.apache.drill.common.util.DecimalUtility.roundUp((int) scale.value); + int scaleSize = org.apache.drill.exec.util.DecimalUtility.roundUp((int) scale.value); int integerIndex = (${type.arraySize} - scaleSize - 1); while (in.value != 0 && integerIndex >= 0) { - out.setInteger(integerIndex--, (int) Math.abs((in.value % org.apache.drill.common.util.DecimalUtility.DIGITS_BASE))); - in.value = in.value / org.apache.drill.common.util.DecimalUtility.DIGITS_BASE; + out.setInteger(integerIndex--, (int) Math.abs((in.value % org.apache.drill.exec.util.DecimalUtility.DIGITS_BASE)), out.start, out.buffer); + in.value = in.value / org.apache.drill.exec.util.DecimalUtility.DIGITS_BASE; } </#if>