public static StorageSegment merge(
            boolean grouping,
            SegmentSchema schema,
            SegmentMode mode,
            List<String> dims,
            List<Metric> metrics,
            List<SegmentFd> fds,
            Path path,
            String name) throws IOException {
        DPSegment mergeSegment = null;
        List<StorageSegment> segments = new ArrayList<>();
        try {
            for (SegmentFd fd : fds) {
                segments.add((StorageSegment) (fd.open()));
            }
            int version = fds.size() == 0 ? Version.LATEST_ID : segments.get(0).version();
            mergeSegment = DPSegment.open(
                    version,
                    mode,
                    path,
                    name,
                    schema,
                    OpenOption.Overwrite);
            mergeSegment.update();

            if (dims == null || dims.size() == 0) {
                // No need to sort, use the fast way - copy bytes directly.
                mergeSegment.merge(segments);
            } else {
                UTF8Row.Creator creator = new UTF8Row.Creator(
                        grouping,
                        schema.columns,
                        dims,
                        metrics,
                        null,
                        null,
                        EventIgnoreStrategy.NO_IGNORE);
                sortedMerge(creator, mergeSegment, segments);
            }

            mergeSegment.seal();
            return mergeSegment;
        } catch (Exception e) {
            IOUtils.closeQuietly(mergeSegment);
            throw e;
        } finally {
            for (Segment segment : segments) {
                Try.on(segment::close, logger);
            }
        }
    }
Merge a list of dumped realtime segments.
indexr-segment/src/main/java/io/indexr/segment/rt/RTSMerge.java