private static void appendTo(Type type, SliceOutput output, Block block) {
   if (type.getJavaType() == long.class) {
     output.appendLong(type.getLong(block, 0));
   } else if (type.getJavaType() == double.class) {
     output.appendDouble(type.getDouble(block, 0));
   } else if (type.getJavaType() == Slice.class) {
     output.appendBytes(type.getSlice(block, 0));
   } else if (type.getJavaType() == boolean.class) {
     output.appendByte(type.getBoolean(block, 0) ? 1 : 0);
   } else {
     throw new IllegalArgumentException("Unsupported type: " + type.getJavaType().getSimpleName());
   }
 }
  @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);
  }