/** * * @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; }
@Override final boolean getBoolean(int rowId) { return accessor.get(rowId) == 1; } }
/** * Same as {@link #set(int, BitHolder)} except that it handles the * case when index is greater than or equal to existing * value capacity {@link #getValueCapacity()}. * * @param index position of element * @param holder data holder for value of element */ public void setSafe(int index, BitHolder holder) { handleSafe(index); set(index, holder); }
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); }
/** * * @param allocator * @param name * @return */ public static BitVector booleanVectorOf(BufferAllocator allocator,String name,int length) { BitVector float8Vector = new BitVector(name,allocator); float8Vector.allocateNew(length); float8Vector.setValueCount(length); return float8Vector; }
private BitVector bitVector(String name) { BitVector vec = new BitVector(name, getAllocator()); vec.allocateNew(COUNT); vec.set(0, 1); vec.set(1, 0); vec.setNull(2); vec.set(3, 1); vec.set(4, 1); vec.setValueCount(COUNT); return vec; }
@Test public void boolNullEveryOther() throws Exception { final int count = 1024; try ( BitVector in = new BitVector("in", allocator); BitVector out = new BitVector("out", allocator); ) { in.allocateNew(count); ArrowBuf tempBuf = allocator.buffer(1024); for (int i = 0; i < count; i ++) { if (i % 2 == 0) { in.set(i, 1); } } in.setValueCount(count); final PivotDef pivot = PivotBuilder.getBlockDefinition(new FieldVectorPair(in, out)); try ( final FixedBlockVector fbv = new FixedBlockVector(allocator, pivot.getBlockWidth()); final VariableBlockVector vbv = new VariableBlockVector(allocator, pivot.getVariableCount()); ) { fbv.ensureAvailableBlocks(count); Pivots.pivot(pivot, count, fbv, vbv); Unpivots.unpivot(pivot, fbv, vbv, 0, count); for (int i = 0; i < count; i++) { assertEquals(in.getObject(i), out.getObject(i)); } } tempBuf.release(); } }
final int count = 4; try ( BitVector in = new BitVector("in", allocator); BitVector out = new BitVector("out", allocator); ) { in.allocateNew(count); ArrowBuf validityBuf = in.getValidityBuffer(); ArrowBuf valueBuf = in.getValidityBuffer(); BitVectorHelper.setValidityBit(valueBuf, 3, 0); in.setValueCount(count); assertEquals(in.getObject(i), out.getObject(i));
final BitVector output = new BitVector("", allocator); final VectorContainer container = new VectorContainer(); ){ output.allocateNew(splitsLoaded); if (!output.isNull(i) && output.get(i) == 1) {
@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(); } }
@Override public FieldVector getNewVector( String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { return new BitVector(name, fieldType, allocator); }
@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); } }
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); } } } }
public void writeNull() { vector.setNull(idx()); vector.setValueCount(idx()+1); } }
public void loadData(SerializedField metadata, ArrowBuf buffer) { /* clear the current buffers (if any) */ vector.clear(); /* get the metadata children */ final SerializedField bitsField = metadata.getChild(0); final SerializedField valuesField = metadata.getChild(1); final int valuesLength = buffer.capacity(); vector.allocateNew(metadata.getValueCount()); /* set inner validity buffer */ setValidityBuffer(bitsField); /* load inner value buffer */ vector.valueBuffer.close(); loadDataBuffer(valuesField, buffer.slice(0, valuesLength)); }
@Override public void allocate() { vector.allocateNew(); }
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);