mirror of
https://github.com/apache/druid.git
synced 2025-02-25 20:48:05 +00:00
Fix "quarter" granularity serialization. (#4316)
This commit is contained in:
parent
9283807ad7
commit
2bd4c0930f
@ -201,7 +201,7 @@ public enum GranularityType
|
||||
case 0:
|
||||
return GranularityType.YEAR;
|
||||
case 1:
|
||||
if (vals[index] == 4) {
|
||||
if (vals[index] == 3) {
|
||||
return GranularityType.QUARTER;
|
||||
}
|
||||
else if (vals[index] == 1) {
|
||||
|
@ -28,6 +28,7 @@ import io.druid.jackson.DefaultObjectMapper;
|
||||
import io.druid.java.util.common.granularity.DurationGranularity;
|
||||
import io.druid.java.util.common.granularity.Granularities;
|
||||
import io.druid.java.util.common.granularity.Granularity;
|
||||
import io.druid.java.util.common.granularity.GranularityType;
|
||||
import io.druid.java.util.common.granularity.PeriodGranularity;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
@ -104,7 +105,7 @@ public class QueryGranularityTest
|
||||
new DateTime("2011-01-01T09:45:00.000Z"),
|
||||
new DateTime("2011-01-01T10:00:00.000Z")
|
||||
),
|
||||
Granularities.FIFTEEN_MINUTE.getIterable(
|
||||
Granularities.FIFTEEN_MINUTE.getIterable(
|
||||
new Interval(
|
||||
baseTime.getMillis(), baseTime.plus(Minutes.minutes(45)).getMillis()
|
||||
))
|
||||
@ -123,7 +124,10 @@ public class QueryGranularityTest
|
||||
new DateTime("2011-01-01T10:00:00.000Z"),
|
||||
new DateTime("2011-01-01T10:15:00.000Z")
|
||||
),
|
||||
Granularities.FIFTEEN_MINUTE.getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Minutes.minutes(45)).getMillis()))
|
||||
Granularities.FIFTEEN_MINUTE.getIterable(new Interval(
|
||||
baseTime.getMillis(),
|
||||
baseTime.plus(Minutes.minutes(45)).getMillis()
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@ -348,11 +352,11 @@ public class QueryGranularityTest
|
||||
new DateTime("2012-11-04T03:00:00.000-08:00")
|
||||
),
|
||||
Lists.newArrayList(
|
||||
hour.bucketStart(new DateTime("2012-11-04T00:30:00-07:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T01:30:00-07:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T01:30:00-08:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T02:30:00-08:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T03:30:00-08:00"))
|
||||
hour.bucketStart(new DateTime("2012-11-04T00:30:00-07:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T01:30:00-07:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T01:30:00-08:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T02:30:00-08:00")),
|
||||
hour.bucketStart(new DateTime("2012-11-04T03:30:00-08:00"))
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -405,9 +409,11 @@ public class QueryGranularityTest
|
||||
public void testPeriodTruncateDays() throws Exception
|
||||
{
|
||||
final DateTime origin = new DateTime("2012-01-02T05:00:00.000-08:00");
|
||||
PeriodGranularity periodOrigin = new PeriodGranularity(new Period("P2D"),
|
||||
origin,
|
||||
DateTimeZone.forID("America/Los_Angeles"));
|
||||
PeriodGranularity periodOrigin = new PeriodGranularity(
|
||||
new Period("P2D"),
|
||||
origin,
|
||||
DateTimeZone.forID("America/Los_Angeles")
|
||||
);
|
||||
assertSameDateTime(
|
||||
Lists.newArrayList(
|
||||
new DateTime("2011-12-31T05:00:00.000-08:00"),
|
||||
@ -422,9 +428,11 @@ public class QueryGranularityTest
|
||||
)
|
||||
);
|
||||
|
||||
PeriodGranularity periodNoOrigin = new PeriodGranularity(new Period("P2D"),
|
||||
null,
|
||||
DateTimeZone.forID("America/Los_Angeles"));
|
||||
PeriodGranularity periodNoOrigin = new PeriodGranularity(
|
||||
new Period("P2D"),
|
||||
null,
|
||||
DateTimeZone.forID("America/Los_Angeles")
|
||||
);
|
||||
assertSameDateTime(
|
||||
Lists.newArrayList(
|
||||
new DateTime("2012-01-01T00:00:00.000-08:00"),
|
||||
@ -640,16 +648,26 @@ public class QueryGranularityTest
|
||||
@Test
|
||||
public void testSerializePeriod() throws Exception
|
||||
{
|
||||
ObjectMapper mapper = new DefaultObjectMapper();
|
||||
final ObjectMapper mapper = new DefaultObjectMapper();
|
||||
|
||||
String json = "{ \"type\": \"period\", \"period\": \"P1D\" }";
|
||||
Granularity gran = mapper.readValue(json, Granularity.class);
|
||||
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), null, null), gran);
|
||||
|
||||
json = "{ \"type\": \"period\", \"period\": \"P1D\","
|
||||
// Nonstandard period
|
||||
json = "{ \"type\": \"period\", \"period\": \"P2D\" }";
|
||||
gran = mapper.readValue(json, Granularity.class);
|
||||
Assert.assertEquals(new PeriodGranularity(new Period("P2D"), null, null), gran);
|
||||
|
||||
// Set timeZone, origin
|
||||
json = "{ \"type\": \"period\", \"period\": \"P1D\","
|
||||
+ "\"timeZone\": \"America/Los_Angeles\", \"origin\": \"1970-01-01T00:00:00Z\"}";
|
||||
gran = mapper.readValue(json, Granularity.class);
|
||||
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), new DateTime(0L), DateTimeZone.forID("America/Los_Angeles")), gran);
|
||||
Assert.assertEquals(new PeriodGranularity(
|
||||
new Period("P1D"),
|
||||
new DateTime(0L),
|
||||
DateTimeZone.forID("America/Los_Angeles")
|
||||
), gran);
|
||||
|
||||
PeriodGranularity expected = new PeriodGranularity(
|
||||
new Period("P1D"),
|
||||
@ -695,46 +713,40 @@ public class QueryGranularityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeSimple() throws Exception
|
||||
public void testStandardGranularitiesSerde() throws Exception
|
||||
{
|
||||
ObjectMapper mapper = new DefaultObjectMapper();
|
||||
|
||||
Assert.assertEquals(
|
||||
Granularities.ALL,
|
||||
mapper.readValue(
|
||||
mapper.writeValueAsString(Granularities.ALL),
|
||||
Granularity.class
|
||||
)
|
||||
);
|
||||
for (GranularityType granularityType : GranularityType.values()) {
|
||||
final Granularity granularity = granularityType.getDefaultGranularity();
|
||||
|
||||
Assert.assertEquals(
|
||||
Granularities.NONE,
|
||||
mapper.readValue(
|
||||
mapper.writeValueAsString(Granularities.NONE),
|
||||
Granularity.class
|
||||
)
|
||||
);
|
||||
}
|
||||
Assert.assertEquals(
|
||||
granularity,
|
||||
mapper.readValue("\"" + granularityType.name().toUpperCase() + "\"", Granularity.class)
|
||||
);
|
||||
|
||||
@Test
|
||||
public void testDeserializeSimple() throws Exception
|
||||
{
|
||||
ObjectMapper mapper = new DefaultObjectMapper();
|
||||
Assert.assertEquals(
|
||||
granularity,
|
||||
mapper.readValue("\"" + granularityType.name().toLowerCase() + "\"", Granularity.class)
|
||||
);
|
||||
|
||||
Assert.assertEquals(Granularities.ALL, mapper.readValue("\"all\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.ALL, mapper.readValue("\"ALL\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.NONE, mapper.readValue("\"none\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.NONE, mapper.readValue("\"NONE\"", Granularity.class));
|
||||
Assert.assertEquals(
|
||||
granularity,
|
||||
mapper.readValue(mapper.writeValueAsString(granularity), Granularity.class)
|
||||
);
|
||||
|
||||
Assert.assertEquals(Granularities.DAY, mapper.readValue("\"day\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.HOUR, mapper.readValue("\"hour\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.MINUTE, mapper.readValue("\"minute\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.FIFTEEN_MINUTE, mapper.readValue("\"fifteen_minute\"", Granularity.class));
|
||||
|
||||
Assert.assertEquals(Granularities.WEEK, mapper.readValue("\"week\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.QUARTER, mapper.readValue("\"quarter\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.MONTH, mapper.readValue("\"month\"", Granularity.class));
|
||||
Assert.assertEquals(Granularities.YEAR, mapper.readValue("\"year\"", Granularity.class));
|
||||
if (granularityType == GranularityType.ALL || granularityType == GranularityType.NONE) {
|
||||
Assert.assertEquals(
|
||||
"{\"type\":\"" + granularityType.name().toLowerCase() + "\"}",
|
||||
mapper.writeValueAsString(granularity)
|
||||
);
|
||||
} else {
|
||||
Assert.assertEquals(
|
||||
"\"" + granularityType.name().toUpperCase() + "\"",
|
||||
mapper.writeValueAsString(granularity)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -745,7 +757,7 @@ public class QueryGranularityTest
|
||||
Assert.assertNull(Granularity.mergeGranularities(Lists.newArrayList(null, Granularities.DAY)));
|
||||
Assert.assertNull(Granularity.mergeGranularities(Lists.newArrayList(Granularities.DAY, null)));
|
||||
Assert.assertNull(
|
||||
Granularity.mergeGranularities(
|
||||
Granularity.mergeGranularities(
|
||||
Lists.newArrayList(
|
||||
Granularities.DAY,
|
||||
null,
|
||||
@ -754,7 +766,7 @@ public class QueryGranularityTest
|
||||
)
|
||||
);
|
||||
Assert.assertNull(
|
||||
Granularity.mergeGranularities(ImmutableList.of(Granularities.ALL, Granularities.DAY))
|
||||
Granularity.mergeGranularities(ImmutableList.of(Granularities.ALL, Granularities.DAY))
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
@ -792,9 +804,9 @@ public class QueryGranularityTest
|
||||
@Test(timeout = 10_000L)
|
||||
public void testDeadLock() throws Exception
|
||||
{
|
||||
final URL[] urls = ((URLClassLoader)Granularity.class.getClassLoader()).getURLs();
|
||||
final URL[] urls = ((URLClassLoader) Granularity.class.getClassLoader()).getURLs();
|
||||
final String className = Granularity.class.getCanonicalName();
|
||||
for(int i = 0; i < 1000; ++i) {
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
final ClassLoader loader = new URLClassLoader(urls, null);
|
||||
Assert.assertNotNull(String.valueOf(i), Class.forName(className, true, loader));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user