Java Code Examples for org.apache.arrow.vector.DecimalVector#setValueCount()

The following examples show how to use org.apache.arrow.vector.DecimalVector#setValueCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBoundedPivots.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
static BigDecimal[] populate16ByteValues(DecimalVector vector, int size){
  vector.allocateNew();
  BigDecimal values[] = new BigDecimal[size];
  for(int i =0; i < values.length; i++){
    if (RAND.nextBoolean()) {
      values[i] = BigDecimal.valueOf(RAND.nextLong());
      vector.setSafe(i, values[i]);
    }
  }
  vector.setValueCount(values.length);
  return values;
}
 
Example 2
Source File: TestBoundedPivots.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
static BigDecimal[] populate16ByteValuesWithoutNull(DecimalVector vector, int size){
  vector.allocateNew();
  BigDecimal values[] = new BigDecimal[size];
  for(int i =0; i < values.length; i++){
    values[i] = BigDecimal.valueOf(RAND.nextLong());
    vector.setSafe(i, values[i]);
  }
  vector.setValueCount(values.length);
  return values;
}
 
Example 3
Source File: TestBackwardsCompatibilityHandler.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Test
public void testPatchDecimal() {
  DecimalVector decimalVector = new DecimalVector("decimal", allocator, 38, 9);
  decimalVector.allocateNew(8);

  BigDecimal decimal1 = new BigDecimal("123456789.000000000");
  BigDecimal decimal2 = new BigDecimal("11.123456789");
  BigDecimal decimal3 = new BigDecimal("1.000000000");
  BigDecimal decimal4 = new BigDecimal("0.111111111");
  BigDecimal decimal5 = new BigDecimal("-987654321.123456789");
  BigDecimal decimal6 = new BigDecimal("-222222222222.222222222");
  BigDecimal decimal7 = new BigDecimal("-7777777777777.666666667");
  BigDecimal decimal8 = new BigDecimal("1212121212.343434343");

  decimalVector.set(0, decimal1);
  decimalVector.set(1, decimal2);
  decimalVector.set(2, decimal3);
  decimalVector.set(3, decimal4);
  decimalVector.set(4, decimal5);
  decimalVector.set(5, decimal6);
  decimalVector.set(6, decimal7);
  decimalVector.set(7, decimal8);

  decimalVector.setValueCount(8);

  assertEquals(8, decimalVector.getValueCount());
  assertEquals(decimal1, decimalVector.getObject(0));
  assertEquals(decimal2, decimalVector.getObject(1));
  assertEquals(decimal3, decimalVector.getObject(2));
  assertEquals(decimal4, decimalVector.getObject(3));
  assertEquals(decimal5, decimalVector.getObject(4));
  assertEquals(decimal6, decimalVector.getObject(5));
  assertEquals(decimal7, decimalVector.getObject(6));
  assertEquals(decimal8, decimalVector.getObject(7));

  FixedWidthVectorHelper vectorHelper = new FixedWidthVectorHelper(decimalVector);
  SerializedField.Builder decimalField = vectorHelper.getMetadataBuilder();
  SerializedField.Builder childDecimalField = decimalField.getChildBuilderList().get(1);
  ByteBuf newBuffer = patchDecimal(allocator, decimalVector.getDataBuffer().asNettyBuffer(), decimalField,
    childDecimalField);

  int startIndex = 0;
  BigDecimal bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal1);
  startIndex += DecimalVector.TYPE_WIDTH + 8;

  bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal2);
  startIndex += DecimalVector.TYPE_WIDTH + 8;

  bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal3);
  startIndex += DecimalVector.TYPE_WIDTH + 8;

  bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal4);
  startIndex += DecimalVector.TYPE_WIDTH + 8;

  bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal5);
  startIndex += DecimalVector.TYPE_WIDTH + 8;

  bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal6);
  startIndex += DecimalVector.TYPE_WIDTH + 8;

  bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal7);
  startIndex += DecimalVector.TYPE_WIDTH + 8;

  bd = DecimalHelper.getBigDecimalFromSparse(newBuffer, startIndex, DrillBackwardsCompatibilityHandler.NUMBER_DECIMAL_DIGITS, decimalVector.getScale());
  assertEquals(bd, decimal8);

  final ArrowBuf validityBuffer = decimalVector.getValidityBuffer();
  validityBuffer.release();
  newBuffer.release();
}