http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java index 406d883..8b4496e 100644 --- a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java +++ b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java @@ -117,7 +117,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F } @Override - public int load(int valueCount, ByteBuf buf){ + public int load(int valueCount, DrillBuf buf){ clear(); this.valueCount = valueCount; int len = valueCount * ${type.width}; @@ -128,10 +128,10 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F } @Override - public void load(SerializedField metadata, ByteBuf buffer) { - assert this.field.matches(metadata); + public void load(SerializedField metadata, DrillBuf buffer) { + assert this.field.matches(metadata) : String.format("The field %s doesn't match the provided metadata %s.", this.field, metadata); int loaded = load(metadata.getValueCount(), buffer); - assert metadata.getBufferLength() == loaded; + assert metadata.getBufferLength() == loaded : String.format("Expected to load %d bytes but actually loaded %d bytes", metadata.getBufferLength(), loaded); } public TransferPair getTransferPair(){ @@ -241,23 +241,19 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F <#if (type.width > 8)> public ${minor.javaType!type.javaType} get(int index) { - ByteBuf dst = io.netty.buffer.Unpooled.wrappedBuffer(new byte[${type.width}]); - //dst = new io.netty.buffer.SwappedByteBuf(dst); - data.getBytes(index * ${type.width}, dst, 0, ${type.width}); - - return dst; + return data.slice(index * ${type.width}, ${type.width}); } <#if (minor.class == "TimeStampTZ")> public void get(int index, ${minor.class}Holder holder){ holder.value = data.getLong(index * ${type.width}); - holder.index = data.getInt((index * ${type.width})+ ${minor.milliSecondsSize}); + holder.index = data.getInt((index * ${type.width})+ ${minor.millisecondsSize}); } public void get(int index, Nullable${minor.class}Holder holder){ holder.isSet = 1; holder.value = data.getLong(index * ${type.width}); - holder.index = data.getInt((index * ${type.width})+ ${minor.milliSecondsSize}); + holder.index = data.getInt((index * ${type.width})+ ${minor.millisecondsSize}); } @Override @@ -273,7 +269,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F int offsetIndex = index * ${type.width}; holder.months = data.getInt(offsetIndex); holder.days = data.getInt(offsetIndex + ${minor.daysOffset}); - holder.milliSeconds = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset}); } public void get(int index, Nullable${minor.class}Holder holder){ @@ -281,7 +277,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F holder.isSet = 1; holder.months = data.getInt(offsetIndex); holder.days = data.getInt(offsetIndex + ${minor.daysOffset}); - holder.milliSeconds = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset}); } @Override @@ -289,7 +285,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F int offsetIndex = index * ${type.width}; int months = data.getInt(offsetIndex); int days = data.getInt(offsetIndex + ${minor.daysOffset}); - int millis = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset}); Period p = new Period(); return p.plusMonths(months).plusDays(days).plusMillis(millis); } @@ -300,7 +296,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F int months = data.getInt(offsetIndex); int days = data.getInt(offsetIndex + ${minor.daysOffset}); - int millis = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset}); int years = (months / org.apache.drill.exec.expr.fn.impl.DateUtility.yearsToMonths); months = (months % org.apache.drill.exec.expr.fn.impl.DateUtility.yearsToMonths); @@ -334,20 +330,20 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F int offsetIndex = index * ${type.width}; holder.days = data.getInt(offsetIndex); - holder.milliSeconds = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset}); } public void get(int index, Nullable${minor.class}Holder holder){ int offsetIndex = index * ${type.width}; holder.isSet = 1; holder.days = data.getInt(offsetIndex); - holder.milliSeconds = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset}); } @Override public ${friendlyType} getObject(int index) { int offsetIndex = index * ${type.width}; - int millis = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset}); int days = data.getInt(offsetIndex); Period p = new Period(); return p.plusDays(days).plusMillis(millis); @@ -357,7 +353,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F public StringBuilder getAsStringBuilder(int index) { int offsetIndex = index * ${type.width}; - int millis = data.getInt(offsetIndex + ${minor.milliSecondsOffset}); + int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset}); int days = data.getInt(offsetIndex); int hours = millis / (org.apache.drill.exec.expr.fn.impl.DateUtility.hoursToMillis); @@ -408,9 +404,9 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F public ${friendlyType} getObject(int index) { <#if (minor.class == "Decimal28Sparse") || (minor.class == "Decimal38Sparse")> // Get the BigDecimal object - return org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(data, index * ${type.width}, ${minor.nDecimalDigits}, getField().getScale()); + return org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromSparse(data, index * ${type.width}, ${minor.nDecimalDigits}, getField().getScale()); <#else> - return org.apache.drill.common.util.DecimalUtility.getBigDecimalFromDense(data, index * ${type.width}, ${minor.nDecimalDigits}, getField().getScale(), ${minor.maxPrecisionDigits}, ${type.width}); + return org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDense(data, index * ${type.width}, ${minor.nDecimalDigits}, getField().getScale(), ${minor.maxPrecisionDigits}, ${type.width}); </#if> } @@ -428,15 +424,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F @Override public ${friendlyType} getObject(int index) { - - ByteBuf dst = io.netty.buffer.Unpooled.wrappedBuffer(new byte[${type.width}]); - //dst = new io.netty.buffer.SwappedByteBuf(dst); - data.getBytes(index * ${type.width}, dst, 0, ${type.width}); - - return dst; - - - + return data.slice(index * ${type.width}, ${type.width}) } </#if> @@ -445,6 +433,13 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F public ${minor.javaType!type.javaType} get(int index) { return data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width}); } + + <#if type.width == 4> + public long getTwoAsLong(int index) { + return data.getLong(index * ${type.width}); + } + + </#if> <#if minor.class == "Date"> public ${friendlyType} getObject(int index) { @@ -513,6 +508,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F return get(index); } </#if> + public void get(int index, ${minor.class}Holder holder){ <#if minor.class.startsWith("Decimal")> holder.scale = getField().getScale(); @@ -521,7 +517,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F holder.value = data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width}); } - + public void get(int index, Nullable${minor.class}Holder holder){ holder.isSet = 1; holder.value = data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width}); @@ -545,7 +541,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F private Mutator(){}; /** * Set the element at the given index to the given value. Note that widths smaller than - * 32 bits are handled by the ByteBuf interface. + * 32 bits are handled by the DrillBuf interface. * * @param index position of the bit to set * @param value value to set @@ -565,131 +561,152 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F } <#if (minor.class == "TimeStampTZ")> + public void set(int index, long timestamp, int tzindex){ + data.setLong((index * ${type.width}), timestamp); + data.setInt(((index * ${type.width}) + ${minor.millisecondsSize}), tzindex); + } + protected void set(int index, ${minor.class}Holder holder){ - data.setLong((index * ${type.width}), holder.value); - data.setInt(((index * ${type.width}) + ${minor.milliSecondsSize}), holder.index); - + set(index, holder.value, holder.index); } protected void set(int index, Nullable${minor.class}Holder holder){ - data.setLong((index * ${type.width}), holder.value); - data.setInt(((index * ${type.width}) + ${minor.milliSecondsSize}), holder.index); + set(index, holder.value, holder.index); } - public boolean setSafe(int index, ${minor.class}Holder holder){ + public boolean setSafe(int index, long timestamp, int tzindex){ if(index >= getValueCapacity()) { decrementAllocationMonitor(); return false; } - set(index, holder); + set(index, timestamp, tzindex); return true; } + + public boolean setSafe(int index, ${minor.class}Holder holder){ + return setSafe(index, holder.value, holder.index); + } public boolean setSafe(int index, Nullable${minor.class}Holder holder){ - if(index >= getValueCapacity()) { - decrementAllocationMonitor(); - return false; - } - set(index, holder); - return true; + return setSafe(index, holder.value, holder.index); } + <#elseif (minor.class == "Interval")> - protected void set(int index, ${minor.class}Holder holder){ + public void set(int index, int months, int days, int milliseconds){ int offsetIndex = index * ${type.width}; - data.setInt(offsetIndex, holder.months); - data.setInt((offsetIndex + ${minor.daysOffset}), holder.days); - data.setInt((offsetIndex + ${minor.milliSecondsOffset}), holder.milliSeconds); + data.setInt(offsetIndex, months); + data.setInt((offsetIndex + ${minor.daysOffset}), days); + data.setInt((offsetIndex + ${minor.millisecondsOffset}), milliseconds); } - + + protected void set(int index, ${minor.class}Holder holder){ + set(index, holder.months, holder.days, holder.milliseconds); + } + protected void set(int index, Nullable${minor.class}Holder holder){ - int offsetIndex = index * ${type.width}; - data.setInt(offsetIndex, holder.months); - data.setInt((offsetIndex + ${minor.daysOffset}), holder.days); - data.setInt((offsetIndex + ${minor.milliSecondsOffset}), holder.milliSeconds); + set(index, holder.months, holder.days, holder.milliseconds); } - public boolean setSafe(int index, ${minor.class}Holder holder){ + public boolean setSafe(int index, int months, int days, int milliseconds){ if(index >= getValueCapacity()) { decrementAllocationMonitor(); return false; } - set(index, holder); + set(index, months, days, milliseconds); return true; } public boolean setSafe(int index, Nullable${minor.class}Holder holder){ - if(index >= getValueCapacity()) { - decrementAllocationMonitor(); - return false; - } - set(index, holder); - return true; + return setSafe(index, holder.months, holder.days, holder.milliseconds); + } + + public boolean setSafe(int index, ${minor.class}Holder holder){ + return setSafe(index, holder.months, holder.days, holder.milliseconds); } + <#elseif (minor.class == "IntervalDay")> - protected void set(int index, ${minor.class}Holder holder){ + public void set(int index, int days, int milliseconds){ int offsetIndex = index * ${type.width}; - data.setInt(offsetIndex, holder.days); - data.setInt((offsetIndex + ${minor.milliSecondsOffset}), holder.milliSeconds); + data.setInt(offsetIndex, days); + data.setInt((offsetIndex + ${minor.millisecondsOffset}), milliseconds); + } + + protected void set(int index, ${minor.class}Holder holder){ + set(index, holder.days, holder.milliseconds); } - protected void set(int index, Nullable${minor.class}Holder holder){ - int offsetIndex = index * ${type.width}; - data.setInt(offsetIndex, holder.days); - data.setInt((offsetIndex + ${minor.milliSecondsOffset}), holder.milliSeconds); + set(index, holder.days, holder.milliseconds); } - public boolean setSafe(int index, ${minor.class}Holder holder){ + public boolean setSafe(int index, int days, int milliseconds){ if(index >= getValueCapacity()) { decrementAllocationMonitor(); return false; } - set(index, holder); + set(index, days, milliseconds); return true; } + + public boolean setSafe(int index, ${minor.class}Holder holder){ + return setSafe(index, holder.days, holder.milliseconds); + } public boolean setSafe(int index, Nullable${minor.class}Holder holder){ - if(index >= getValueCapacity()) { - decrementAllocationMonitor(); - return false; - } - set(index, holder); - return true; + return setSafe(index, holder.days, holder.milliseconds); } <#elseif (minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse") || (minor.class == "Decimal28Dense") || (minor.class == "Decimal38Dense")> public void set(int index, ${minor.class}Holder holder){ - data.setBytes(index * ${type.width}, holder.buffer, holder.start, ${type.width}); + set(index, holder.start, holder.buffer); } void set(int index, Nullable${minor.class}Holder holder){ - data.setBytes(index * ${type.width}, holder.buffer, holder.start, ${type.width}); + set(index, holder.start, holder.buffer); } - + public boolean setSafe(int index, Nullable${minor.class}Holder holder){ - if(index >= getValueCapacity()) { - decrementAllocationMonitor(); - return false; - } - set(index, holder); - return true; + return setSafe(index, holder.start, holder.buffer); } - public boolean setSafe(int index, ${minor.class}Holder holder){ - if(index >= getValueCapacity()) { - decrementAllocationMonitor(); - return false; - } - set(index, holder); - return true; + return setSafe(index, holder.start, holder.buffer); + } + + public boolean setSafe(int index, int start, DrillBuf buffer){ + if(index >= getValueCapacity()) { + decrementAllocationMonitor(); + return false; + } + set(index, start, buffer); + return true; + } + + public void set(int index, int start, DrillBuf buffer){ + data.setBytes(index * ${type.width}, buffer, start, ${type.width}); } <#else> + protected void set(int index, ${minor.class}Holder holder){ - data.setBytes(index * ${type.width}, holder.buffer, holder.start, ${type.width}); + set(index, holder.start, holder.buffer); + } + + public void set(int index, Nullable${minor.class}Holder holder){ + set(index, holder.start, holder.buffer); + } + + public void set(int index, int start, DrillBuf buffer){ + data.setBytes(index * ${type.width}, buffer, start, ${type.width}); } public boolean setSafe(int index, ${minor.class}Holder holder){ + return setSafe(index, holder.start, holder.buffer); + } + public boolean setSafe(int index, Nullable${minor.class}Holder holder){ + return setSafe(index, holder.start, holder.buffer); + } + + public boolean setSafe(int index, int start, DrillBuf buffer){ if(index >= getValueCapacity()) { decrementAllocationMonitor(); return false; @@ -714,6 +731,9 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F } } } + + + <#else> <#-- type.width <= 8 --> public void set(int index, <#if (type.width >= 4)>${minor.javaType!type.javaType}<#else>int</#if> value) { @@ -767,6 +787,19 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F } } } + + + public void generateTestDataAlt(int size) { + setValueCount(size); + boolean even = true; + for(int i =0; i < valueCount; i++, even = !even){ + if(even){ + set(i, (${(minor.javaType!type.javaType)}) 1); + }else{ + set(i, (${(minor.javaType!type.javaType)}) 0); + } + } + } </#if> <#-- type.width -->
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/HolderReaderImpl.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/HolderReaderImpl.java b/exec/java-exec/src/main/codegen/templates/HolderReaderImpl.java index bd862a1..7d4ff31 100644 --- a/exec/java-exec/src/main/codegen/templates/HolderReaderImpl.java +++ b/exec/java-exec/src/main/codegen/templates/HolderReaderImpl.java @@ -96,15 +96,20 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { @Override public MajorType getType() { <#if holderMode == "Repeated"> - return this.repeatedHolder.getType(); + return this.repeatedHolder.TYPE; <#else> - return this.holder.getType(); + return this.holder.TYPE; </#if> } @Override public boolean isSet() { - return this.holder.isSet(); + <#if nullMode == "Nullable"> + return this.holder.isSet == 1; + <#else> + return true; + </#if> + } <#if holderMode == "Repeated"> @@ -122,7 +127,7 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { @Override public ${friendlyType} read${safeType}(){ <#if nullMode == "Nullable"> - if (!holder.isSet()) { + if (!isSet()) { return null; } </#if> @@ -145,11 +150,11 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { <#elseif minor.class == "Interval"> Period p = new Period(); - return p.plusMonths(holder.months).plusDays(holder.days).plusMillis(holder.milliSeconds); + return p.plusMonths(holder.months).plusDays(holder.days).plusMillis(holder.milliseconds); <#elseif minor.class == "IntervalDay"> Period p = new Period(); - return p.plusDays(holder.days).plusMillis(holder.milliSeconds); + return p.plusDays(holder.days).plusMillis(holder.milliseconds); <#elseif minor.class == "Decimal9" || minor.class == "Decimal18" > @@ -158,7 +163,7 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { <#elseif minor.class == "Decimal28Dense" || minor.class == "Decimal38Dense"> - return org.apache.drill.common.util.DecimalUtility.getBigDecimalFromDense(holder.buffer, + return org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDense(holder.buffer, holder.start, holder.nDecimalDigits, holder.scale, @@ -167,7 +172,7 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { <#elseif minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse"> - return org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(holder.buffer, + return org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromSparse(holder.buffer, holder.start, holder.nDecimalDigits, holder.scale); @@ -196,7 +201,7 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { private Object readSingleObject() { <#if nullMode == "Nullable"> - if (!holder.isSet()) { + if (!isSet()) { return null; } </#if> @@ -218,11 +223,11 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { <#elseif minor.class == "Interval"> Period p = new Period(); - return p.plusMonths(holder.months).plusDays(holder.days).plusMillis(holder.milliSeconds); + return p.plusMonths(holder.months).plusDays(holder.days).plusMillis(holder.milliseconds); <#elseif minor.class == "IntervalDay"> Period p = new Period(); - return p.plusDays(holder.days).plusMillis(holder.milliSeconds); + return p.plusDays(holder.days).plusMillis(holder.milliseconds); <#elseif minor.class == "Decimal9" || minor.class == "Decimal18" > @@ -231,7 +236,7 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { <#elseif minor.class == "Decimal28Dense" || minor.class == "Decimal38Dense"> - return org.apache.drill.common.util.DecimalUtility.getBigDecimalFromDense(holder.buffer, + return org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDense(holder.buffer, holder.start, holder.nDecimalDigits, holder.scale, @@ -240,7 +245,7 @@ public class ${holderMode}${name}HolderReaderImpl extends AbstractFieldReader { <#elseif minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse"> - return org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(holder.buffer, + return org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromSparse(holder.buffer, holder.start, holder.nDecimalDigits, holder.scale); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java b/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java index ba57210..c7f5918 100644 --- a/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java +++ b/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java @@ -80,10 +80,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu <#if type.inputType.endsWith("Interval")> sum.value += (long) in.months * org.apache.drill.exec.expr.fn.impl.DateUtility.monthToStandardDays + in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) + - in.milliSeconds; + in.milliseconds; <#elseif type.inputType.endsWith("IntervalDay")> sum.value += (long) in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) + - in.milliSeconds; + in.milliseconds; <#else> sum.value += in.value; </#if> @@ -104,11 +104,11 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu out.months = (int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis); millis = millis % org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis; out.days =(int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); - out.milliSeconds = (int) (millis % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); + out.milliseconds = (int) (millis % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); <#elseif type.inputType.endsWith("IntervalDay")> out.months = 0; out.days = (int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); - out.milliSeconds = (int) (millis % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis); + out.milliseconds = (int) (millis % 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/JsonOutputRecordWriter.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java b/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java index d1a6d4e..f0ddde2 100644 --- a/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java +++ b/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java @@ -37,7 +37,7 @@ import org.apache.drill.exec.record.BatchSchema; import org.apache.drill.exec.store.EventBasedRecordWriter.FieldConverter; import org.apache.drill.exec.store.parquet.ParquetTypeHelper; import org.apache.drill.exec.vector.*; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.vector.complex.reader.FieldReader; import parquet.io.api.RecordConsumer; import parquet.schema.MessageType; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java b/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java index 6876cab..ec99e79 100644 --- a/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java +++ b/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java @@ -47,15 +47,17 @@ package org.apache.drill.exec.vector; public final class ${className} extends BaseValueVector implements <#if type.major == "VarLen">VariableWidth<#else>FixedWidth</#if>Vector{ private int valueCount; - final BitVector bits; + final UInt1Vector bits; final ${valuesName} values; - private final Accessor accessor = new Accessor(); - private final Mutator mutator = new Mutator(); + private final Accessor accessor; + private final Mutator mutator; public ${className}(MaterializedField field, BufferAllocator allocator) { super(field, allocator); - this.bits = new BitVector(null, allocator); + this.bits = new UInt1Vector(null, allocator); this.values = new ${minor.class}Vector(field, allocator); + this.accessor = new Accessor(); + this.mutator = new Mutator(); } public int getValueCapacity(){ @@ -71,8 +73,8 @@ public final class ${className} extends BaseValueVector implements <#if type.maj } @Override - public ByteBuf[] getBuffers() { - ByteBuf[] buffers = ObjectArrays.concat(bits.getBuffers(), values.getBuffers(), ByteBuf.class); + public DrillBuf[] getBuffers() { + DrillBuf[] buffers = ObjectArrays.concat(bits.getBuffers(), values.getBuffers(), DrillBuf.class); clear(); return buffers; } @@ -88,7 +90,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj return values.getBufferSize() + bits.getBufferSize(); } - public ByteBuf getData(){ + public DrillBuf getData(){ return values.getData(); } @@ -126,7 +128,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj } @Override - public int load(int dataBytes, int valueCount, ByteBuf buf){ + public int load(int dataBytes, int valueCount, DrillBuf buf){ clear(); this.valueCount = valueCount; int loaded = bits.load(valueCount, buf); @@ -140,10 +142,10 @@ public final class ${className} extends BaseValueVector implements <#if type.maj } @Override - public void load(SerializedField metadata, ByteBuf buffer) { - assert this.field.matches(metadata); + public void load(SerializedField metadata, DrillBuf buffer) { + assert this.field.matches(metadata) : String.format("The field %s doesn't match the provided metadata %s.", this.field, metadata); int loaded = load(metadata.getBufferLength(), metadata.getValueCount(), buffer); - assert metadata.getBufferLength() == loaded; + assert metadata.getBufferLength() == loaded : String.format("Expected to load %d bytes but actually loaded %d bytes", metadata.getBufferLength(), loaded); } @Override @@ -199,7 +201,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj } @Override - public int load(int valueCount, ByteBuf buf){ + public int load(int valueCount, DrillBuf buf){ clear(); this.valueCount = valueCount; int loaded = bits.load(valueCount, buf); @@ -211,7 +213,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj } @Override - public void load(SerializedField metadata, ByteBuf buffer) { + public void load(SerializedField metadata, DrillBuf buffer) { assert this.field.matches(metadata); int loaded = load(metadata.getValueCount(), buffer); assert metadata.getBufferLength() == loaded; @@ -321,14 +323,30 @@ public final class ${className} extends BaseValueVector implements <#if type.maj return b1 && b2; } + public long getDataAddr(){ + return values.getDataAddr(); + } + + public long getBitAddr(){ + return bits.getDataAddr(); + } + + <#if type.major == "VarLen"> + public long getOffsetAddr(){ + return values.getOffsetAddr(); + } + </#if> public final class Accessor implements ValueVector.Accessor<#if type.major = "VarLen">, VariableWidthVector.VariableWidthAccessor</#if>{ final FieldReader reader = new Nullable${minor.class}ReaderImpl(Nullable${minor.class}Vector.this); + final UInt1Vector.Accessor bAccessor = bits.getAccessor(); + final ${valuesName}.Accessor vAccessor = values.getAccessor(); public FieldReader getReader(){ return reader; } + /** * Get the element at the specified position. * @@ -338,7 +356,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj */ public <#if type.major == "VarLen">byte[]<#else>${minor.javaType!type.javaType}</#if> get(int index) { assert !isNull(index) : "Tried to get null value"; - return values.getAccessor().get(index); + return vAccessor.get(index); } public boolean isNull(int index) { @@ -346,8 +364,21 @@ public final class ${className} extends BaseValueVector implements <#if type.maj } public int isSet(int index){ - return bits.getAccessor().get(index); + return bAccessor.get(index); + } + + <#if type.major == "VarLen"> + public long getStartEnd(int index){ + return vAccessor.getStartEnd(index); + } + + public long getOffsetAddr(){ + return values.getOffsetAddr(); } + </#if> + + + <#if type.major == "VarLen"> @@ -357,8 +388,8 @@ public final class ${className} extends BaseValueVector implements <#if type.maj </#if> public void get(int index, Nullable${minor.class}Holder holder){ - values.getAccessor().get(index, holder); - holder.isSet = bits.getAccessor().get(index); + vAccessor.get(index, holder); + holder.isSet = bAccessor.get(index); <#if minor.class.startsWith("Decimal")> holder.scale = getField().getScale(); @@ -371,7 +402,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj if (isNull(index)) { return null; }else{ - return values.getAccessor().getObject(index); + return vAccessor.getObject(index); } } @@ -380,7 +411,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj if (isNull(index)) { return null; }else{ - return values.getAccessor().getAsStringBuilder(index); + return vAccessor.getAsStringBuilder(index); } } </#if> @@ -467,6 +498,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj values.getMutator().set(index, holder); } + public void set(int index, Nullable${minor.class}Holder holder){ <#if type.major == "VarLen"> for (int i = lastSet + 1; i < index; i++) { @@ -493,14 +525,44 @@ public final class ${className} extends BaseValueVector implements <#if type.maj return outIndex < Nullable${minor.class}Vector.this.getValueCapacity(); } - //public boolean setSafe(int index, <#if type.major == "VarLen" || minor.class == "TimeStampTZ" || minor.class == "Interval" || minor.class == "IntervalDay">Nullable${minor.class}Holder <#elseif (type.width < 4)>int<#else>${minor.javaType!type.javaType}</#if> value){ + //public boolean setSafe(int index, int isSet<#if type.major == "VarLen" || minor.class == "TimeStampTZ" || minor.class == "Interval" || minor.class == "IntervalDay">Nullable${minor.class}Holder <#elseif (type.width < 4)>int<#else>${minor.javaType!type.javaType}</#if> value){ + + <#assign fields = minor.fields!type.fields /> + public void set(int index, int isSet<#list fields as field><#if field.include!true >, ${field.type} ${field.name}Field</#if></#list> ){ + <#if type.major == "VarLen"> + for (int i = lastSet + 1; i < index; i++) { + values.getMutator().set(i, new byte[]{}); + } + </#if> + bits.getMutator().set(index, isSet); + values.getMutator().set(index<#list fields as field><#if field.include!true >, ${field.name}Field</#if></#list>); + <#if type.major == "VarLen">lastSet = index;</#if> + } + + public boolean setSafe(int index, int isSet<#list fields as field><#if field.include!true >, ${field.type} ${field.name}Field</#if></#list> ) { + <#if type.major == "VarLen"> + if(!fillEmpties(index)) return false; + </#if> + + boolean b1 = bits.getMutator().setSafe(index, isSet); + boolean b2 = values.getMutator().setSafe(index<#list fields as field><#if field.include!true >, ${field.name}Field</#if></#list>); + if(b1 && b2){ + setCount++; + <#if type.major == "VarLen">lastSet = index;</#if> + return true; + }else{ + return false; + } + + } + public boolean setSafe(int index, Nullable${minor.class}Holder value) { <#if type.major == "VarLen"> if(!fillEmpties(index)) return false; </#if> - boolean b1 = bits.getMutator().setSafe(index, 1); + boolean b1 = bits.getMutator().setSafe(index, value.isSet); boolean b2 = values.getMutator().setSafe(index, value); if(b1 && b2){ setCount++; @@ -561,7 +623,7 @@ public final class ${className} extends BaseValueVector implements <#if type.maj } public void generateTestData(int valueCount){ - bits.getMutator().generateTestData(valueCount); + bits.getMutator().generateTestDataAlt(valueCount); values.getMutator().generateTestData(valueCount); <#if type.major = "VarLen">lastSet = valueCount;</#if> setValueCount(valueCount); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/NumericToCharFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/NumericToCharFunctions.java b/exec/java-exec/src/main/codegen/templates/NumericToCharFunctions.java index 6615e33..ff2c675 100644 --- a/exec/java-exec/src/main/codegen/templates/NumericToCharFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/NumericToCharFunctions.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,8 @@ import org.apache.drill.exec.expr.holders.*; import org.apache.drill.exec.record.RecordBatch; import io.netty.buffer.ByteBuf; +import io.netty.buffer.DrillBuf; + import java.text.NumberFormat; import java.text.DecimalFormat; @@ -47,12 +51,12 @@ public class G${type}ToChar implements DrillSimpleFunc { @Param ${type}Holder left; @Param VarCharHolder right; - @Workspace ByteBuf buffer; + @Inject DrillBuf buffer; @Workspace java.text.NumberFormat outputFormat; @Output VarCharHolder out; public void setup(RecordBatch b) { - buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[100]); + buffer = buffer.reallocIfNeeded(100); byte[] buf = new byte[right.end - right.start]; right.buffer.getBytes(right.start, buf, 0, right.end - right.start); String inputFormat = new String(buf); @@ -65,10 +69,10 @@ public class G${type}ToChar implements DrillSimpleFunc { java.math.BigDecimal bigDecimal = new java.math.BigDecimal(java.math.BigInteger.valueOf(left.value), left.scale); String str = outputFormat.format(bigDecimal); <#elseif type == "Decimal28Sparse" || type == "Decimal38Sparse"> - java.math.BigDecimal bigDecimal = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromByteBuf(left.buffer, left.start, left.nDecimalDigits, left.scale, true); + java.math.BigDecimal bigDecimal = org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDrillBuf(left.buffer, left.start, left.nDecimalDigits, left.scale, true); String str = outputFormat.format(bigDecimal); <#elseif type == "Decimal28Dense" || type == "Decimal38Dense"> - java.math.BigDecimal bigDecimal = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromDense(left.buffer, left.start, left.nDecimalDigits, left.scale, left.maxPrecision, left.WIDTH); + java.math.BigDecimal bigDecimal = org.apache.drill.exec.util.DecimalUtility.getBigDecimalFromDense(left.buffer, left.start, left.nDecimalDigits, left.scale, left.maxPrecision, left.WIDTH); String str = outputFormat.format(bigDecimal); <#else> String str = outputFormat.format(left.value); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/ParquetOutputRecordWriter.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/ParquetOutputRecordWriter.java b/exec/java-exec/src/main/codegen/templates/ParquetOutputRecordWriter.java index aa25d1a..d4b5af5 100644 --- a/exec/java-exec/src/main/codegen/templates/ParquetOutputRecordWriter.java +++ b/exec/java-exec/src/main/codegen/templates/ParquetOutputRecordWriter.java @@ -36,7 +36,7 @@ import org.apache.drill.exec.record.BatchSchema; import org.apache.drill.exec.store.EventBasedRecordWriter.FieldConverter; import org.apache.drill.exec.store.parquet.ParquetTypeHelper; import org.apache.drill.exec.vector.*; -import org.apache.drill.common.util.DecimalUtility; +import org.apache.drill.exec.util.DecimalUtility; import org.apache.drill.exec.vector.complex.reader.FieldReader; import parquet.io.api.RecordConsumer; import parquet.schema.MessageType; @@ -191,7 +191,7 @@ public abstract class ParquetOutputRecordWriter extends AbstractRecordWriter imp byte[] bytes = DecimalUtility.getBigDecimalFromSparse( holder.buffer, holder.start, ${minor.class}Holder.nDecimalDigits, holder.scale).unscaledValue().toByteArray(); byte[] output = new byte[ParquetTypeHelper.getLengthForMinorType(MinorType.${minor.class?upper_case})]; - if (holder.getSign()) { + if (holder.getSign(holder.start, holder.buffer)) { Arrays.fill(output, 0, output.length - bytes.length, (byte)0xFF); } else { Arrays.fill(output, 0, output.length - bytes.length, (byte)0x0); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java index 107a667..97117a4 100644 --- a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java +++ b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java @@ -78,7 +78,7 @@ package org.apache.drill.exec.vector; return offsets.getBufferSize() + values.getBufferSize(); } - public ByteBuf getData(){ + public DrillBuf getData(){ return values.getData(); } @@ -199,7 +199,7 @@ package org.apache.drill.exec.vector; } @Override - public int load(int dataBytes, int parentValueCount, int childValueCount, ByteBuf buf){ + public int load(int dataBytes, int parentValueCount, int childValueCount, DrillBuf buf){ clear(); this.parentValueCount = parentValueCount; this.childValueCount = childValueCount; @@ -210,10 +210,10 @@ package org.apache.drill.exec.vector; } @Override - public void load(SerializedField metadata, ByteBuf buffer) { - assert this.field.matches(metadata); + public void load(SerializedField metadata, DrillBuf buffer) { + assert this.field.matches(metadata) : String.format("The field %s doesn't match the provided metadata %s.", this.field, metadata); int loaded = load(metadata.getVarByteLength(), metadata.getGroupCount(), metadata.getValueCount(), buffer); - assert metadata.getBufferLength() == loaded; + assert metadata.getBufferLength() == loaded : String.format("Expected to load %d bytes but actually loaded %d bytes", metadata.getBufferLength(), loaded); } public int getByteCapacity(){ @@ -240,7 +240,7 @@ package org.apache.drill.exec.vector; accessor.reset(); } - public int load(int parentValueCount, int childValueCount, ByteBuf buf){ + public int load(int parentValueCount, int childValueCount, DrillBuf buf){ clear(); this.parentValueCount = parentValueCount; this.childValueCount = childValueCount; @@ -251,7 +251,7 @@ package org.apache.drill.exec.vector; } @Override - public void load(SerializedField metadata, ByteBuf buffer) { + public void load(SerializedField metadata, DrillBuf buffer) { assert this.field.matches(metadata); int loaded = load(metadata.getGroupCount(), metadata.getValueCount(), buffer); assert metadata.getBufferLength() == loaded; @@ -259,8 +259,8 @@ package org.apache.drill.exec.vector; </#if> @Override - public ByteBuf[] getBuffers() { - ByteBuf[] buffers = ObjectArrays.concat(offsets.getBuffers(), values.getBuffers(), ByteBuf.class); + public DrillBuf[] getBuffers() { + DrillBuf[] buffers = ObjectArrays.concat(offsets.getBuffers(), values.getBuffers(), DrillBuf.class); clear(); return buffers; } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/SqlAccessors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java index 701c8b8..b569185 100644 --- a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java +++ b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java @@ -69,7 +69,7 @@ public class ${name}Accessor extends AbstractSqlAccessor{ <#case "VarBinary"> public String getString(int index) { byte [] b = ac.get(index); - return DrillStringUtils.toBinaryString(io.netty.buffer.Unpooled.wrappedBuffer(b), 0, b.length); + return DrillStringUtils.toBinaryString(b); } <#break> <#case "VarChar"> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/ValueHolders.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/ValueHolders.java b/exec/java-exec/src/main/codegen/templates/ValueHolders.java index 46cf9e0..1902843 100644 --- a/exec/java-exec/src/main/codegen/templates/ValueHolders.java +++ b/exec/java-exec/src/main/codegen/templates/ValueHolders.java @@ -35,134 +35,76 @@ public final class ${className} implements ValueHolder{ public MajorType getType() {return TYPE;} - <#if mode.name != "Repeated"> - + <#if mode.name == "Repeated"> + + /** The first index (inclusive) into the Vector. **/ + public int start; + + /** The last index (exclusive) into the Vector. **/ + public int end; + + /** The Vector holding the actual values. **/ + public ${minor.class}Vector vector; + + <#else> public static final int WIDTH = ${type.width}; - <#if mode.name == "Optional"> - /** Whether the given holder holds a valid value. 1 means non-null. 0 means null. **/ - public int isSet; - - public boolean isSet() { - return isSet == 1; - } - <#else> - public boolean isSet() { - return true; - } - - </#if> - - - - <#if type.major != "VarLen"> - - <#if (minor.class == "TimeStampTZ")> - public long value; - public int index; - <#elseif (minor.class == "Interval")> - public int months; - public int days; - public int milliSeconds; - <#elseif (minor.class == "IntervalDay")> - public int days; - public int milliSeconds; - <#elseif minor.class.startsWith("Decimal")> - public int scale; - public int precision; + <#if mode.name == "Optional">public int isSet;</#if> + <#assign fields = minor.fields!type.fields /> + <#list fields as field> + public ${field.type} ${field.name}; + </#list> + + <#if minor.class.startsWith("Decimal")> public static final int maxPrecision = ${minor.maxPrecisionDigits}; <#if minor.class.startsWith("Decimal28") || minor.class.startsWith("Decimal38")> - public int start; - public ByteBuf buffer; public static final int nDecimalDigits = ${minor.nDecimalDigits}; - - - public int getInteger(int index) { - int value = buffer.getInt(start + (index * 4)); - - if (index == 0) { - /* the first byte contains sign bit, return value without it */ - <#if minor.class.endsWith("Sparse")> - value = (value & 0x7FFFFFFF); - <#elseif minor.class.endsWith("Dense")> - value = (value & 0x0000007F); - </#if> - } - return value; + + public static int getInteger(int index, int start, DrillBuf buffer) { + int value = buffer.getInt(start + (index * 4)); + + if (index == 0) { + /* the first byte contains sign bit, return value without it */ + <#if minor.class.endsWith("Sparse")> + value = (value & 0x7FFFFFFF); + <#elseif minor.class.endsWith("Dense")> + value = (value & 0x0000007F); + </#if> + } + return value; } - public void setInteger(int index, int value) { + public static void setInteger(int index, int value, int start, DrillBuf buffer) { buffer.setInt(start + (index * 4), value); } - - public void setSign(boolean sign) { + + public static void setSign(boolean sign, int start, DrillBuf buffer) { // Set MSB to 1 if sign is negative if (sign == true) { - int value = getInteger(0); - setInteger(0, (value | 0x80000000)); + int value = getInteger(0, start, buffer); + setInteger(0, (value | 0x80000000), start, buffer); } } - - public boolean getSign() { + + public static boolean getSign(int start, DrillBuf buffer) { return ((buffer.getInt(start) & 0x80000000) != 0); } - - <#else> - public ${minor.javaType!type.javaType} value; - </#if> - - <#elseif (type.width > 8)> - public int start; - public ByteBuf buffer; - <#else> - public ${minor.javaType!type.javaType} value; - </#if> - <#else> - /** The first offset (inclusive) into the buffer. **/ - public int start; - - /** The last offset (exclusive) into the buffer. **/ - public int end; - - /** The buffer holding actual values. **/ - public ByteBuf buffer; - - public String toString() { - <#if mode.name == "Optional"> - if (isSet == 0) - return "<NULL>"; - </#if> - byte[] buf = new byte[end-start]; - buffer.getBytes(start, buf, 0, end-start); - - <#switch minor.class> - <#case "Var16Char"> - return new String(buf, com.google.common.base.Charsets.UTF_16); - <#break> - <#case "VarChar"> - <#default> - return new String(buf, com.google.common.base.Charsets.UTF_8); - </#switch> - } - - </#if> - - <#else> + </#if></#if> - /** The first index (inclusive) into the Vector. **/ - public int start; - - /** The last index (exclusive) into the Vector. **/ - public int end; - - /** The Vector holding the actual values. **/ - public ${minor.class}Vector vector; - - public boolean isSet() { - return true; - } - + @Deprecated + public int hashCode(){ + throw new UnsupportedOperationException(); + } + + @Deprecated + public String toString(){ + throw new UnsupportedOperationException(); + } </#if> + + + + } </#list> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java b/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java index 746d25b..4b9c43b 100644 --- a/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java +++ b/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java @@ -33,14 +33,19 @@ package org.apache.drill.exec.expr.fn.impl.gaggr; +<#include "/@includes/vv_imports.ftl" /> + import org.apache.drill.exec.expr.DrillAggFunc; import org.apache.drill.exec.expr.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope; import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.annotations.Workspace; +import org.apache.drill.exec.expr.fn.impl.ByteFunctionHelpers; import org.apache.drill.exec.expr.holders.*; +import javax.inject.Inject; import org.apache.drill.exec.record.RecordBatch; + import io.netty.buffer.ByteBuf; @SuppressWarnings("unused") @@ -57,6 +62,8 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu @Param ${type.inputType}Holder in; <#if aggrtype.funcName == "max" || aggrtype.funcName == "min"> @Workspace ObjectHolder value; + @Workspace UInt1Holder init; + @Inject DrillBuf buf; <#else> @Workspace ${type.runningType}Holder value; </#if> @@ -64,6 +71,8 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu public void setup(RecordBatch b) { <#if aggrtype.funcName == "max" || aggrtype.funcName == "min"> + init = new UInt1Holder(); + init.value = 0; value = new ObjectHolder(); ${type.runningType}Holder tmp = new ${type.runningType}Holder(); tmp.start = 0; @@ -81,10 +90,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu public void add() { <#if type.inputType?starts_with("Nullable")> sout: { - if (in.isSet == 0) { - // processing nullable input and the value is null, so don't do anything... - break sout; - } + if (in.isSet == 0) { + // processing nullable input and the value is null, so don't do anything... + break sout; + } </#if> <#if aggrtype.funcName == "max" || aggrtype.funcName == "min"> ${type.runningType}Holder tmp = (${type.runningType}Holder)value.obj; @@ -92,27 +101,12 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu boolean swap = false; // if buffer is null then swap - if (tmp.buffer == null) { + if (init.value == 0) { + init.value = 1; swap = true; } else { // Compare the bytes - for (int l = in.start, r = tmp.start; l < in.end && r < tmp.end; l++, r++) { - byte leftByte = in.buffer.getByte(l); - byte rightByte = tmp.buffer.getByte(r); - if (leftByte != rightByte) { - cmp = ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1; - break; - } - } - - if (cmp == 0) { - int l = (in.end - in.start) - (tmp.end - tmp.start); - if (l > 0) { - cmp = 1; - } else { - cmp = -1; - } - } + int compare = org.apache.drill.exec.expr.fn.impl.ByteFunctionHelpers.compare(in.buffer.memoryAddress(), in.start, in.end, tmp.buffer.memoryAddress(), tmp.start, tmp.end); <#if aggrtype.className == "Min"> swap = (cmp == -1); @@ -122,15 +116,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu } if (swap) { int length = in.end - in.start; - if (length > (tmp.end - tmp.start)) { - // if workspace buffer is smaller, release and allocate a new one - if (tmp.buffer != null) { - tmp.buffer.release(); - } - tmp.buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte [length]); - } + this.buf = tmp.buffer = buf.reallocIfNeeded(in.end - in.start); in.buffer.getBytes(in.start, tmp.buffer, 0, length); tmp.end = length; + } <#else> value.value++; @@ -156,14 +145,7 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu public void reset() { <#if aggrtype.funcName == "max" || aggrtype.funcName == "min"> value = new ObjectHolder(); - ${type.runningType}Holder tmp = new ${type.runningType}Holder(); - tmp.start = 0; - tmp.end = 0; - if (tmp.buffer != null) { - tmp.buffer.release(); - tmp.buffer = null; - } - value.obj = tmp; + init.value = 0; <#else> value = new ${type.runningType}Holder(); value.value = 0; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java b/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java index 0b49f85..95cd3cc 100644 --- a/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java +++ b/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java @@ -40,7 +40,7 @@ package org.apache.drill.exec.vector; * ${minor.class}Vector implements a vector of variable width values. Elements in the vector * are accessed by position from the logical start of the vector. A fixed width offsetVector * is used to convert an element's position to it's offset from the start of the (0-based) - * ByteBuf. Size is inferred by adjacent elements. + * DrillBuf. Size is inferred by adjacent elements. * The width of each element is ${type.width} byte(s) * The equivalent Java primitive is '${minor.javaType!type.javaType}' * @@ -51,8 +51,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(${minor.class}Vector.class); private final UInt${type.width}Vector offsetVector; - private final Accessor accessor = new Accessor(); - private final Mutator mutator = new Mutator(); + private final Accessor accessor; + private final Mutator mutator; + + private final UInt${type.width}Vector.Accessor oAccessor; + private int allocationTotalByteCount = 32768; private int allocationMonitor = 0; @@ -60,6 +63,9 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V public ${minor.class}Vector(MaterializedField field, BufferAllocator allocator) { super(field, allocator); this.offsetVector = new UInt${type.width}Vector(null, allocator); + this.oAccessor = offsetVector.getAccessor(); + this.accessor = new Accessor(); + this.mutator = new Mutator(); } public int getBufferSize(){ @@ -101,7 +107,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V .build(); } - public int load(int dataBytes, int valueCount, ByteBuf buf){ + public int load(int dataBytes, int valueCount, DrillBuf buf){ this.valueCount = valueCount; if(valueCount == 0){ allocateNew(0,0); @@ -114,10 +120,10 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V } @Override - public void load(SerializedField metadata, ByteBuf buffer) { - assert this.field.matches(metadata); + public void load(SerializedField metadata, DrillBuf buffer) { + assert this.field.matches(metadata) : String.format("The field %s doesn't match the provided metadata %s.", this.field, metadata); int loaded = load(metadata.getBufferLength(), metadata.getValueCount(), buffer); - assert metadata.getBufferLength() == loaded; + assert metadata.getBufferLength() == loaded : String.format("Expected to load %d bytes but actually loaded %d bytes", metadata.getBufferLength(), loaded); } @Override @@ -128,12 +134,16 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V @Override - public ByteBuf[] getBuffers() { - ByteBuf[] buffers = ObjectArrays.concat(offsetVector.getBuffers(), super.getBuffers(), ByteBuf.class); + public DrillBuf[] getBuffers() { + DrillBuf[] buffers = ObjectArrays.concat(offsetVector.getBuffers(), super.getBuffers(), DrillBuf.class); clear(); return buffers; } + public long getOffsetAddr(){ + return offsetVector.getDataAddr(); + } + public TransferPair getTransferPair(){ return new TransferImpl(getField()); } @@ -290,15 +300,19 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V public final class Accessor extends BaseValueVector.BaseAccessor implements VariableWidthAccessor { final FieldReader reader = new ${minor.class}ReaderImpl(${minor.class}Vector.this); - + final UInt${type.width}Vector.Accessor oAccessor = offsetVector.getAccessor(); public FieldReader getReader(){ return reader; } + public long getStartEnd(int index){ + return oAccessor.getTwoAsLong(index); + } + public byte[] get(int index) { assert index >= 0; - int startIdx = offsetVector.getAccessor().get(index); - int length = offsetVector.getAccessor().get(index + 1) - startIdx; + int startIdx = oAccessor.get(index); + int length = oAccessor.get(index + 1) - startIdx; assert length >= 0; byte[] dst = new byte[length]; data.getBytes(startIdx, dst, 0, length); @@ -310,15 +324,15 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V } public void get(int index, ${minor.class}Holder holder){ - holder.start = offsetVector.getAccessor().get(index); - holder.end = offsetVector.getAccessor().get(index + 1); + holder.start = oAccessor.get(index); + holder.end = oAccessor.get(index + 1); holder.buffer = data; } public void get(int index, Nullable${minor.class}Holder holder){ holder.isSet = 1; - holder.start = offsetVector.getAccessor().get(index); - holder.end = offsetVector.getAccessor().get(index + 1); + holder.start = oAccessor.get(index); + holder.end = oAccessor.get(index + 1); holder.buffer = data; } @@ -362,7 +376,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V * Mutable${minor.class} implements a vector of variable width values. Elements in the vector * are accessed by position from the logical start of the vector. A fixed width offsetVector * is used to convert an element's position to it's offset from the start of the (0-based) - * ByteBuf. Size is inferred by adjacent elements. + * DrillBuf. Size is inferred by adjacent elements. * The width of each element is ${type.width} byte(s) * The equivalent Java primitive is '${minor.javaType!type.javaType}' * @@ -434,6 +448,26 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V return offsetVector.getMutator().setSafe(index + 1, offsetVector.getAccessor().get(index) + length); } + + public boolean setSafe(int index, int start, int end, DrillBuf buffer){ + int len = end - start; + + int outputStart = offsetVector.data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width}); + + if(data.capacity() < outputStart + len) { + decrementAllocationMonitor(); + return false; + } + + if (!offsetVector.getMutator().setSafe( index+1, outputStart + len)) { + return false; + } + buffer.getBytes(start, data, outputStart, len); + + return true; + } + + public boolean setSafe(int index, Nullable${minor.class}Holder holder){ assert holder.isSet == 1; @@ -481,11 +515,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V return true; } - protected void set(int index, int start, int length, ByteBuf buffer){ + protected void set(int index, int start, int length, DrillBuf buffer){ assert index >= 0; int currentOffset = offsetVector.getAccessor().get(index); offsetVector.getMutator().set(index + 1, currentOffset + length); - ByteBuf bb = buffer.slice(start, length); + DrillBuf bb = buffer.slice(start, length); data.setBytes(currentOffset, bb); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5c5cef06/exec/java-exec/src/main/java/io/netty/buffer/AccountingByteBuf.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/io/netty/buffer/AccountingByteBuf.java b/exec/java-exec/src/main/java/io/netty/buffer/AccountingByteBuf.java deleted file mode 100644 index e5b0f94..0000000 --- a/exec/java-exec/src/main/java/io/netty/buffer/AccountingByteBuf.java +++ /dev/null @@ -1,866 +0,0 @@ -/** - * 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 io.netty.buffer; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.channels.GatheringByteChannel; -import java.nio.channels.ScatteringByteChannel; -import java.nio.charset.Charset; - -import org.apache.drill.exec.memory.Accountor; - -public class AccountingByteBuf extends ByteBuf{ - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AccountingByteBuf.class); - - private final UnsafeDirectLittleEndian b; - private volatile Accountor acct; - private volatile int size; - - public AccountingByteBuf(Accountor a, ByteBuf b) { - super(); - this.b = (UnsafeDirectLittleEndian) b; - this.acct = a; - this.size = b.capacity(); - } - - @Override - public int refCnt() { - return b.refCnt(); - } - - public boolean transferAccounting(Accountor target){ - boolean outcome = acct.transferTo(target, this, size); - acct = target; - return outcome; - } - - @Override - public synchronized boolean release() { - if(b.release()){ - acct.release(this, size); - return true; - } - return false; - } - - @Override - public synchronized boolean release(int decrement) { - if(b.release(decrement)){ - acct.release(this, size); - return true; - } - return false; - } - - @Override - public int capacity() { - return b.capacity(); - } - - @Override - public synchronized ByteBuf capacity(int newCapacity) { - if(newCapacity == size){ - return this; - }else if(newCapacity < size){ - b.capacity(newCapacity); - int diff = size - b.capacity(); - acct.releasePartial(this, diff); - this.size = size - diff; - return this; - }else{ - throw new UnsupportedOperationException("Accounting byte buf doesn't support increasing allocations."); - } - - } - - @Override - public int maxCapacity() { - return size; - } - - @Override - public ByteBufAllocator alloc() { - return b.alloc(); - } - - @Override - public ByteOrder order() { - return ByteOrder.LITTLE_ENDIAN; - } - - @Override - public ByteBuf order(ByteOrder endianness) { -// if(endianness != ByteOrder.LITTLE_ENDIAN) throw new UnsupportedOperationException("Drill buffers only support little endian."); - return this; - } - - @Override - public ByteBuf unwrap() { - return this; - } - - @Override - public boolean isDirect() { - return true; - } - - @Override - public int readerIndex() { - return b.readerIndex(); - } - - @Override - public ByteBuf readerIndex(int readerIndex) { - b.readerIndex(readerIndex); - return this; - } - - @Override - public int writerIndex() { - return b.writerIndex(); - } - - @Override - public ByteBuf writerIndex(int writerIndex) { - b.writerIndex(writerIndex); - return this; - } - - @Override - public ByteBuf setIndex(int readerIndex, int writerIndex) { - b.setIndex(readerIndex, writerIndex); - return this; - } - - @Override - public int readableBytes() { - return b.readableBytes(); - } - - @Override - public int writableBytes() { - return b.writableBytes(); - } - - @Override - public int maxWritableBytes() { - return b.maxWritableBytes(); - } - - @Override - public boolean isReadable() { - return b.isReadable(); - } - - @Override - public boolean isReadable(int size) { - return b.isReadable(size); - } - - @Override - public boolean isWritable() { - return b.isWritable(); - } - - @Override - public boolean isWritable(int size) { - return b.isWritable(size); - } - - @Override - public ByteBuf clear() { - b.clear(); - return this; - } - - @Override - public ByteBuf markReaderIndex() { - b.markReaderIndex(); - return this; - } - - @Override - public ByteBuf resetReaderIndex() { - b.resetReaderIndex(); - return this; - } - - @Override - public ByteBuf markWriterIndex() { - b.markWriterIndex(); - return this; - } - - @Override - public ByteBuf resetWriterIndex() { - b.resetWriterIndex(); - return this; - } - - @Override - public ByteBuf discardReadBytes() { - b.discardReadBytes(); - return this; - } - - @Override - public ByteBuf discardSomeReadBytes() { - b.discardSomeReadBytes(); - return this; - } - - @Override - public ByteBuf ensureWritable(int minWritableBytes) { - b.ensureWritable(minWritableBytes); - return this; - } - - @Override - public int ensureWritable(int minWritableBytes, boolean force) { - return b.ensureWritable(minWritableBytes, false); - } - - @Override - public boolean getBoolean(int index) { - return b.getBoolean(index); - } - - @Override - public byte getByte(int index) { - return b.getByte(index); - } - - @Override - public short getUnsignedByte(int index) { - return b.getUnsignedByte(index); - } - - @Override - public short getShort(int index) { - return b.getShort(index); - } - - @Override - public int getUnsignedShort(int index) { - return b.getUnsignedShort(index); - } - - @Override - public int getMedium(int index) { - return b.getMedium(index); - } - - @Override - public int getUnsignedMedium(int index) { - return b.getUnsignedMedium(index); - } - - @Override - public int getInt(int index) { - return b.getInt(index); - } - - @Override - public long getUnsignedInt(int index) { - return b.getUnsignedInt(index); - } - - @Override - public long getLong(int index) { - return b.getLong(index); - } - - @Override - public char getChar(int index) { - return b.getChar(index); - } - - @Override - public float getFloat(int index) { - return b.getFloat(index); - } - - @Override - public double getDouble(int index) { - return b.getDouble(index); - } - - @Override - public ByteBuf getBytes(int index, ByteBuf dst) { - b.getBytes(index, dst); - return this; - } - - @Override - public ByteBuf getBytes(int index, ByteBuf dst, int length) { - b.getBytes(index, dst, length); - return this; - } - - @Override - public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { - b.getBytes(index, dst, dstIndex, length); - return this; - } - - @Override - public ByteBuf getBytes(int index, byte[] dst) { - b.getBytes(index, dst); - return this; - } - - @Override - public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) { - b.getBytes(index, dst, dstIndex, length); - return this; - } - - @Override - public ByteBuf getBytes(int index, ByteBuffer dst) { - b.getBytes(index, dst); - return this; - } - - @Override - public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { - b.getBytes(index, out, length); - return this; - } - - @Override - public int getBytes(int index, GatheringByteChannel out, int length) throws IOException { - return b.getBytes(index, out, length); - } - - @Override - public ByteBuf setBoolean(int index, boolean value) { - b.setBoolean(index, value); - return this; - } - - @Override - public ByteBuf setByte(int index, int value) { - b.setByte(index, value); - return this; - } - - @Override - public ByteBuf setShort(int index, int value) { - b.setShort(index, value); - return this; - } - - @Override - public ByteBuf setMedium(int index, int value) { - b.setMedium(index, value); - return this; - } - - @Override - public ByteBuf setInt(int index, int value) { - b.setInt(index, value); - return this; - } - - @Override - public ByteBuf setLong(int index, long value) { - b.setLong(index, value); - return this; - } - - @Override - public ByteBuf setChar(int index, int value) { - b.setChar(index, value); - return this; - } - - @Override - public ByteBuf setFloat(int index, float value) { - b.setFloat(index, value); - return this; - } - - @Override - public ByteBuf setDouble(int index, double value) { - b.setDouble(index, value); - return this; - } - - @Override - public ByteBuf setBytes(int index, ByteBuf src) { - b.setBytes(index, src); - return this; - } - - @Override - public ByteBuf setBytes(int index, ByteBuf src, int length) { - b.setBytes(index, src, length); - return this; - } - - @Override - public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) { - b.setBytes(index, src, srcIndex, length); - return this; - } - - @Override - public ByteBuf setBytes(int index, byte[] src) { - b.setBytes(index, src); - return this; - } - - @Override - public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) { - b.setBytes(index, src, srcIndex, length); - return this; - } - - @Override - public ByteBuf setBytes(int index, ByteBuffer src) { - b.setBytes(index, src); - return this; - } - - @Override - public int setBytes(int index, InputStream in, int length) throws IOException { - return b.setBytes(index, in, length); - } - - @Override - public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { - return b.setBytes(index, in, length); - } - - @Override - public ByteBuf setZero(int index, int length) { - b.setZero(index, length); - return this; - } - - @Override - public boolean readBoolean() { - return b.readBoolean(); - } - - @Override - public byte readByte() { - return b.readByte(); - } - - @Override - public short readUnsignedByte() { - return b.readUnsignedByte(); - } - - @Override - public short readShort() { - return b.readShort(); - } - - @Override - public int readUnsignedShort() { - return b.readUnsignedShort(); - } - - @Override - public int readMedium() { - return b.readMedium(); - } - - @Override - public int readUnsignedMedium() { - return b.readUnsignedMedium(); - } - - @Override - public int readInt() { - return b.readInt(); - } - - @Override - public long readUnsignedInt() { - return b.readUnsignedInt(); - } - - @Override - public long readLong() { - return b.readLong(); - } - - @Override - public char readChar() { - return b.readChar(); - } - - @Override - public float readFloat() { - return b.readFloat(); - } - - @Override - public double readDouble() { - return b.readDouble(); - } - - @Override - public ByteBuf readBytes(int length) { - throw new UnsupportedOperationException(); - } - - @Override - public ByteBuf readSlice(int length) { - ByteBuf slice = slice(readerIndex(), length); - readerIndex(readerIndex() + length); - return slice; - } - - - @Override - public ByteBuf readBytes(ByteBuf dst) { - b.readBytes(dst); - return this; - } - - @Override - public ByteBuf readBytes(ByteBuf dst, int length) { - b.readBytes(dst, length); - return this; - } - - @Override - public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length) { - b.readBytes(dst, dstIndex, length); - return this; - } - - @Override - public ByteBuf readBytes(byte[] dst) { - b.readBytes(dst); - return this; - } - - @Override - public ByteBuf readBytes(byte[] dst, int dstIndex, int length) { - b.readBytes(dst, dstIndex, length); - return this; - } - - @Override - public ByteBuf readBytes(ByteBuffer dst) { - b.readBytes(dst); - return this; - } - - @Override - public ByteBuf readBytes(OutputStream out, int length) throws IOException { - b.readBytes(out, length); - return null; - } - - @Override - public int readBytes(GatheringByteChannel out, int length) throws IOException { - return b.readBytes(out, length); - } - - @Override - public ByteBuf skipBytes(int length) { - b.skipBytes(length); - return this; - } - - @Override - public ByteBuf writeBoolean(boolean value) { - b.writeBoolean(value); - return this; - } - - @Override - public ByteBuf writeByte(int value) { - b.writeByte(value); - return this; - } - - @Override - public ByteBuf writeShort(int value) { - b.writeShort(value); - return this; - } - - @Override - public ByteBuf writeMedium(int value) { - b.writeMedium(value); - return this; - } - - @Override - public ByteBuf writeInt(int value) { - b.writeInt(value); - return this; - } - - @Override - public ByteBuf writeLong(long value) { - b.writeLong(value); - return this; - } - - @Override - public ByteBuf writeChar(int value) { - b.writeChar(value); - return this; - } - - @Override - public ByteBuf writeFloat(float value) { - b.writeFloat(value); - return this; - } - - @Override - public ByteBuf writeDouble(double value) { - b.writeDouble(value); - return this; - } - - @Override - public ByteBuf writeBytes(ByteBuf src) { - b.writeBytes(src); - return this; - } - - @Override - public ByteBuf writeBytes(ByteBuf src, int length) { - b.writeBytes(src, length); - return this; - } - - @Override - public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) { - b.writeBytes(src, srcIndex, length); - return this; - } - - @Override - public ByteBuf writeBytes(byte[] src) { - b.writeBytes(src); - return this; - } - - @Override - public ByteBuf writeBytes(byte[] src, int srcIndex, int length) { - b.writeBytes(src, srcIndex, length); - return this; - } - - @Override - public ByteBuf writeBytes(ByteBuffer src) { - b.writeBytes(src); - return this; - } - - @Override - public int writeBytes(InputStream in, int length) throws IOException { - return b.writeBytes(in, length); - } - - @Override - public int writeBytes(ScatteringByteChannel in, int length) throws IOException { - return b.writeBytes(in, length); - } - - @Override - public ByteBuf writeZero(int length) { - b.writeZero(length); - return this; - } - - @Override - public int indexOf(int fromIndex, int toIndex, byte value) { - return b.indexOf(fromIndex, toIndex, value); - } - - @Override - public int bytesBefore(byte value) { - return b.bytesBefore(value); - } - - @Override - public int bytesBefore(int length, byte value) { - return b.bytesBefore(length, value); - } - - @Override - public int bytesBefore(int index, int length, byte value) { - return b.bytesBefore(index, length, value); - } - - @Override - public int forEachByte(ByteBufProcessor processor) { - return b.forEachByte(processor); - } - - @Override - public int forEachByte(int index, int length, ByteBufProcessor processor) { - return b.forEachByte(index, length, processor); - } - - @Override - public int forEachByteDesc(ByteBufProcessor processor) { - return b.forEachByteDesc(processor); - } - - @Override - public int forEachByteDesc(int index, int length, ByteBufProcessor processor) { - return b.forEachByteDesc(index, length, processor); - } - - @Override - public ByteBuf copy() { - throw new UnsupportedOperationException(); - } - - @Override - public ByteBuf copy(int index, int length) { - throw new UnsupportedOperationException(); - } - - @Override - public ByteBuf slice() { - return slice(b.readerIndex(), readableBytes()); - } - - @Override - public ByteBuf slice(int index, int length) { -// if (length == 0) { -// return Unpooled.EMPTY_BUFFER; -// } - - return new SlicedByteBuf(this, index, length); - } - - @Override - public ByteBuf duplicate() { - return new DuplicatedByteBuf(this); - } - - @Override - public int nioBufferCount() { - return b.nioBufferCount(); - } - - @Override - public ByteBuffer nioBuffer() { - return b.nioBuffer(); - } - - @Override - public ByteBuffer nioBuffer(int index, int length) { - return b.nioBuffer(index, length); - } - - @Override - public ByteBuffer internalNioBuffer(int index, int length) { - return b.internalNioBuffer(index, length); - } - - @Override - public ByteBuffer[] nioBuffers() { - return b.nioBuffers(); - } - - @Override - public ByteBuffer[] nioBuffers(int index, int length) { - return b.nioBuffers(index, length); - } - - @Override - public boolean hasArray() { - return b.hasArray(); - } - - @Override - public byte[] array() { - return b.array(); - } - - @Override - public int arrayOffset() { - return b.arrayOffset(); - } - - @Override - public boolean hasMemoryAddress() { - return b.hasMemoryAddress(); - } - - @Override - public long memoryAddress() { - return b.memoryAddress(); - } - - @Override - public String toString(Charset charset) { - return b.toString(charset); - } - - @Override - public String toString(int index, int length, Charset charset) { - return b.toString(index, length, charset); - } - - @Override - public int hashCode() { - return System.identityHashCode(this); - } - - @Override - public boolean equals(Object obj) { - // identity equals only. - return this == obj; - } - - @Override - public String toString() { - return "AccountingByteBuf [Inner buffer=" + b + ", size=" + size + "]"; - } - - @Override - public int compareTo(ByteBuf buffer) { - return b.compareTo(buffer); - } - - - @Override - public ByteBuf retain(int increment) { - b.retain(increment); - return this; - } - - @Override - public ByteBuf retain() { - b.retain(); - return this; - } - - -}
