For all of the segments for a partition, create the parent partition, combine the
        children into the parent, and delete the children.
331030
def unify_partitions(self):
        

        partitions = self.collect_segment_partitions()

        # For each group, copy the segment partitions to the parent partitions, then
        # delete the segment partitions.

        with self.progress.start('coalesce', 0, message='Coalescing partition segments') as ps:

            for name, segments in iteritems(partitions):
                ps.add(item_type='partitions', item_count=len(segments),
                       message='Colescing partition {}'.format(name))
                self.unify_partition(name, segments, ps)
292422
function buildSegmentRows(segments) {
		var rowCnt = getRowCnt();
		var segmentRows = [];
		var segmentI;
		var segment;
		var rowI;

		// group segments by row
		for (segmentI=0; segmentI<segments.length; segmentI++) {
			segment = segments[segmentI];
			rowI = segment.row;
			if (segment.element) { // was rendered?
				if (segmentRows[rowI]) {
					// already other segments. append to array
					segmentRows[rowI].push(segment);
				}
				else {
					// first segment in row. create new array
					segmentRows[rowI] = [ segment ];
				}
			}
		}

		// sort each row
		for (rowI=0; rowI<rowCnt; rowI++) {
			segmentRows[rowI] = sortSegmentRow(
				segmentRows[rowI] || [] // guarantee an array, even if no segments
			);
		}

		return segmentRows;
	}
356588
private static void joinPath(StringBuilder path, String parent, String child)
    {
        // Add parent piece, with no trailing slash.
        if ( (parent != null) && (parent.length() > 0) )
        {
            if ( !parent.startsWith(PATH_SEPARATOR) )
            {
                path.append(PATH_SEPARATOR);
            }
            if ( parent.endsWith(PATH_SEPARATOR) )
            {
                path.append(parent.substring(0, parent.length() - 1));
            }
            else
            {
                path.append(parent);
            }
        }

        if ( (child == null) || (child.length() == 0) || (child.equals(PATH_SEPARATOR)) )
        {
            // Special case, empty parent and child
            if ( path.length() == 0 )
            {
                path.append(PATH_SEPARATOR);
            }
            return;
        }

        // Now add the separator between parent and child.
        path.append(PATH_SEPARATOR);

        if ( child.startsWith(PATH_SEPARATOR) )
        {
            child = child.substring(1);
        }

        if ( child.endsWith(PATH_SEPARATOR) )
        {
            child = child.substring(0, child.length() - 1);
        }

        // Finally, add the child.
        path.append(child);
    }
1086313
def delete(path, headers: {}, query: {})
      @parent.delete("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
                     headers: @default_headers.merge(headers), query: query)
    end
1085672
def add_parents(self, parents):
        

        self._parents += [p for p in parents if p not in self._parents]
546724
private synchronized void resetCurrentSegment() {
    JournalSegment<E> lastSegment = getLastSegment();
    if (lastSegment != null) {
      currentSegment = lastSegment;
    } else {
      JournalSegmentDescriptor descriptor = JournalSegmentDescriptor.builder()
          .withId(1)
          .withIndex(1)
          .withMaxSegmentSize(maxSegmentSize)
          .withMaxEntries(maxEntriesPerSegment)
          .build();

      currentSegment = createSegment(descriptor);

      segments.put(1L, currentSegment);
    }
  }
642271
@Override
	public void clearPartitions() {
		// clear the iterators, so the next call to next() will notice
		this.bucketIterator = null;
		this.probeIterator = null;

		for (int i = this.partitionsBeingBuilt.size() - 1; i >= 0; --i) {
			final BinaryHashPartition p = this.partitionsBeingBuilt.get(i);
			try {
				p.clearAllMemory(this.availableMemory);
			} catch (Exception e) {
				LOG.error("Error during partition cleanup.", e);
			}
		}
		this.partitionsBeingBuilt.clear();

		// clear the partitions that are still to be done (that have files on disk)
		for (final BinaryHashPartition p : this.partitionsPending) {
			p.clearAllMemory(this.availableMemory);
		}
	}
