Search in sources :

Example 1 with Granularity

use of com.metamx.common.Granularity in project hive by apache.

the class DruidRecordWriter method getSegmentIdentifierAndMaybePush.

/**
   * 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.
   */
private SegmentIdentifier getSegmentIdentifierAndMaybePush(long truncatedTime) {
    final Granularity segmentGranularity = dataSchema.getGranularitySpec().getSegmentGranularity();
    final Interval interval = new Interval(new DateTime(truncatedTime), segmentGranularity.increment(new DateTime(truncatedTime)));
    SegmentIdentifier retVal;
    if (currentOpenSegment == null) {
        retVal = new SegmentIdentifier(dataSchema.getDataSource(), interval, tuningConfig.getVersioningPolicy().getVersion(interval), new LinearShardSpec(0));
        currentOpenSegment = retVal;
        return retVal;
    } else if (currentOpenSegment.getInterval().equals(interval)) {
        retVal = currentOpenSegment;
        int rowCount = appenderator.getRowCount(retVal);
        if (rowCount < maxPartitionSize) {
            return retVal;
        } else {
            retVal = new SegmentIdentifier(dataSchema.getDataSource(), interval, tuningConfig.getVersioningPolicy().getVersion(interval), new LinearShardSpec(currentOpenSegment.getShardSpec().getPartitionNum() + 1));
            pushSegments(Lists.newArrayList(currentOpenSegment));
            LOG.info("Creating new partition for segment {}, partition num {}", retVal.getIdentifierAsString(), retVal.getShardSpec().getPartitionNum());
            currentOpenSegment = retVal;
            return retVal;
        }
    } else {
        retVal = new SegmentIdentifier(dataSchema.getDataSource(), interval, tuningConfig.getVersioningPolicy().getVersion(interval), new LinearShardSpec(0));
        pushSegments(Lists.newArrayList(currentOpenSegment));
        LOG.info("Creating segment {}", retVal.getIdentifierAsString());
        currentOpenSegment = retVal;
        return retVal;
    }
}
Also used : SegmentIdentifier(io.druid.segment.realtime.appenderator.SegmentIdentifier) LinearShardSpec(io.druid.timeline.partition.LinearShardSpec) Granularity(com.metamx.common.Granularity) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval)

Aggregations

Granularity (com.metamx.common.Granularity)1 SegmentIdentifier (io.druid.segment.realtime.appenderator.SegmentIdentifier)1 LinearShardSpec (io.druid.timeline.partition.LinearShardSpec)1 DateTime (org.joda.time.DateTime)1 Interval (org.joda.time.Interval)1