org.apache.arrow.vector.DecimalVector Java Examples

The following examples show how to use org.apache.arrow.vector.DecimalVector. 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: MinAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long minAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putLong(minAddr, Double.doubleToLongBits(min(Double.longBitsToDouble(PlatformDependent.getLong(minAddr)), newVal.doubleValue(), bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #2
Source File: SumAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putLong(sumAddr, Double.doubleToLongBits(Double.longBitsToDouble(PlatformDependent.getLong(sumAddr)) + newVal.doubleValue() * bitVal));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #3
Source File: MaxAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxMemAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxMemAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++){
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long maxAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putLong(maxAddr, Double.doubleToLongBits(max(Double.longBitsToDouble(PlatformDependent.getLong(maxAddr)), newVal.doubleValue(), bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #4
Source File: SumZeroAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    final long sumAddr = valueAddresses[tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK] + (tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK) * WIDTH_ACCUMULATOR;
    PlatformDependent.putLong(sumAddr, Double.doubleToLongBits(Double.longBitsToDouble(PlatformDependent.getLong(sumAddr)) + newVal.doubleValue() * bitVal));
  }
}
 
Example #5
Source File: SumZeroAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    // without if we would need to do a multiply which is slow.
    if (bitVal == 0) {
      continue;
    }
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    final long sumAddr = valueAddresses[tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK] + (tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK) * WIDTH_ACCUMULATOR;
    BigDecimal curVal = DecimalUtils.getBigDecimalFromLEBytes(sumAddr, valBuf, scale);
    BigDecimal runningVal = curVal.add(newVal, DecimalUtils.MATH);
    byte [] valueInArrowBytes = DecimalUtils.convertBigDecimalToArrowByteArray(runningVal);
    PlatformDependent.copyMemory(valueInArrowBytes, 0, sumAddr, WIDTH_INPUT);
  }
}
 
Example #6
Source File: TestBoundedPivots.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void fixedOnlyWithoutNull(){
  try(IntVector col1 = new IntVector("col1", allocator);
      BigIntVector col2 = new BigIntVector("col2", allocator);
      DecimalVector col3 = new DecimalVector("col3", allocator, 30, 0);
      BitVector col4 = new BitVector("col4", allocator)){

    PivotDef pivot = PivotBuilder.getBlockDefinition(
      new FieldVectorPair(col1, col1),
      new FieldVectorPair(col2, col2),
      new FieldVectorPair(col3, col3),
      new FieldVectorPair(col4, col4)
    );
    Integer col1Val[] = populate4ByteValuesWithoutNull(col1, 4096);
    Long col2Val[] = populate8ByteValuesWithoutNull(col2, 4096);
    BigDecimal col3Val[] = populate16ByteValuesWithoutNull(col3, 4096);
    Boolean col4Val[] = populateBooleanValuesWithoutNull(col4, 4096);

    assertEquals(32, pivot.getBlockWidth());

    try(FixedBlockVector fixed = new FixedBlockVector(allocator, pivot.getBlockWidth(), 4096, true);
        VariableBlockVector variable = new VariableBlockVector(allocator, pivot.getVariableCount(), 4096 * 10, true)){
      fixedOnlyHelper(pivot, fixed, variable, 0, 4096, false, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 128, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 17, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 76, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 5, 39, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 5, 189, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 5, 123, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 1023, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 2046, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 3069, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 4092, 4, true, col1Val, col2Val, col3Val, col4Val);
    }
  }
}
 
Example #7
Source File: ArrowUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private static int getPrecision(DecimalVector decimalVector) {
	int precision = -1;
	try {
		java.lang.reflect.Field precisionField = decimalVector.getClass().getDeclaredField("precision");
		precisionField.setAccessible(true);
		precision = (int) precisionField.get(decimalVector);
	} catch (NoSuchFieldException | IllegalAccessException e) {
		// should not happen, ignore
	}
	return precision;
}
 
Example #8
Source File: BaseTestJoin.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
protected void baseManyColumnsDecimal() throws Exception {
  int columns = 1000;
  int leftColumns = columns;
  int rightColumns = columns;

  JoinInfo joinInfo = getJoinInfo(Arrays.asList(new JoinCondition("EQUALS", f("left_1"), f("right_1"))), JoinRelType.LEFT, JoinUtils.projectAll(1000).asSet(), JoinUtils.projectAll(1000).asSet());

  Table expected = t(getHeader("right", rightColumns, "left", leftColumns), false, getDataDecimal(columns, leftColumns, 1));
  validateDual(joinInfo.operator, joinInfo.clazz,
    new ManyColumnsGenerator<DecimalVector>(getTestAllocator(), "left", leftColumns, 1,
      DecimalVector.class, new ArrowType.Decimal(38, 0), BaseTestJoin::insertIntoDecimalVector),
    new ManyColumnsGenerator<DecimalVector>(getTestAllocator(), "right", rightColumns, 1,
      DecimalVector.class, new ArrowType.Decimal(38, 0), BaseTestJoin::insertIntoDecimalVector),
    DEFAULT_BATCH, expected);
}
 
Example #9
Source File: BaseTestJoin.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static void insertIntoDecimalVector(int index, int value, BaseFixedWidthVector vector) {
  DecimalVector vec = (DecimalVector)vector;
  DecimalHolder holder = new DecimalHolder();
  holder.buffer = vec.getDataBuffer();
  DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(value), holder.buffer, 0);
  holder.start = 0;
  holder.scale = 0;
  holder.precision = 38;
  vec.setSafe(index, holder);
}
 
Example #10
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 #11
Source File: VectorizedParquetDefinitionLevelReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
public void readBatchOfIntLongBackedDecimals(
    final FieldVector vector, final int startOffset,
    final int typeWidth, final int numValsToRead, NullabilityHolder nullabilityHolder,
    ValuesAsBytesReader valuesReader) {
  int bufferIdx = startOffset;
  int left = numValsToRead;
  while (left > 0) {
    if (this.currentCount == 0) {
      this.readNextGroup();
    }
    int num = Math.min(left, this.currentCount);
    byte[] byteArray = new byte[DecimalVector.TYPE_WIDTH];
    switch (mode) {
      case RLE:
        if (currentValue == maxDefLevel) {
          for (int i = 0; i < num; i++) {
            setIntLongBackedDecimal(vector, typeWidth, nullabilityHolder, valuesReader, bufferIdx, byteArray);
            bufferIdx++;
          }
        } else {
          setNulls(nullabilityHolder, bufferIdx, num, vector.getValidityBuffer());
          bufferIdx += num;
        }
        break;
      case PACKED:
        for (int i = 0; i < num; ++i) {
          if (packedValuesBuffer[packedValuesBufferIdx++] == maxDefLevel) {
            setIntLongBackedDecimal(vector, typeWidth, nullabilityHolder, valuesReader, bufferIdx, byteArray);
          } else {
            setNull(nullabilityHolder, bufferIdx, vector.getValidityBuffer());
          }
          bufferIdx++;
        }
        break;
    }
    left -= num;
    currentCount -= num;
  }
}
 
Example #12
Source File: VectorizedParquetDefinitionLevelReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private void setIntLongBackedDecimal(FieldVector vector, int typeWidth, NullabilityHolder nullabilityHolder,
                                     ValuesAsBytesReader valuesReader, int bufferIdx, byte[] byteArray) {
  valuesReader.getBuffer(typeWidth).get(byteArray, 0, typeWidth);
  vector.getDataBuffer().setBytes(bufferIdx * DecimalVector.TYPE_WIDTH, byteArray);
  nullabilityHolder.setNotNull(bufferIdx);
  if (setArrowValidityVector) {
    BitVectorHelper.setValidityBitToOne(vector.getValidityBuffer(), bufferIdx);
  }
}
 
Example #13
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 #14
Source File: SumAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector) inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    java.math.BigDecimal newVal = DecimalUtils.getBigDecimalFromLEBytes(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target addresses of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    /* store the accumulated values at the target location of accumulation vector */
    PlatformDependent.putLong(sumAddr, Double.doubleToLongBits(Double.longBitsToDouble(PlatformDependent.getLong(sumAddr)) + newVal.doubleValue() * bitVal));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #15
Source File: DecimalWriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void doWrite(T in, int ordinal) {
	if (isNullAt(in, ordinal)) {
		((DecimalVector) getValueVector()).setNull(getCount());
	} else {
		BigDecimal bigDecimal = readDecimal(in, ordinal).toBigDecimal();
		bigDecimal = fromBigDecimal(bigDecimal, precision, scale);
		if (bigDecimal == null) {
			((DecimalVector) getValueVector()).setNull(getCount());
		} else {
			((DecimalVector) getValueVector()).setSafe(getCount(), bigDecimal);
		}
	}
}
 
Example #16
Source File: Dremio09BackwardCompatibilityHandler.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * swap the bytes in place to get the BE byte order in NullableDecimalVector
 * @param dataBuffer data buffer of decimal vector
 */
static void patchDecimal(final NettyArrowBuf dataBuffer) {
  final int decimalLength = DecimalVector.TYPE_WIDTH;
  int startPoint = dataBuffer.readerIndex();
  final int valueCount = dataBuffer.readableBytes()/decimalLength;
  for (int i = 0; i < valueCount; i++) {
    for (int j = startPoint, k = startPoint + decimalLength - 1; j < k; j++, k--) {
      final byte firstByte = dataBuffer.getByte(j);
      final byte lastByte = dataBuffer.getByte(k);
      dataBuffer.setByte(j, lastByte);
      dataBuffer.setByte(k, firstByte);
    }
    startPoint += decimalLength;
  }
}
 
Example #17
Source File: TestBoundedPivots.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void fixedOnly(){
  try(IntVector col1 = new IntVector("col1", allocator);
      BigIntVector col2 = new BigIntVector("col2", allocator);
      DecimalVector col3 = new DecimalVector("col3", allocator, 30, 0);
      BitVector col4 = new BitVector("col4", allocator)){

    PivotDef pivot = PivotBuilder.getBlockDefinition(
        new FieldVectorPair(col1, col1),
        new FieldVectorPair(col2, col2),
        new FieldVectorPair(col3, col3),
        new FieldVectorPair(col4, col4)
    );
    Integer col1Val[] = populate4ByteValues(col1, 4096);
    Long col2Val[] = populate8ByteValues(col2, 4096);
    BigDecimal col3Val[] = populate16ByteValues(col3, 4096);
    Boolean col4Val[] = populateBooleanValues(col4, 4096);

    assertEquals(32, pivot.getBlockWidth());

    try(FixedBlockVector fixed = new FixedBlockVector(allocator, pivot.getBlockWidth(), 4096, true);
        VariableBlockVector variable = new VariableBlockVector(allocator, pivot.getVariableCount(), 4096 * 10, true)){
      fixedOnlyHelper(pivot, fixed, variable, 0, 4096, false, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 128, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 17, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 76, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 5, 39, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 5, 189, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 5, 123, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 0, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 1023, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 2046, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 3069, 1023, true, col1Val, col2Val, col3Val, col4Val);
      fixedOnlyHelper(pivot, fixed, variable, 4092, 4, true, col1Val, col2Val, col3Val, col4Val);
    }
  }
}
 
Example #18
Source File: TestBatchSize.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecordBatchAllocs() {
  OptionManager options = Mockito.mock(OptionManager.class);
  when(options.getOption(ExecConstants.TARGET_BATCH_RECORDS_MIN)).thenReturn(127L);
  when(options.getOption(ExecConstants.TARGET_BATCH_RECORDS_MAX)).thenReturn(4095L);
  when(options.getOption(ExecConstants.TARGET_BATCH_SIZE_BYTES)).thenReturn(1024 * 1024L);

  int batchSize = PhysicalPlanCreator.calculateBatchCountFromRecordSize(options, 0);
  Assert.assertTrue(batchSize >= (int)(0.95 * 4096));

  try (BufferAllocator allocator = allocatorRule.newAllocator("test-batch-size", 0, Long.MAX_VALUE)) {
    final ValueVector bitV = new BitVector("bits", allocator);
    AllocationHelper.allocate(bitV, batchSize, 0);
    Assert.assertEquals(1024, allocator.getAllocatedMemory());
    bitV.close();

    final ValueVector intV = new IntVector("ints", allocator);
    AllocationHelper.allocate(intV, batchSize, 0);
    Assert.assertEquals(4096 * 4, allocator.getAllocatedMemory());
    intV.close();

    final ValueVector longV = new BigIntVector("longs", allocator);
    AllocationHelper.allocate(longV, batchSize, 0);
    Assert.assertEquals(4096 * 8, allocator.getAllocatedMemory());
    longV.close();

    final ValueVector decimalV = new DecimalVector("decimals", allocator, 38, 9);
    AllocationHelper.allocate(decimalV, batchSize, 0);
    Assert.assertEquals(4096 * 16, allocator.getAllocatedMemory());
    decimalV.close();
  }
}
 
Example #19
Source File: VectorizedDictionaryEncodedParquetValuesReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
void readBatchOfDictionaryEncodedIntLongBackedDecimals(FieldVector vector, int typeWidth, int startOffset,
                                                       int numValuesToRead, Dictionary dict,
                                                       NullabilityHolder nullabilityHolder) {
  int left = numValuesToRead;
  int idx = startOffset;
  while (left > 0) {
    if (this.currentCount == 0) {
      this.readNextGroup();
    }
    int num = Math.min(left, this.currentCount);
    switch (mode) {
      case RLE:
        for (int i = 0; i < num; i++) {
          ((DecimalVector) vector).set(
              idx,
              typeWidth == Integer.BYTES ? dict.decodeToInt(currentValue) : dict.decodeToLong(currentValue));
          nullabilityHolder.setNotNull(idx);
          idx++;
        }
        break;
      case PACKED:
        for (int i = 0; i < num; i++) {
          ((DecimalVector) vector).set(
              idx,
              typeWidth == Integer.BYTES ?
                  dict.decodeToInt(packedValuesBuffer[packedValuesBufferIdx++])
                  : dict.decodeToLong(packedValuesBuffer[packedValuesBufferIdx++]));
          nullabilityHolder.setNotNull(idx);
          idx++;
        }
        break;
    }
    left -= num;
    currentCount -= num;
  }
}
 
Example #20
Source File: SumAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector) inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    long addressOfInput = incomingValue + (incomingIndex * WIDTH_INPUT);
    long newValLow = PlatformDependent.getLong(addressOfInput) * bitVal;
    long newValHigh =
      PlatformDependent.getLong(addressOfInput + DecimalUtils.LENGTH_OF_LONG) * bitVal;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target addresses of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    /* store the accumulated values at the target location of accumulation vector */
    long curValLow = PlatformDependent.getLong(sumAddr);
    long curValHigh = PlatformDependent.getLong(sumAddr + DecimalUtils.LENGTH_OF_LONG);
    DecimalUtils.addSignedDecimals(sumAddr, newValLow, newValHigh, curValLow, curValHigh);
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #21
Source File: DrillBackwardsCompatibilityHandler.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Dremio has 16 byte little endian decimal format. When sending data to Drill clients
 * we map our data to 24 byte DECIMAL38SPARSE format in Drill.
 * @param dataBuffer data buffer of decimal vector
 */
