Example usage for org.joda.time Interval getEnd

List of usage examples for org.joda.time Interval getEnd

Introduction

In this page you can find the example usage for org.joda.time Interval getEnd.

Prototype

public DateTime getEnd() 

Source Link

Document

Gets the end of this time interval, which is exclusive, as a DateTime.

Usage

From source file:com.metamx.druid.index.v1.IndexStorageAdapter.java

License:Open Source License

private Pair<Integer, Integer> computeTimeStartEnd(Interval interval) {
    DateTime actualIntervalStart = index.dataInterval.getStart();
    DateTime actualIntervalEnd = index.dataInterval.getEnd();

    if (index.dataInterval.contains(interval.getStart())) {
        actualIntervalStart = interval.getStart();
    }/*from  ww  w.  j av a 2  s  .  c  o  m*/

    if (index.dataInterval.contains(interval.getEnd())) {
        actualIntervalEnd = interval.getEnd();
    }

    return computeOffsets(actualIntervalStart.getMillis(), 0, actualIntervalEnd.getMillis(),
            index.timeOffsets.length);
}

From source file:com.metamx.druid.index.v1.MMappedIndexStorageAdapter.java

License:Open Source License

@Override
public Iterable<Cursor> makeCursors(Filter filter, Interval interval, QueryGranularity gran) {
    Interval actualInterval = interval;
    if (!actualInterval.overlaps(index.dataInterval)) {
        return ImmutableList.of();
    }//from  www . j ava  2s  . c  o m

    if (actualInterval.getStart().isBefore(index.dataInterval.getStart())) {
        actualInterval = actualInterval.withStart(index.dataInterval.getStart());
    }
    if (actualInterval.getEnd().isAfter(index.dataInterval.getEnd())) {
        actualInterval = actualInterval.withEnd(index.dataInterval.getEnd());
    }

    final Iterable<Cursor> iterable;
    if (filter == null) {
        iterable = new NoFilterCursorIterable(index, actualInterval, gran);
    } else {
        Offset offset = new ConciseOffset(filter.goConcise(new MMappedBitmapIndexSelector(index)));

        iterable = new CursorIterable(index, actualInterval, gran, offset);
    }

    return FunctionalIterable.create(iterable).keep(Functions.<Cursor>identity());
}

From source file:com.metamx.druid.index.v1.QueryableIndexStorageAdapter.java

License:Open Source License

@Override
public Iterable<Cursor> makeCursors(Filter filter, Interval interval, QueryGranularity gran) {
    Interval actualInterval = interval;
    final Interval dataInterval = getInterval();
    if (!actualInterval.overlaps(dataInterval)) {
        return ImmutableList.of();
    }//from w ww  .ja va2s  . c  o  m

    if (actualInterval.getStart().isBefore(dataInterval.getStart())) {
        actualInterval = actualInterval.withStart(dataInterval.getStart());
    }
    if (actualInterval.getEnd().isAfter(dataInterval.getEnd())) {
        actualInterval = actualInterval.withEnd(dataInterval.getEnd());
    }

    final Iterable<Cursor> iterable;
    if (filter == null) {
        iterable = new NoFilterCursorIterable(index, actualInterval, gran);
    } else {
        Offset offset = new ConciseOffset(filter.goConcise(new MMappedBitmapIndexSelector(index)));

        iterable = new CursorIterable(index, actualInterval, gran, offset);
    }

    return FunctionalIterable.create(iterable).keep(Functions.<Cursor>identity());
}

From source file:com.metamx.druid.indexer.HadoopDruidIndexerConfig.java

License:Open Source License

public Path makeSegmentPartitionInfoPath(Bucket bucket) {
    final Interval bucketInterval = getGranularitySpec().bucketInterval(bucket.time).get();

    return new Path(String.format("%s/%s_%s/partitions.json", makeIntermediatePath(),
            ISODateTimeFormat.basicDateTime().print(bucketInterval.getStart()),
            ISODateTimeFormat.basicDateTime().print(bucketInterval.getEnd())));
}

From source file:com.metamx.druid.indexer.HadoopDruidIndexerConfig.java

License:Open Source License

public Path makeSegmentOutputPath(Bucket bucket) {
    final Interval bucketInterval = getGranularitySpec().bucketInterval(bucket.time).get();

    return new Path(String.format("%s/%s_%s/%s/%s", getSegmentOutputDir(), bucketInterval.getStart().toString(),
            bucketInterval.getEnd().toString(), getVersion().toString(), bucket.partitionNum));
}

From source file:com.metamx.druid.indexing.common.task.DeleteTask.java

License:Open Source License

@JsonCreator
public DeleteTask(@JsonProperty("id") String id, @JsonProperty("dataSource") String dataSource,
        @JsonProperty("interval") Interval interval) {
    super(id != null ? id
            : String.format("delete_%s_%s_%s_%s", dataSource, interval.getStart(), interval.getEnd(),
                    new DateTime().toString()),
            dataSource, Preconditions.checkNotNull(interval, "interval"));
}

From source file:com.metamx.druid.indexing.common.task.IndexDeterminePartitionsTask.java

License:Open Source License

