Java Code Examples for io.netty.util.internal.PlatformDependent#getInt()

The following examples show how to use io.netty.util.internal.PlatformDependent#getInt() . 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: 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 2
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 * 4;
  final long incomaxgBit = getInput().getValidityBufferAddress();
  final long incomaxgValue =  getInput().getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;

  int incomaxgIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxMemAddr; ordinalAddr += 4, incomaxgIndex++){
    final int newVal = PlatformDependent.getInt(incomaxgValue + (incomaxgIndex * WIDTH));
    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) * 4;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomaxgBit + ((incomaxgIndex >>> 3))) >>> (incomaxgIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putInt(maxAddr, max(PlatformDependent.getInt(maxAddr), newVal, bitVal));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 3
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 4
Source File: LBlockHashTable.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static final boolean variableKeyEquals(
  final long keyVarAddr,
  final long tableVarAddr,
  final int keyVarLength
) {
  final int tableVarLength = PlatformDependent.getInt(tableVarAddr);
  return keyVarLength == tableVarLength && memEqual(keyVarAddr + VAR_LENGTH_SIZE, tableVarAddr + VAR_LENGTH_SIZE, keyVarLength);
}
 
Example 5
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 6
Source File: ConditionalFieldBufferCopier6.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long offsetAddr, int count) {
  targetAlt.allocateNew(count);
  final long max = offsetAddr + count * BUILD_RECORD_LINK_SIZE;
  final long[] srcAddrs = this.srcAddrs;
  long dstAddr = target.getDataBufferAddress();
  for(long addr = offsetAddr; addr < max; addr += BUILD_RECORD_LINK_SIZE, dstAddr += SIZE){
    final int batchIndex = PlatformDependent.getInt(addr);
    if(batchIndex != SKIP){
      final int batchOffset = Short.toUnsignedInt(PlatformDependent.getShort(addr + 4));
      final long srcAddr = srcAddrs[batchIndex] + batchOffset * SIZE;
      PlatformDependent.putLong(dstAddr, PlatformDependent.getLong(srcAddr));
    }
  }
}
 
Example 7
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 8
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 9
Source File: FieldBufferCopier6.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long offsetAddr, int count) {
  if(allocateAsFixed){
    targetAlt.allocateNew(count);
  }
  final long[] srcAddr = this.srcAddrs;
  final long dstAddr;
  switch (bufferOrdinal) {
    case NULL_BUFFER_ORDINAL:
      dstAddr = target.getValidityBufferAddress();
      break;
    case VALUE_BUFFER_ORDINAL:
      dstAddr = target.getDataBufferAddress();
      break;
    default:
      throw new UnsupportedOperationException("unexpected buffer offset");
  }

  final long maxAddr = offsetAddr + count * BUILD_RECORD_LINK_SIZE;
  int targetIndex = 0;
  for(; offsetAddr < maxAddr; offsetAddr += BUILD_RECORD_LINK_SIZE, targetIndex++){
    final int batchIndex = PlatformDependent.getInt(offsetAddr);
    final int batchOffset = Short.toUnsignedInt(PlatformDependent.getShort(offsetAddr + 4));
    final int byteValue = PlatformDependent.getByte(srcAddr[batchIndex] + (batchOffset >>> 3));
    final int bitVal = ((byteValue >>> (batchOffset & 7)) & 1) << (targetIndex & 7);
    final long addr = dstAddr + (targetIndex >>> 3);
    PlatformDependent.putByte(addr, (byte) (PlatformDependent.getByte(addr) | bitVal));
  }
}
 
Example 10
Source File: UnSafeTuple.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public char[] getUnicodeChars(int fieldId) {
  long pos = getFieldAddr(fieldId);
  int len = PlatformDependent.getInt(pos);
  pos += SizeOf.SIZE_OF_INT;

  byte [] bytes = new byte[len];
  PlatformDependent.copyMemory(pos, bytes, 0, len);
  return StringUtils.convertBytesToChars(bytes, Charset.forName("UTF-8"));
}
 
Example 11
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 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 double newVal = Double.longBitsToDouble(PlatformDependent.getLong(incomingValue + (incomingIndex * WIDTH_INPUT)));
    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, bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 12
Source File: QBlockHashTable.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static final boolean variableKeyEquals(
    final long keyVarAddr,
    final long tableVarAddr,
    final int keyVarLength
    ) {
  final int tableVarLength = PlatformDependent.getInt(tableVarAddr);
  return keyVarLength == tableVarLength && memEqual(keyVarAddr + VAR_LENGTH_SIZE, tableVarAddr + VAR_LENGTH_SIZE, keyVarLength);
}
 
