Exemple #1
0
  public GroupByIdBlock getGroupIds(Page page) {
    int positionCount = page.getPositionCount();

    int groupIdBlockSize = SINGLE_LONG.getFixedSize() * positionCount;
    BlockBuilder blockBuilder =
        new BlockBuilder(
            SINGLE_LONG, groupIdBlockSize, Slices.allocate(groupIdBlockSize).getOutput());

    // open cursors for group blocks
    BlockCursor[] cursors = new BlockCursor[channels.length];
    for (int i = 0; i < channels.length; i++) {
      cursors[i] = page.getBlock(channels[i]).cursor();
    }

    // use cursors in hash strategy to provide value for "current" row
    hashStrategy.setCurrentRow(cursors);

    for (int position = 0; position < positionCount; position++) {
      for (BlockCursor cursor : cursors) {
        checkState(cursor.advanceNextPosition());
      }

      int groupId = pagePositionToGroupId.get(CURRENT_ROW_ADDRESS);
      if (groupId < 0) {
        groupId = addNewGroup(cursors);
      }
      blockBuilder.append(groupId);
    }
    UncompressedBlock block = blockBuilder.build();
    return new GroupByIdBlock(nextGroupId, block);
  }
 private void testIsFull(VariableWidthBlockBuilder blockBuilder) {
   assertTrue(blockBuilder.isEmpty());
   while (!blockBuilder.isFull()) {
     VARCHAR.writeSlice(blockBuilder, Slices.allocate(VARCHAR_VALUE_SIZE));
   }
   assertEquals(blockBuilder.getPositionCount(), EXPECTED_ENTRY_COUNT);
   assertEquals(blockBuilder.isFull(), true);
 }
Exemple #3
0
 @Description("convert ASCII character code to string")
 @ScalarFunction
 @SqlType(VarcharType.class)
 public static Slice chr(@SqlType(BigintType.class) long n) {
   Slice slice = Slices.allocate(1);
   slice.setByte(0, Ints.saturatedCast(n));
   return slice;
 }
Exemple #4
0
    public ChannelBuilder(Type type, int blockSize) {
      checkNotNull(type, "type is null");

      this.type = type;
      this.slice = Slices.allocate(blockSize);
      this.sliceOutput = slice.getOutput();
      this.positionOffsets = new IntArrayList(1024);
    }
 private static Block createMapBlock(int positionCount, Block keyBlock, Block valueBlock) {
   InterleavedBlock interleavedBlock = new InterleavedBlock(new Block[] {keyBlock, valueBlock});
   int[] offsets = new int[positionCount];
   int mapSize = keyBlock.getPositionCount() / positionCount;
   for (int i = 0; i < positionCount; i++) {
     offsets[i] = mapSize * 2 * i;
   }
   return new ArrayBlock(
       interleavedBlock, Slices.wrappedIntArray(offsets), 0, Slices.allocate(positionCount));
 }
Exemple #6
0
 @Description("reverses the given string")
 @ScalarFunction
 @SqlType(VarcharType.class)
 public static Slice reverse(@SqlType(VarcharType.class) Slice slice) {
   Slice reverse = Slices.allocate(slice.length());
   for (int i = 0, j = slice.length() - 1; i < slice.length(); i++, j--) {
     reverse.setByte(j, slice.getByte(i));
   }
   return reverse;
 }
Exemple #7
0
 @Description("concatenates given strings")
 @ScalarFunction
 @SqlType(VarcharType.class)
 public static Slice concat(
     @SqlType(VarcharType.class) Slice str1, @SqlType(VarcharType.class) Slice str2) {
   Slice concat = Slices.allocate(str1.length() + str2.length());
   concat.setBytes(0, str1);
   concat.setBytes(str1.length(), str2);
   return concat;
 }
Exemple #8
0
 @Description("converts all the alphabets in the string to upper case")
 @ScalarFunction
 @SqlType(VarcharType.class)
 public static Slice upper(@SqlType(VarcharType.class) Slice slice) {
   Slice upper = Slices.allocate(slice.length());
   for (int i = 0; i < slice.length(); i++) {
     upper.setByte(i, Ascii.toUpperCase((char) slice.getByte(i)));
   }
   return upper;
 }
  @Override
  public Block copyPositions(List<Integer> positions) {
    int finalLength = positions.stream().mapToInt(this::getLength).sum();
    SliceOutput newSlice = Slices.allocate(finalLength).getOutput();
    int[] newOffsets = new int[positions.size() + 1];
    boolean[] newValueIsNull = new boolean[positions.size()];

    for (int i = 0; i < positions.size(); i++) {
      int position = positions.get(i);
      if (isEntryNull(position)) {
        newValueIsNull[i] = true;
      } else {
        newSlice.appendBytes(
            sliceOutput
                .getUnderlyingSlice()
                .getBytes(getPositionOffset(position), getLength(position)));
      }
      newOffsets[i + 1] = newSlice.size();
    }
    return new VariableWidthBlock(positions.size(), newSlice.slice(), newOffsets, newValueIsNull);
  }
Exemple #10
0
 protected Slice allocate(int size) {
   return Slices.allocate(size);
 }