/** * Get the variable length element at specified index and sets the state * in provided holder. * * @param index position of element to get * @param holder data holder to be populated by this function */ public void get(int index, NullableVarCharHolder holder) { assert index >= 0; if (isSet(index) == 0) { holder.isSet = 0; return; } holder.isSet = 1; holder.start = getstartOffset(index); holder.end = offsetBuffer.getInt((index + 1) * OFFSET_WIDTH); holder.buffer = valueBuffer; }
/** * Get the variable length element at specified index as byte array. * * @param index position of element to get * @return array of bytes for non-null element, null otherwise */ public byte[] get(int index) { assert index >= 0; if (isSet(index) == 0) { throw new IllegalStateException("Value at index is null"); } final int startOffset = getstartOffset(index); final int dataLength = offsetBuffer.getInt((index + 1) * OFFSET_WIDTH) - startOffset; final byte[] result = new byte[dataLength]; valueBuffer.getBytes(startOffset, result, 0, dataLength); return result; }
/** * Copy a cell value from a particular index in source vector to a particular * position in this vector. * * @param fromIndex position to copy from in source vector * @param thisIndex position to copy to in this vector * @param from source vector */ public void copyFrom(int fromIndex, int thisIndex, VarCharVector from) { final int start = from.offsetBuffer.getInt(fromIndex * OFFSET_WIDTH); final int end = from.offsetBuffer.getInt((fromIndex + 1) * OFFSET_WIDTH); final int length = end - start; fillHoles(thisIndex); BitVectorHelper.setValidityBit(this.validityBuffer, thisIndex, from.isSet(fromIndex)); final int copyStart = offsetBuffer.getInt(thisIndex * OFFSET_WIDTH); from.valueBuffer.getBytes(start, this.valueBuffer, copyStart, length); offsetBuffer.setInt((thisIndex + 1) * OFFSET_WIDTH, copyStart + length); lastSet = thisIndex; }
/** * Same as {@link #copyFrom(int, int, VarCharVector)} except that * it handles the case when the capacity of the vector needs to be expanded * before copy. * * @param fromIndex position to copy from in source vector * @param thisIndex position to copy to in this vector * @param from source vector */ public void copyFromSafe(int fromIndex, int thisIndex, VarCharVector from) { final int start = from.offsetBuffer.getInt(fromIndex * OFFSET_WIDTH); final int end = from.offsetBuffer.getInt((fromIndex + 1) * OFFSET_WIDTH); final int length = end - start; handleSafe(thisIndex, length); fillHoles(thisIndex); BitVectorHelper.setValidityBit(this.validityBuffer, thisIndex, from.isSet(fromIndex)); final int copyStart = offsetBuffer.getInt(thisIndex * OFFSET_WIDTH); from.valueBuffer.getBytes(start, this.valueBuffer, copyStart, length); offsetBuffer.setInt((thisIndex + 1) * OFFSET_WIDTH, copyStart + length); lastSet = thisIndex; }
case VARCHAR : holder = new NullableVarCharHolder(); ((NullableVarCharHolder)holder).isSet = ((VarCharVector) vector).isSet(index); if (((NullableVarCharHolder)holder).isSet == 1) { ((VarCharVector) vector).get(index, (NullableVarCharHolder)holder);