Example 13
Source File: FieldBufferCopier4.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long sv4Addr, int count) {
  final Reallocator realloc = this.realloc;

  final long maxSV4 = sv4Addr + count * STEP_SIZE;
  final long srcOffsetAddrs[] = this.srcOffsetAddrs;
  final long srcDataAddrs[] = this.srcDataAddrs;

  targetAlt.allocateNew(AVG_VAR_WIDTH * count, count);
  long dstOffsetAddr = target.getOffsetBufferAddress() + 4;
  long initDataAddr = realloc.addr();
  long curDataAddr = realloc.addr();
  long maxDataAddr = realloc.max();
  int lastOffset = 0;

  for(; sv4Addr < maxSV4; sv4Addr += STEP_SIZE, dstOffsetAddr += 4){
    final int batchNOFF = PlatformDependent.getInt(sv4Addr);
    final int batchNumber =  batchNOFF >>> BATCH_BITS;
    final int batchOffset = batchNOFF & MAX_BATCH;

    final long startAndEnd = PlatformDependent.getLong(srcOffsetAddrs[batchNumber] + batchOffset * 4);
    final int firstOffset = (int) startAndEnd;
    final int secondOffset = (int) (startAndEnd >> 32);
    final int len = secondOffset - firstOffset;
    if(curDataAddr + len > maxDataAddr){
      initDataAddr = realloc.ensure(lastOffset + len);
      curDataAddr = initDataAddr + lastOffset;
      maxDataAddr = realloc.max();
    }

    lastOffset += len;
    PlatformDependent.putInt(dstOffsetAddr, lastOffset);
    com.dremio.sabot.op.common.ht2.Copier.copy(srcDataAddrs[batchNumber] + firstOffset, curDataAddr, len);
    curDataAddr += len;
  }

  realloc.setCount(count);
}
 
Example 14
Source File: QBlockHashTable.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static final boolean memEqual(final long laddr, final long raddr, int len) {
  int n = len;
  long lPos = laddr;
  long rPos = raddr;

  while (n > 7) {
    long leftLong = PlatformDependent.getLong(lPos);
    long rightLong = PlatformDependent.getLong(rPos);
    if (leftLong != rightLong) {
      return false;
    }
    lPos += 8;
    rPos += 8;
    n -= 8;
  }
  while (n > 3) {
    int leftInt = PlatformDependent.getInt(lPos);
    int rightInt = PlatformDependent.getInt(rPos);
    if (leftInt != rightInt) {
      return false;
    }
    lPos += 4;
    rPos += 4;
    n -= 4;
  }
  while (n-- != 0) {
    byte leftByte = PlatformDependent.getByte(lPos);
    byte rightByte = PlatformDependent.getByte(rPos);
    if (leftByte != rightByte) {
      return false;
    }
    lPos++;
    rPos++;
  }
  return true;
}
 
Example 15
Source File: MinAccumulatorsNoSpill.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;

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    if (bitVal == 0) {
      continue;
    }
    /* get the corresponding data from input vector -- source data for accumulation */
    long addressOfInput = incomingValue + (incomingIndex * WIDTH_INPUT);
    long newValLow = PlatformDependent.getLong(addressOfInput);
    long newValHigh = PlatformDependent.getLong(addressOfInput + DecimalUtils.LENGTH_OF_LONG);
    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 bitUpdateVal = bitVal << (chunkOffset & 31);
    /* Get current value and compare */
    long curValLow = PlatformDependent.getLong(minAddr);
    long curValHigh = PlatformDependent.getLong(minAddr + DecimalUtils.LENGTH_OF_LONG);
    int compare = DecimalUtils.compareDecimalsAsTwoLongs(newValHigh, newValLow, curValHigh, curValLow);

    if (compare < 0) {
      /* store the accumulated values(new min or existing) at the target location of accumulation vector */
      PlatformDependent.putLong(minAddr, newValLow);
      PlatformDependent.putLong(minAddr + DecimalUtils.LENGTH_OF_LONG, newValHigh);
      PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
    }
  }
}
 
