@Override public Object deserializeKey(String key, DeserializationContext ctxt) { return DateTimes.of(key); } }
@Override public DateTime getMaxTime() { return DateTimes.of(end); }
@Override public DateTime getTimestamp() { return DateTimes.of(timeStr); }
@Override public DateTime getTimestamp() { return DateTimes.of(timeStr); }
@Override public DateTime getTimestamp() { return DateTimes.of("2013-01-01"); }
@Override public long getTimestampFromEpoch() { return DateTimes.of("2013-01-01").getMillis(); }
private static Stream getStreamOfEvents() { return IntStream.range(0, MAX_ROWS).mapToObj(i -> ImmutableMap.of( TIME_COLUMN, DateTimes.of("2011-01-13T00:00:00.000Z").plusDays(i).getMillis(), DIM_NAME, DIM_VALUE, DIM_FLOAT_NAME, i / 1.6179775280898876 )); }
private Row createRow(String timestamp, Object... vals) { Preconditions.checkArgument(vals.length % 2 == 0); Map<String, Object> theVals = new HashMap<>(); for (int i = 0; i < vals.length; i += 2) { theVals.put(vals[i].toString(), vals[i + 1]); } return new MapBasedRow(DateTimes.of(timestamp), theVals); } }
private static InputRow IR(String dt, String dim1, String dim2, float met) { return new MapBasedInputRow( DateTimes.of(dt).getMillis(), ImmutableList.of("dim1", "dim2"), ImmutableMap.of( "dim1", dim1, "dim2", dim2, "met", met ) ); }
@Test public void testIterableHourSimple() { final DateTime baseTime = DateTimes.of("2011-01-01T09:00:00.000Z"); assertSameInterval( Lists.newArrayList( DateTimes.of("2011-01-01T09:00:00.000Z"), DateTimes.of("2011-01-01T10:00:00.000Z"), DateTimes.of("2011-01-01T11:00:00.000Z") ), Granularities.HOUR.getIterable(new Interval(baseTime, baseTime.plus(Hours.hours(3)))) ); }
@Test public void testRuby() { final Function<Object, DateTime> parser = TimestampParser.createObjectTimestampParser("ruby"); Assert.assertEquals(DateTimes.of("2013-01-16T14:41:47.435Z"), parser.apply("1358347307.435447")); Assert.assertEquals(DateTimes.of("2013-01-16T14:41:47.435Z"), parser.apply(1358347307.435447D)); }
@Test public void testTruncate() { DateTime date = DateTimes.of("2011-03-15T22:42:23.898"); Assert.assertEquals(DateTimes.of("2011-01-01T00:00:00.000"), YEAR.bucketStart(date)); Assert.assertEquals(DateTimes.of("2011-03-01T00:00:00.000"), MONTH.bucketStart(date)); Assert.assertEquals(DateTimes.of("2011-03-14T00:00:00.000"), WEEK.bucketStart(date)); Assert.assertEquals(DateTimes.of("2011-03-15T00:00:00.000"), DAY.bucketStart(date)); Assert.assertEquals(DateTimes.of("2011-03-15T22:00:00.000"), HOUR.bucketStart(date)); Assert.assertEquals(DateTimes.of("2011-03-15T22:42:00.000"), MINUTE.bucketStart(date)); Assert.assertEquals(DateTimes.of("2011-03-15T22:42:23.000"), SECOND.bucketStart(date)); }
@Test public void testMakeTaskId() { Assert.assertEquals( "index_realtime_test_0_2015-01-02T00:00:00.000Z_abcdefgh", RealtimeIndexTask.makeTaskId("test", 0, DateTimes.of("2015-01-02"), "abcdefgh") ); }
@Test public void testIterableAllSimple() { final DateTime baseTime = DateTimes.of("2011-01-01T00:00:00.000Z"); assertSameInterval( Collections.singletonList(baseTime), Granularities.ALL.getIterable(new Interval(baseTime, baseTime.plus(Days.days(3)))) ); }
@Test public void testExtractTimestamp() { TimestampSpec spec = new TimestampSpec("TIMEstamp", "yyyy-MM-dd", null); Assert.assertEquals( DateTimes.of("2014-03-01"), spec.extractTimestamp(ImmutableMap.of("TIMEstamp", "2014-03-01")) ); }
@Test public void testTimeExample() { String utcHour = "function(t) {\nreturn 'Second ' + Math.floor((t % 60000) / 1000);\n}"; final long millis = DateTimes.of("2015-01-02T13:00:59.999Z").getMillis(); Assert.assertEquals("Second 59", new JavaScriptExtractionFn(utcHour, false, JavaScriptConfig.getEnabledInstance()).apply(millis)); }
@Test public void testV1SerializationNullMetrics() throws Exception { final DataSegment segment = DataSegment.builder() .dataSource("foo") .interval(Intervals.of("2012-01-01/2012-01-02")) .version(DateTimes.of("2012-01-01T11:22:33.444Z").toString()) .build(); final DataSegment segment2 = mapper.readValue(mapper.writeValueAsString(segment), DataSegment.class); Assert.assertEquals("empty dimensions", ImmutableList.of(), segment2.getDimensions()); Assert.assertEquals("empty metrics", ImmutableList.of(), segment2.getMetrics()); }
private static IncrementalIndex newIndex(String minTimeStamp, int maxRowCount) { final IncrementalIndexSchema schema = new IncrementalIndexSchema.Builder() .withMinTimestamp(DateTimes.of(minTimeStamp).getMillis()) .withQueryGranularity(Granularities.HOUR) .withMetrics(TestIndex.METRIC_AGGS) .build(); return new IncrementalIndex.Builder() .setIndexSchema(schema) .setMaxRowCount(maxRowCount) .buildOnheap(); }