static ByteBuf patchDecimal(BufferAllocator allocator, final NettyArrowBuf dataBuffer,
                            final SerializedField.Builder decimalField, final SerializedField.Builder childDecimalField) {
  final int decimalLength = DecimalVector.TYPE_WIDTH;
  final int startPoint = dataBuffer.readerIndex();
  final int valueCount = dataBuffer.readableBytes()/decimalLength;
  final ByteBuf drillBuffer = allocator.buffer(dataBuffer.readableBytes() + 8*valueCount).asNettyBuffer();
  int length = 0;
  for (int i = startPoint; i < startPoint + dataBuffer.readableBytes() - 1; i+=decimalLength) {
    final BigDecimal arrowDecimal = DecimalUtility.getBigDecimalFromArrowBuf(dataBuffer.arrowBuf(), i/16,
      decimalField.getMajorType().getScale());
    final int startIndex = (i == startPoint) ? i : i + length;
    DecimalHelper.getSparseFromBigDecimal(arrowDecimal, drillBuffer, startIndex, decimalField.getMajorType().getScale(), NUMBER_DECIMAL_DIGITS);
    length += 8;
  }

  TypeProtos.MajorType.Builder majorTypeBuilder = TypeProtos.MajorType.newBuilder()
    .setMinorType(MinorType.DECIMAL38SPARSE)
    .setMode(DataMode.OPTIONAL)
    .setPrecision(decimalField.getMajorType().getPrecision())
    .setScale(decimalField.getMajorType().getScale());

  decimalField.setMajorType(majorTypeBuilder.build());
  decimalField.setBufferLength(decimalField.getBufferLength() + 8*valueCount);
  drillBuffer.writerIndex(dataBuffer.readableBytes() + 8*valueCount);
  childDecimalField.setMajorType(com.dremio.common.types.Types.required(MinorType.DECIMAL38SPARSE));
  childDecimalField.setBufferLength(childDecimalField.getBufferLength() + 8*valueCount);
  dataBuffer.release();

  return drillBuffer;
}
 
