@Override public DateTimeFormatter getFormatter(Formatter type) { GranularityType granularityType = GranularityType.fromPeriod(period); switch (type) { case DEFAULT: return DateTimeFormat.forPattern(granularityType.getDefaultFormat()); case HIVE: return DateTimeFormat.forPattern(granularityType.getHiveFormat()); case LOWER_DEFAULT: return DateTimeFormat.forPattern(granularityType.getLowerDefaultFormat()); default: throw new IAE("There is no format for type %s", type); } }
@Override public void serialize(JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { // Retain the same behavior as before #3850. // i.e. when Granularity class was an enum. if (GranularityType.isStandard(this)) { jsonGenerator.writeString(GranularityType.fromPeriod(getPeriod()).toString()); } else { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("type", "period"); jsonGenerator.writeObjectField("period", getPeriod()); jsonGenerator.writeObjectField("timeZone", getTimeZone()); jsonGenerator.writeObjectField("origin", getOrigin()); jsonGenerator.writeEndObject(); } }
@Override public DateTime toDate(String filePath, Formatter formatter) { Integer[] vals = getDateValues(filePath, formatter); GranularityType granularityType = GranularityType.fromPeriod(period); DateTime date = granularityType.getDateTime(vals); if (date != null) { return bucketStart(date); } return null; }
dimensionsSpec, metricsSpec, GranularityType.fromPeriod(interval.toPeriod()).getDefaultGranularity(), jsonMapper );
@Test public void testCustomNestedPeriodFail() { try { Period p = Period.years(6).withMonths(3).withSeconds(23); GranularityType.fromPeriod(p); Assert.fail("Complicated period creation should fail b/c of unsupported granularity type."); } catch (IAE e) { // pass } }
@Override public DateTimeFormatter getFormatter(Formatter type) { GranularityType granularityType = GranularityType.fromPeriod(period); switch (type) { case DEFAULT: return DateTimeFormat.forPattern(granularityType.getDefaultFormat()); case HIVE: return DateTimeFormat.forPattern(granularityType.getHiveFormat()); case LOWER_DEFAULT: return DateTimeFormat.forPattern(granularityType.getLowerDefaultFormat()); default: throw new IAE("There is no format for type %s", type); } }
@Override public void serialize( JsonGenerator jsonGenerator, SerializerProvider serializerProvider ) throws IOException, JsonProcessingException { // Retain the same behavior as before #3850. // i.e. when Granularity class was an enum. if (GranularityType.isStandard(this)) { jsonGenerator.writeString(GranularityType.fromPeriod(getPeriod()).toString()); } else { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("type", "period"); jsonGenerator.writeObjectField("period", getPeriod()); jsonGenerator.writeObjectField("timeZone", getTimeZone()); jsonGenerator.writeObjectField("origin", getOrigin()); jsonGenerator.writeEndObject(); } }
@Override public DateTime toDate(String filePath, Formatter formatter) { Integer[] vals = getDateValues(filePath, formatter); GranularityType granularityType = GranularityType.fromPeriod(period); DateTime date = granularityType.getDateTime(vals); if (date != null) { return bucketStart(date); } return null; }