Exemple #1
0
  private int addNewGroup(BlockCursor... row) {
    int pageIndex = allPages.size() - 1;
    if (!activePage.append(row)) {
      // record the active page memory size
      completedPagesMemorySize += activePage.getMemorySize();

      activePage = new GroupByPageBuilder(types);
      if (!activePage.append(row)) {
        if (!memoryManager.canUse(getEstimatedSize() + GroupByPageBuilder.memoryRequiredFor(row))) {
          throw new PrestoException(
              StandardErrorCode.EXCEEDED_MEMORY_LIMIT.toErrorCode(),
              "Not enough memory to build group by hash");
        }
        activePage = new GroupByPageBuilder(types, row);
        checkState(activePage.append(row), "Could not add row to empty page builder");
      }
      allPages.add(activePage);
      pageIndex++;
    }

    // record group id in hash
    int groupId = nextGroupId++;
    long address = encodeSyntheticAddress(pageIndex, activePage.getPositionCount() - 1);
    pagePositionToGroupId.put(address, groupId);

    return groupId;
  }
Exemple #2
0
 public long getEstimatedSize() {
   return completedPagesMemorySize
       + activePage.getMemorySize()
       + pagePositionToGroupId.getEstimatedSize();
 }
Exemple #3
0
 public void appendValuesTo(long pagePosition, BlockBuilder[] builders) {
   GroupByPageBuilder page = allPages.get(decodeSliceIndex(pagePosition));
   page.appendValuesTo(decodePosition(pagePosition), builders);
 }