Example #22
Source File: MinAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    java.math.BigDecimal newVal = DecimalUtils.getBigDecimalFromLEBytes(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target addresses of accumulation vector */
    final long minAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    /* store the accumulated values(new min or existing) at the target location of accumulation vector */
    PlatformDependent.putLong(minAddr, Double.doubleToLongBits(min(Double.longBitsToDouble(PlatformDependent.getLong(minAddr)), newVal.doubleValue(), bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #23
Source File: SumZeroAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    long addressOfInput = incomingValue + (incomingIndex * WIDTH_INPUT);
    long newValLow = PlatformDependent.getLong(addressOfInput) * bitVal;
    long newValHigh =
      PlatformDependent.getLong(addressOfInput + DecimalUtils.LENGTH_OF_LONG) * bitVal;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target address of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    /* store the accumulated values at the target location of accumulation vector */
    long curValLow = PlatformDependent.getLong(sumAddr);
    long curValHigh = PlatformDependent.getLong(sumAddr + DecimalUtils.LENGTH_OF_LONG);
    DecimalUtils.addSignedDecimals(sumAddr, newValLow, newValHigh, curValLow, curValHigh);
  }
}
 
Example #24
Source File: SumZeroAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    java.math.BigDecimal newVal = DecimalUtils.getBigDecimalFromLEBytes(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target address of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    /* store the accumulated values at the target location of accumulation vector */
    PlatformDependent.putLong(sumAddr, Double.doubleToLongBits(Double.longBitsToDouble(PlatformDependent.getLong(sumAddr)) + newVal.doubleValue() * bitVal));
  }
}
 
Example #25
Source File: ColumnReaderFactory.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
static VarLengthValuesColumn<?> getReader(DeprecatedParquetVectorizedReader parentReader, int allocateSize, ColumnDescriptor descriptor,
                                          ColumnChunkMetaData columnChunkMetaData, boolean fixedLength, ValueVector v,
                                          SchemaElement schemaElement
) throws ExecutionSetupException {
  ConvertedType convertedType = schemaElement.getConverted_type();
  switch (descriptor.getMaxDefinitionLevel()) {
    case 0:
      if (convertedType == null) {
        return new VarLengthColumnReaders.VarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }
      switch (convertedType) {
        case UTF8:
          return new VarLengthColumnReaders.VarCharColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarCharVector) v, schemaElement);
        case DECIMAL:
          return new VarLengthColumnReaders.Decimal28Column(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (DecimalVector) v, schemaElement);
        default:
          return new VarLengthColumnReaders.VarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }
    default:
      if (convertedType == null) {
        return new VarLengthColumnReaders.NullableVarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }

      switch (convertedType) {
        case UTF8:
          return new VarLengthColumnReaders.NullableVarCharColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarCharVector) v, schemaElement);
        case DECIMAL:
          return new NullableDecimalColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (DecimalVector) v, schemaElement);
        default:
          return new VarLengthColumnReaders.NullableVarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }
  }
}
 
