/** * 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); }
private static Pair<BitVector, ResultVerifier> testBitVector(final int startIndexInCurrentOutput, final int startIndexInJob) { BitVector colBitV = new BitVector("colBit", allocator); colBitV.allocateNew(5); colBitV.set(0, 1); colBitV.set(1, 0); colBitV.setNull(2); colBitV.set(3, 1); colBitV.set(4, 1); ResultVerifier verifier = new ResultVerifier() { @Override public void verify(DataPOJO output) { int index = startIndexInCurrentOutput; assertTrue((Boolean)output.extractValue("colBit", index++)); assertFalse((Boolean)output.extractValue("colBit", index++)); assertNull(output.extractValue("colBit", index++)); assertTrue((Boolean)output.extractValue("colBit", index++)); assertTrue((Boolean)output.extractValue("colBit", index)); } }; return Pair.of(colBitV, verifier); }
private static Boolean[] populateBooleanValues(BitVector vector, int size) { assert size >= 4096; vector.allocateNew(size); Boolean[] booleanValues = new Boolean[size]; for (int i = 0; i < size; i++) { if (i < 64 || (i >= 256 && i < 256 + 64)) { vector.setNull(i); continue; } if ((i % 6) != 0) { /* every 6th value in boolean column is null */ if ((i & 1) == 0) { /* column value true */ vector.set(i, 1); booleanValues[i] = true; } else { /* column value false */ vector.set(i, 0); booleanValues[i] = false; } } else { vector.setNull(i); booleanValues[i] = null; } } vector.setValueCount(size); return booleanValues; }
/** Helper method which creates a test bit vector */ private static BitVector testBitVector() { BitVector colBitV = new BitVector("colBit", ALLOCATOR); colBitV.allocateNew(5); for(int i=0; i<TEST_BIT_VALUES.size(); i++) { if (TEST_BIT_VALUES.get(i) == null) { colBitV.setNull(i); } else { colBitV.set(i, TEST_BIT_VALUES.get(i) ? 1 : 0); } } return colBitV; }
/** * Same as {@link #set(int, NullableBitHolder)} 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 nullable data holder for value of element */ public void setSafe(int index, NullableBitHolder holder) throws IllegalArgumentException { handleSafe(index); set(index, holder); }
private static Boolean[] populateBooleanValuesWithoutNull(BitVector vector, int size) { assert size >= 4096; vector.allocateNew(size); Boolean[] booleanValues = new Boolean[size]; for (int i = 0; i < size; i++) { if (i < 64 || (i >= 256 && i < 256 + 64)) { vector.setNull(i); continue; } if ((i % 6) != 0) { /* every 6th value in boolean column is null */ if ((i & 1) == 0) { /* column value true */ vector.set(i, 1); booleanValues[i] = true; } else { /* column value false */ vector.set(i, 0); booleanValues[i] = false; } } else { vector.setNull(i); booleanValues[i] = null; } } vector.setValueCount(size); return booleanValues; }
@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(); } }
/** * Same as {@link #set(int, int)} 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 value value of element */ public void setSafe(int index, int value) { handleSafe(index); set(index, value); }
in.set(i, 1);
/** * Same as {@link #set(int, int, int)} except that it handles the case * when index is greater than or equal to current value capacity of the * vector. * * @param index position of the new value * @param isSet 0 for NULL value, 1 otherwise * @param value element value */ public void setSafe(int index, int isSet, int value) { handleSafe(index); set(index, isSet, value); }
/** * Store the given value at a particular position in the vector. isSet indicates * whether the value is NULL or not. * * @param index position of the new value * @param isSet 0 for NULL value, 1 otherwise * @param value element value */ public void set(int index, int isSet, int value) { if (isSet > 0) { set(index, value); } else { BitVectorHelper.setValidityBit(validityBuffer, index, 0); } }