@@ -725,44 +725,72 @@ public ValueVector visit(RunEndEncodedVector deltaVector, Void value) {
725725 // Then append the run-ends vector.
726726 BaseIntVector targetRunEndsVector = (BaseIntVector ) targetEncodedVector .getRunEndsVector ();
727727 BaseIntVector deltaRunEndsVector = (BaseIntVector ) deltaVector .getRunEndsVector ();
728+ appendRunEndsVector (targetRunEndsVector , deltaRunEndsVector , targetLogicalValueCount );
728729
729- // Shift the delta run-ends vector in-place before appending.
730- shiftRunEndsVector (
731- deltaRunEndsVector ,
730+ targetEncodedVector .setValueCount (targetLogicalValueCount + deltaVector .getValueCount ());
731+ return targetVector ;
732+ }
733+
734+ private void appendRunEndsVector (
735+ BaseIntVector targetRunEndsVector ,
736+ BaseIntVector deltaRunEndsVector ,
737+ int targetLogicalValueCount ) {
738+ int targetPhysicalValueCount = targetRunEndsVector .getValueCount ();
739+ int newPhysicalValueCount = targetPhysicalValueCount + deltaRunEndsVector .getValueCount ();
740+
741+ // make sure there is enough capacity
742+ while (targetVector .getValueCapacity () < newPhysicalValueCount ) {
743+ targetVector .reAlloc ();
744+ }
745+
746+ // append validity buffer
747+ BitVectorHelper .concatBits (
748+ targetRunEndsVector .getValidityBuffer (),
749+ targetRunEndsVector .getValueCount (),
750+ deltaRunEndsVector .getValidityBuffer (),
751+ deltaRunEndsVector .getValueCount (),
752+ targetRunEndsVector .getValidityBuffer ());
753+
754+ // shift and append data buffer
755+ shiftAndAppendRunEndsDataBuffer (
756+ targetRunEndsVector ,
757+ targetPhysicalValueCount ,
732758 deltaRunEndsVector .getDataBuffer (),
733759 targetLogicalValueCount ,
734760 deltaRunEndsVector .getValueCount ());
735761
736- // Append the now-shifted delta run-ends vector to the target.
737- new VectorAppender (targetRunEndsVector ).visit ((BaseFixedWidthVector ) deltaRunEndsVector , null );
738-
739- targetEncodedVector .setValueCount (targetLogicalValueCount + deltaVector .getValueCount ());
740-
741- return targetVector ;
762+ targetRunEndsVector .setValueCount (newPhysicalValueCount );
742763 }
743764
744- private void shiftRunEndsVector (
745- ValueVector toRunEndVector , ArrowBuf fromRunEndBuffer , int offset , int physicalLength ) {
765+ private void shiftAndAppendRunEndsDataBuffer (
766+ BaseIntVector toRunEndVector ,
767+ int toIndex ,
768+ ArrowBuf fromRunEndBuffer ,
769+ int offset ,
770+ int physicalLength ) {
746771 ArrowBuf toRunEndBuffer = toRunEndVector .getDataBuffer ();
747772 if (toRunEndVector instanceof SmallIntVector ) {
748773 byte typeWidth = SmallIntVector .TYPE_WIDTH ;
749774 for (int i = 0 ; i < physicalLength ; i ++) {
750775 toRunEndBuffer .setShort (
751- (long ) i * typeWidth , fromRunEndBuffer .getShort ((long ) (i ) * typeWidth ) + offset );
776+ (long ) (i + toIndex ) * typeWidth ,
777+ fromRunEndBuffer .getShort ((long ) (i ) * typeWidth ) + offset );
752778 }
753779
754780 } else if (toRunEndVector instanceof IntVector ) {
755781 byte typeWidth = IntVector .TYPE_WIDTH ;
756782 for (int i = 0 ; i < physicalLength ; i ++) {
757783 toRunEndBuffer .setInt (
758- (long ) i * typeWidth , fromRunEndBuffer .getInt ((long ) (i ) * typeWidth ) + offset );
784+ (long ) (i + toIndex ) * typeWidth ,
785+ fromRunEndBuffer .getInt ((long ) (i ) * typeWidth ) + offset );
759786 }
760787
761788 } else if (toRunEndVector instanceof BigIntVector ) {
762789 byte typeWidth = BigIntVector .TYPE_WIDTH ;
763790 for (int i = 0 ; i < physicalLength ; i ++) {
764791 toRunEndBuffer .setLong (
765- (long ) i * typeWidth , fromRunEndBuffer .getLong ((long ) (i ) * typeWidth ) + offset );
792+ (long ) (i + toIndex ) * typeWidth ,
793+ fromRunEndBuffer .getLong ((long ) (i ) * typeWidth ) + offset );
766794 }
767795 } else {
768796 throw new IllegalArgumentException (
0 commit comments