@Override public void copy(int inputIdx, int count, int outputIdx) { final long[] input = inputVector.vector; if (inputVector.isRepeating) { if (inputVector.isNull[0]) { return; // If all repeating values are null, then there is no need to write anything to vector } final int value = (int) input[0]; for (int i = 0; i < count; i++, outputIdx++) { outputVector.setSafe(outputIdx, value); } } else if (inputVector.noNulls) { for (int i = 0; i < count; i++, inputIdx++, outputIdx++) { outputVector.setSafe(outputIdx, (int) input[inputIdx]); } } else { final boolean isNull[] = inputVector.isNull; for (int i = 0; i < count; i++, inputIdx++, outputIdx++) { if (!isNull[inputIdx]) { outputVector.setSafe(outputIdx, (int) input[inputIdx]); } } } } }
@Override public void writeField(Object pojo, int outboundIndex) throws IllegalArgumentException, IllegalAccessException { Boolean o = (Boolean) field.get(pojo); if (o != null) { vector.setSafe(outboundIndex, o ? 1 : 0); } }
public void populate(final int count){ for (int i = 0; i < count; i++) { if(value != null) { ((BitVector) vector).setSafe(i, value ? 1 : 0); } } vector.setValueCount(count); }
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final boolean value = (boolean) ((BooleanObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue); ((BitVector) outputVV).setSafe(outputIndex, value ? 1 : 0); } }
@Override public void set(ValueVector v, int index) { if(obj != null){ ((BitVector) v).setSafe(index, obj == true ? 1 : 0); } }
@Override protected void readField(long recordsToReadInThisPass) { recordsReadInThisIteration = Math.min(pageReader.currentPageCount - pageReader.valuesRead, recordsToReadInThisPass - valuesReadInCurrentPass); // A more optimized reader for bit columns was removed to fix the bug // DRILL-2031. It attempted to copy large runs of values directly from the // decompressed parquet stream into a BitVector. This was complicated by // parquet not always breaking a page on a row number divisible by 8. In // this case the batch would have to be cut off early or we would have to // copy the next page byte-by-byte with a bit shift to move the values into // the correct position (to make the value vector one contiguous buffer of // data). As page boundaries do not line up across columns, cutting off a // batch at every page boundary of a bit column could be costly with many // such pages, so we opted to try to shift the nodes when necessary. // // In the end, this was too much complexity for not enough performance // benefit, for now this reader has been moved to use the higher level value // by value reader provided by the parquet library. for (int i = 0; i < recordsReadInThisIteration; i++){ valueVec.setSafe(i + valuesReadInCurrentPass, pageReader.valueReader.readBoolean() ? 1 : 0 ); } } }
public void write(NullableBitHolder h) { vector.setSafe(idx(), h); vector.setValueCount(idx()+1); }
public void write(BitHolder h) { vector.setSafe(idx(), h); vector.setValueCount(idx()+1); }
public void writeBit(int value) { vector.setSafe(idx(), 1, value); vector.setValueCount(idx()+1); }
/** * * @param allocator * @param name * @param data * @return */ public static BitVector vectorFor(BufferAllocator allocator,String name,boolean[] data) { BitVector float8Vector = new BitVector(name,allocator); float8Vector.allocateNew(data.length); for(int i = 0; i < data.length; i++) { float8Vector.setSafe(i,data[i] ? 1 : 0); } float8Vector.setValueCount(data.length); return float8Vector; }
private void decodeBoolean(IntVector input, BitVector output) { if (hasSv2) { final SelectionVector2 sv2 = incoming.getSelectionVector2(); for (int i = 0; i < recordsConsumedCurrentBatch; ++i) { final int svIndex = sv2.getIndex(i); if (input.isNull(svIndex)) { output.setNull(svIndex); } else { final int id = input.get(svIndex); output.setSafe(svIndex, id); } } } else { for (int i = 0; i < recordsConsumedCurrentBatch; ++i) { if (input.isNull(i)) { output.setNull(i); } else { final int id = input.get(i); output.setSafe(i, id); } } } }
BitVector bitVect = (BitVector) vv; if(pv.getBitValue() != null){ bitVect.setSafe(index, pv.getBitValue() ? 1 : 0);
@Test public void testConvertBitsToBytes() { try ( BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); BitVector bits = new BitVector("$bits$", allocator); UInt1Vector bytes = new UInt1Vector("$bits$", allocator); ) { int count = 100; for (int i = 0; i < count ; i++) { bits.setSafe(i, i % 2); } bits.setValueCount(count); ArrowBuf oldBuf = bits.getDataBuffer(); oldBuf.retain(); SerializedField.Builder fieldBuilder = TypeHelper.getMetadataBuilder(bits); ArrowBuf newBuf = convertBitsToBytes(allocator, fieldBuilder, oldBuf); bytes.setValueCount(count); SerializedField.Builder newfieldBuilder = TypeHelper.getMetadataBuilder(bytes); TypeHelper.loadData(bytes, newfieldBuilder.build(), newBuf); for (int i = 0; i < count ; i++) { assertEquals(i % 2, bytes.get(i)); } newBuf.release(); } }
switch (type.getMode()) { case REQUIRED: ((BitVector) vector).setSafe(index, (BitHolder) holder); return; case OPTIONAL: if (holder instanceof NullableBitHolder) { if (((NullableBitHolder) holder).isSet == 1) { ((BitVector) vector).setSafe(index, (NullableBitHolder) holder); } else { ((BitVector) vector).isSafe(index); ((BitVector) vector).setSafe(index, (BitHolder) holder);