Example #26
Source File: VectorizedHashAggPartition.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void updateMinMaxAccumulator(final FieldVector deserializedAccumulator,
                                     final Accumulator[] partitionAccumulators,
                                     final int index,
                                     final BufferAllocator computationVectorAllocator) {

  /* We only need to handle DECIMAL in case decimal v2 is disabled.
   * For example, Int(Min/Max)Accumulator remains Int(Min/Max)Accumulator, Float(Min/Max)Accumulator
   * remains Float(Min/Max)Accumulator and similarly for Double(Min/Max), BigInt(Min/Max) etc.
   * The accumulator vector that was spilled now becomes the new input vector for
   * post-spill processing. However, for decimal min/max we store the output
   * (min and max values) in an accumulator vector of type Double. So for post-spill
   * processing Decimal(Min/Max)Accumulator becomes Double(Min/Max)Accumulator
   */
  final Accumulator partitionAccumulator = partitionAccumulators[index];
  if (!decimalV2Enabled) {
    if (partitionAccumulator instanceof MaxAccumulators.DecimalMaxAccumulator) {
      Preconditions.checkArgument(partitionAccumulator.getInput() instanceof DecimalVector,
        "Error: expecting decimal vector");
      partitionAccumulators[index] =
        new MaxAccumulators.DoubleMaxAccumulator((MaxAccumulators.DecimalMaxAccumulator) partitionAccumulator,
          deserializedAccumulator,
          hashTable.getActualValuesPerBatch(),
          computationVectorAllocator);
      return;
    } else if (partitionAccumulator instanceof MinAccumulators.DecimalMinAccumulator) {
      Preconditions.checkArgument(partitionAccumulator.getInput() instanceof DecimalVector,
        "Error: expecting decimal vector");
      partitionAccumulators[index] =
        new MinAccumulators.DoubleMinAccumulator((MinAccumulators.DecimalMinAccumulator) partitionAccumulator,
          deserializedAccumulator,
          hashTable.getActualValuesPerBatch(),
          computationVectorAllocator);
      return;
    }
    /* fall through in all other cases */
  }
  partitionAccumulator.setInput(deserializedAccumulator);

}
 