Example 16
Source File: HashJoinOperator.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private void setCurrentIndex(final int hashTableIndex, final int buildBatch, final int incomingRecordIndex) throws SchemaChangeException {

    if (hashTableIndex > maxHashTableIndex) {
      maxHashTableIndex = hashTableIndex;
    }

    /* set the current record batch index and the index
     * within the batch at the specified keyIndex. The keyIndex
     * denotes the global index where the key for this record is
     * stored in the hash table
     */
    int hashTableBatch  = hashTableIndex / HashTable.BATCH_SIZE;
    int hashTableOffset = hashTableIndex % HashTable.BATCH_SIZE;

    final ArrowBuf startIndex = startIndices.get(hashTableBatch);
    final long startIndexMemStart = startIndex.memoryAddress() + hashTableOffset * BUILD_RECORD_LINK_SIZE;

    // If head of the list is empty, insert current index at this position
    final int linkBatch = PlatformDependent.getInt(startIndexMemStart);
    if (linkBatch == INDEX_EMPTY) {
      PlatformDependent.putInt(startIndexMemStart, buildBatch);
      PlatformDependent.putShort(startIndexMemStart + 4, (short) incomingRecordIndex);
    } else {
        /* Head of this list is not empty, if the first link
         * is empty insert there
         */
      hashTableBatch = linkBatch;
      hashTableOffset = Short.toUnsignedInt(PlatformDependent.getShort(startIndexMemStart + 4));

      final ArrowBuf firstLink = buildInfoList.get(hashTableBatch).getLinks();
      final long firstLinkMemStart = firstLink.memoryAddress() + hashTableOffset * BUILD_RECORD_LINK_SIZE;

      final int firstLinkBatch = PlatformDependent.getInt(firstLinkMemStart);

      if (firstLinkBatch == INDEX_EMPTY) {
        PlatformDependent.putInt(firstLinkMemStart, buildBatch);
        PlatformDependent.putShort(firstLinkMemStart + 4, (short) incomingRecordIndex);
      } else {
          /* Insert the current value as the first link and
           * make the current first link as its next
           */
        final int firstLinkOffset = Short.toUnsignedInt(PlatformDependent.getShort(firstLinkMemStart + 4));

        final ArrowBuf nextLink = buildInfoList.get(buildBatch).getLinks();
        final long nextLinkMemStart = nextLink.memoryAddress() + incomingRecordIndex * BUILD_RECORD_LINK_SIZE;

        PlatformDependent.putInt(nextLinkMemStart, firstLinkBatch);
        PlatformDependent.putShort(nextLinkMemStart + 4, (short) firstLinkOffset);

        // As the existing (batch, offset) pair is moved out of firstLink into nextLink,
        // now put the new (batch, offset) in the firstLink
        PlatformDependent.putInt(firstLinkMemStart, buildBatch);
        PlatformDependent.putShort(firstLinkMemStart + 4, (short) incomingRecordIndex);
      }
    }
  }
 