1306101
private void deleteGroup(List<Segment> group) {
    // Delete the old segments.
    for (Segment oldSegment : group) {
      oldSegment.close();
      oldSegment.delete();
    }
  }
1132296
@Override
	public void createPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec, CatalogPartition partition, boolean ignoreIfExists)
		throws TableNotExistException, TableNotPartitionedException, PartitionSpecInvalidException, PartitionAlreadyExistsException, CatalogException {

		validatePartitionSpec(tablePath, partitionSpec);

		if (partitionExists(tablePath, partitionSpec)) {
			if (!ignoreIfExists) {
				throw new PartitionAlreadyExistsException(catalogName, tablePath, partitionSpec);
			}
		} else {
			partitions.get(tablePath).put(partitionSpec, partition.copy());
		}
	}
483875
private void compactSegments() {
    // Create a compact segment with a newer version to which to rewrite the segment entries.
    Segment compactSegment = manager.createSegment(SegmentDescriptor.builder()
      .withId(segment.descriptor().id())
      .withVersion(segment.descriptor().version() + 1)
      .withIndex(segment.descriptor().index())
      .withMaxSegmentSize(segment.descriptor().maxSegmentSize())
      .withMaxEntries(segment.descriptor().maxEntries())
      .build());

    compactEntries(segment, compactSegment);

    // Replace the old segment with the compact segment.
    manager.replaceSegments(Collections.singletonList(segment), compactSegment);

    // Update the new segment with offsets that were released during compaction.
    mergeReleasedEntries(segment, compactSegment);

    // Delete the old segment.
    segment.close();
    segment.delete();
  }
1144856
private void compactEntries(Segment segment, Segment compactSegment) {
    for (long i = segment.firstIndex(); i <= segment.lastIndex(); i++) {
      checkEntry(i, segment, compactSegment);
    }
  }
1148123
function process(segments, parent) {
  var last = segments.pop();
  if (last) {
    parent[last] = parent[last] || {};
    process(segments, parent[last]);
  } else {
    parent[true] = true;
  }
}
396048
def partition(self):
        """"""
        step = int(math.ceil(self.num_tasks / float(self.partitions)))
        if self.indices == None:
            slice_ind = list(range(0, self.num_tasks, step))
            for start in slice_ind:
                yield self.__class__(self.partitions, 
                                     list(range(start, start + step)))
        else:
            slice_ind = list(range(0, len(self.indices), step))
            for start in slice_ind:
                if start + step <= len(self.indices):
                    yield self.__class__(self.partitions, 
                                         self.indices[start: start + step])
                else:
                    yield self.__class__(self.partitions, self.indices[start:])
972519
function (theparent) {
            if (this.parent() !== null)
                this.detach();
            var children = theparent.children();
            children.push(this);
            theparent.children(children);
            this.parent(theparent);
        }
1342798
def cleanup(workdir, fileroot, scans=[]):
    

    os.chdir(workdir)

    # merge cands/noise files per scan
    for scan in scans:
        merge_segments(fileroot, scan, cleanup=True, sizelimit=2.)
995055
protected void clearPartitions() {
		for (int i = this.partitionsBeingBuilt.size() - 1; i >= 0; --i) {
			final HashPartition<BT, PT> p = this.partitionsBeingBuilt.get(i);
			try {
				p.clearAllMemory(this.availableMemory);
			} catch (Exception e) {
				LOG.error("Error during partition cleanup.", e);
			}
		}
		this.partitionsBeingBuilt.clear();
	}
356667
def _create_partitions(self, instance, partitions):
        """"""
        for partition in partitions:
            RelationPartition.objects.create(
                relation=instance,
                entity=partition['entity'],
                label=partition.get('label', None),
                position=partition.get('position', None),
            )