private void pushSegments(List<SegmentIdWithShardSpec> segmentsToPush) {
    try {
      SegmentsAndMetadata segmentsAndMetadata = appenderator.push(segmentsToPush, committerSupplier.get(), false).get();
      final Set<String> pushedSegmentIdentifierHashSet = new HashSet<>();

      for (DataSegment pushedSegment : segmentsAndMetadata.getSegments()) {
        pushedSegmentIdentifierHashSet.add(SegmentIdWithShardSpec.fromDataSegment(pushedSegment).toString());
        final Path
            segmentDescriptorOutputPath =
            DruidStorageHandlerUtils.makeSegmentDescriptorOutputPath(pushedSegment, segmentsDescriptorDir);
        DruidStorageHandlerUtils.writeSegmentDescriptor(fileSystem, pushedSegment, segmentDescriptorOutputPath);
        LOG.info(String.format("Pushed the segment [%s] and persisted the descriptor located at [%s]",
            pushedSegment,
            segmentDescriptorOutputPath));
      }

      final Set<String>
          toPushSegmentsHashSet =
          segmentsToPush.stream()
              .map(SegmentIdWithShardSpec::toString)
              .collect(Collectors.toCollection(HashSet::new));

      if (!pushedSegmentIdentifierHashSet.equals(toPushSegmentsHashSet)) {
        throw new IllegalStateException(String.format("was asked to publish [%s] but was able to publish only [%s]",
            Joiner.on(", ").join(toPushSegmentsHashSet),
            Joiner.on(", ").join(pushedSegmentIdentifierHashSet)));
      }
      for (SegmentIdWithShardSpec dataSegmentId : segmentsToPush) {
        LOG.info("Dropping segment {}", dataSegmentId.toString());
        appenderator.drop(dataSegmentId).get();
      }

      LOG.info(String.format("Published [%,d] segments.", segmentsToPush.size()));
    } catch (InterruptedException e) {
      LOG.error(String.format("got interrupted, failed to push  [%,d] segments.", segmentsToPush.size()), e);
      Thread.currentThread().interrupt();
    } catch (IOException | ExecutionException e) {
      LOG.error(String.format("Failed to push  [%,d] segments.", segmentsToPush.size()), e);
      Throwables.propagate(e);
    }
  }
This function computes the segment identifier and push the current open segment
The push will occur if max size is reached or the event belongs to the next interval.
Note that this function assumes that timestamps are pseudo sorted.
This function will close and move to the next segment granularity as soon as
an event from the next interval appears. The sorting is done by the previous stage.

@return segmentIdentifier with of the truncatedTime and maybe push the current open segment.
druid-handler/src/java/org/apache/hadoop/hive/druid/io/DruidRecordWriter.java