Example 17
Source File: NdvAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void accumulate(final long memoryAddr, final int count) {
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long numWords = (count + (BITS_PER_LONG-1)) >>> BITS_PER_LONG_SHIFT; // rounded up number of words that cover 'count' bits
  final long maxInputAddr = incomingValue + numWords * WIDTH_LONG;
  final long maxOrdinalAddr = memoryAddr + count * WIDTH_ORDINAL;

  // Like every accumulator, the code below essentially implements:
  //   accumulators[ordinals[i]] += inputs[i]
  // with the only complication that both accumulators and inputs are bits.
  // There's nothing we can do about the locality of the accumulators, but inputs can be processed a word at a time.
  // Algorithm:
  // - get 64 bits worth of inputs, until all inputs exhausted. For each long:
  //   - find the accumulator word it pertains to
  //   - read/update/write the accumulator bit
  // In the code below:
  // - input* refers to the data values in the incoming batch
  // - ordinal* refers to the temporary table that hashAgg passes in, identifying which hash table entry each input matched to
  for (long inputAddr = incomingValue, inputBitAddr = incomingBit, batchCount = 0;
       inputAddr < maxInputAddr;
       inputAddr += WIDTH_LONG, inputBitAddr += WIDTH_LONG, batchCount++) {
    final long inputBatch = PlatformDependent.getLong(inputAddr);
    final long inputBits = PlatformDependent.getLong(inputBitAddr);
    long ordinalAddr = memoryAddr + (batchCount << BITS_PER_LONG_SHIFT);

    for (long bitNum = 0; bitNum < BITS_PER_LONG && ordinalAddr < maxOrdinalAddr; bitNum++, ordinalAddr += WIDTH_ORDINAL) {
      final int tableIndex = PlatformDependent.getInt(ordinalAddr);
      int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
      int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;

      final int inputBitVal = (int)((inputBits >>> bitNum) & 0x01);
      final int inputVal = (int)((inputBatch >>> bitNum) & 0x01);
      final int minBitUpdateVal = inputBitVal << (chunkOffset & 31);

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

  }
}
 
Example 18
Source File: VectorizedHashAggPartitionSerializable.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private int getLEIntFromByteArray(byte[] array, int index) {
  return PlatformDependent.getInt(array, index);
}
 
Example 19
Source File: UnsafeDirectSwappedByteBuf.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
protected int _getInt(AbstractByteBuf wrapped, int index) {
    return PlatformDependent.getInt(addr(wrapped, index));
}
 
Example 20
Source File: VectorizedHashJoinOperator.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private void setLinks(long indexAddr, final int buildBatch, final int records){
  for(int incomingRecordIndex = 0; incomingRecordIndex < records; incomingRecordIndex++, indexAddr+=4){

    final int hashTableIndex = PlatformDependent.getInt(indexAddr);

    if(hashTableIndex == -1){
      continue;
    }

    if (hashTableIndex > maxHashTableIndex) {
      maxHashTableIndex = hashTableIndex;
    }
    /* Use the global index returned by the hash table, to store
     * the current record index and batch index. This will be used
     * later when we probe and find a match.
     */


    /* set the current record batch index and the index
     * within the batch at the specified keyIndex. The keyIndex
     * denotes the global index where the key for this record is
     * stored in the hash table
     */
    int hashTableBatch  = hashTableIndex >>> 16;
    int hashTableOffset = hashTableIndex & BATCH_MASK;

    ArrowBuf startIndex;
    try {
      startIndex = startIndices.get(hashTableBatch);
    } catch (IndexOutOfBoundsException e){
      UserException.Builder b = UserException.functionError()
        .message("Index out of bounds in VectorizedHashJoin. Index = %d, size = %d", hashTableBatch, startIndices.size())
        .addContext("incomingRecordIndex=%d, hashTableIndex=%d", incomingRecordIndex, hashTableIndex);
      if (debugInsertion) {
        b.addContext(table.traceReport());
      }
      throw b.build(logger);
    }
    final long startIndexMemStart = startIndex.memoryAddress() + hashTableOffset * HashTable.BUILD_RECORD_LINK_SIZE;

    // If head of the list is empty, insert current index at this position
    final int linkBatch = PlatformDependent.getInt(startIndexMemStart);
    if (linkBatch == INDEX_EMPTY) {
      PlatformDependent.putInt(startIndexMemStart, buildBatch);
      PlatformDependent.putShort(startIndexMemStart + 4, (short) incomingRecordIndex);
    } else {
      /* Head of this list is not empty, if the first link
       * is empty insert there
       */
      hashTableBatch = linkBatch;
      hashTableOffset = Short.toUnsignedInt(PlatformDependent.getShort(startIndexMemStart + 4));

      final ArrowBuf firstLink = buildInfoList.get(hashTableBatch).getLinks();
      final long firstLinkMemStart = firstLink.memoryAddress() + hashTableOffset * HashTable.BUILD_RECORD_LINK_SIZE;

      final int firstLinkBatch = PlatformDependent.getInt(firstLinkMemStart);

      if (firstLinkBatch == INDEX_EMPTY) {
        PlatformDependent.putInt(firstLinkMemStart, buildBatch);
        PlatformDependent.putShort(firstLinkMemStart + 4, (short) incomingRecordIndex);
      } else {
        /* Insert the current value as the first link and
         * make the current first link as its next
         */
        final int firstLinkOffset = Short.toUnsignedInt(PlatformDependent.getShort(firstLinkMemStart + 4));

        final ArrowBuf nextLink = buildInfoList.get(buildBatch).getLinks();
        final long nextLinkMemStart = nextLink.memoryAddress() + incomingRecordIndex * HashTable.BUILD_RECORD_LINK_SIZE;

        PlatformDependent.putInt(nextLinkMemStart, firstLinkBatch);
        PlatformDependent.putShort(nextLinkMemStart + 4, (short) firstLinkOffset);

        // As the existing (batch, offset) pair is moved out of firstLink into nextLink,
        // now put the new (batch, offset) in the firstLink
        PlatformDependent.putInt(firstLinkMemStart, buildBatch);
        PlatformDependent.putShort(firstLinkMemStart + 4, (short) incomingRecordIndex);
      }
    }
  }
}