Example #27
Source File: MaxAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxMemAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxMemAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    java.math.BigDecimal newVal = DecimalUtils.getBigDecimalFromLEBytes(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target addresses of accumulation vector */
    final long maxAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    /* store the accumulated values(new max or existing) at the target location of accumulation vector */
    PlatformDependent.putLong(maxAddr, Double.doubleToLongBits(max(Double.longBitsToDouble(PlatformDependent.getLong(maxAddr)), newVal.doubleValue(), bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #28
Source File: SumAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    // without if we would need to do a multiply which is slow.
    if (bitVal == 0) {
      continue;
    }
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue
      + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    BigDecimal curVal = DecimalUtils.getBigDecimalFromLEBytes(sumAddr, valBuf, scale);
    BigDecimal runningVal = curVal.add(newVal, DecimalUtils.MATH);
    byte [] valueInArrowBytes = DecimalUtils.convertBigDecimalToArrowByteArray(runningVal);
    PlatformDependent.copyMemory(valueInArrowBytes, 0, sumAddr, WIDTH_INPUT);
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example #29
Source File: NdvAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;

    //incoming record is null, skip it
    if (bitVal == 0) {
      continue;
    }

    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);

    //get the proper chunk from the ordinal
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;

    final HllAccumHolder ah =  this.accumulators[chunkIndex];
    final HllSketch sketch = ah.getAccums()[chunkOffset];
    sketch.update(newVal.doubleValue());
  }
}
 
Example #30
Source File: NdvAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final int scale = ((DecimalVector) inputVector).getScale();

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    // without if we would need to do a multiply which is slow.
    if (bitVal == 0) {
      continue;
    }

    final ByteBuffer buffer = inputVector.getDataBuffer().nioBuffer(incomingIndex * WIDTH_INPUT, WIDTH_INPUT);

    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;

    final HllAccumHolder ah =  this.accumulators[chunkIndex];
    final HllSketch sketch = ah.getAccums()[chunkOffset];

    sketch.update(Memory.wrap(buffer), 0, WIDTH_INPUT);
  } //for
}