@JsonCreator
public IndexDeterminePartitionsTask(@JsonProperty("id") String id, @JsonProperty("groupId") String groupId,
        @JsonProperty("interval") Interval interval, @JsonProperty("firehose") FirehoseFactory firehoseFactory,
        @JsonProperty("schema") Schema schema, @JsonProperty("targetPartitionSize") long targetPartitionSize,
        @JsonProperty("rowFlushBoundary") int rowFlushBoundary) {
    super(id != null ? id : makeTaskId(groupId, interval.getStart(), interval.getEnd()), groupId,
            schema.getDataSource(), Preconditions.checkNotNull(interval, "interval"));

    this.firehoseFactory = firehoseFactory;
    this.schema = schema;
    this.targetPartitionSize = targetPartitionSize;
    this.rowFlushBoundary = rowFlushBoundary;
}

From source file:com.metamx.druid.indexing.common.task.IndexGeneratorTask.java

License:Open Source License

@JsonCreator
public IndexGeneratorTask(@JsonProperty("id") String id, @JsonProperty("groupId") String groupId,
        @JsonProperty("interval") Interval interval, @JsonProperty("firehose") FirehoseFactory firehoseFactory,
        @JsonProperty("schema") Schema schema, @JsonProperty("rowFlushBoundary") int rowFlushBoundary) {
    super(id != null ? id
            : String.format("%s_generator_%s_%s_%s", groupId, interval.getStart(), interval.getEnd(),
                    schema.getShardSpec().getPartitionNum()),
            groupId, schema.getDataSource(), Preconditions.checkNotNull(interval, "interval"));

    this.firehoseFactory = firehoseFactory;
    this.schema = schema;
    this.rowFlushBoundary = rowFlushBoundary;
}

From source file:com.metamx.druid.indexing.common.task.IndexGeneratorTask.java

License:Open Source License

@Override
public TaskStatus run(final TaskToolbox toolbox) throws Exception {
    // We should have a lock from before we started running
    final TaskLock myLock = Iterables
            .getOnlyElement(toolbox.getTaskActionClient().submit(new LockListAction()));

    // We know this exists
    final Interval interval = getImplicitLockInterval().get();

    // Set up temporary directory for indexing
    final File tmpDir = new File(toolbox.getTaskWorkDir(),
            String.format("%s_%s_%s_%s_%s", this.getDataSource(), interval.getStart(), interval.getEnd(),
                    myLock.getVersion(), schema.getShardSpec().getPartitionNum()));

    // We need to track published segments.
    final List<DataSegment> pushedSegments = new CopyOnWriteArrayList<DataSegment>();
    final DataSegmentPusher wrappedDataSegmentPusher = new DataSegmentPusher() {
        @Override/*from www.  j  a v  a2 s. com*/
        public DataSegment push(File file, DataSegment segment) throws IOException {
            final DataSegment pushedSegment = toolbox.getSegmentPusher().push(file, segment);
            pushedSegments.add(pushedSegment);
            return pushedSegment;
        }
    };

    // Create firehose + plumber
    final FireDepartmentMetrics metrics = new FireDepartmentMetrics();
    final Firehose firehose = firehoseFactory.connect();
    final Plumber plumber = new YeOldePlumberSchool(interval, myLock.getVersion(), wrappedDataSegmentPusher,
            tmpDir).findPlumber(schema, metrics);

    // rowFlushBoundary for this job
    final int myRowFlushBoundary = this.rowFlushBoundary > 0 ? rowFlushBoundary
            : toolbox.getConfig().getDefaultRowFlushBoundary();

    try {
        while (firehose.hasMore()) {
            final InputRow inputRow = firehose.nextRow();

            if (shouldIndex(inputRow)) {
                final Sink sink = plumber.getSink(inputRow.getTimestampFromEpoch());
                if (sink == null) {
                    throw new NullPointerException(
                            String.format("Was expecting non-null sink for timestamp[%s]",
                                    new DateTime(inputRow.getTimestampFromEpoch())));
                }

                int numRows = sink.add(inputRow);
                metrics.incrementProcessed();

                if (numRows >= myRowFlushBoundary) {
                    plumber.persist(firehose.commit());
                }
            } else {
                metrics.incrementThrownAway();
            }
        }
    } finally {
        firehose.close();
    }

    plumber.persist(firehose.commit());
    plumber.finishJob();

    // Output metrics
    log.info("Task[%s] took in %,d rows (%,d processed, %,d unparseable, %,d thrown away) and output %,d rows",
            getId(), metrics.processed() + metrics.unparseable() + metrics.thrownAway(), metrics.processed(),
            metrics.unparseable(), metrics.thrownAway(), metrics.rowOutput());

    // Request segment pushes
    toolbox.getTaskActionClient().submit(new SegmentInsertAction(ImmutableSet.copyOf(pushedSegments)));

    // Done
    return TaskStatus.success(getId());
}

From source file:com.metamx.druid.indexing.common.task.KillTask.java

License:Open Source License

@JsonCreator
public KillTask(@JsonProperty("id") String id, @JsonProperty("dataSource") String dataSource,
        @JsonProperty("interval") Interval interval) {
    super(id != null ? id
            : String.format("kill_%s_%s_%s_%s", dataSource, interval.getStart(), interval.getEnd(),
                    new DateTime().toString()),
            dataSource, interval);/*  ww  w .  jav a 2 s .  com*/
}