diff --git a/core/src/main/java/org/apache/druid/java/util/common/granularity/Granularities.java b/core/src/main/java/org/apache/druid/java/util/common/granularity/Granularities.java index 91492aef717..303f835d889 100644 --- a/core/src/main/java/org/apache/druid/java/util/common/granularity/Granularities.java +++ b/core/src/main/java/org/apache/druid/java/util/common/granularity/Granularities.java @@ -33,6 +33,7 @@ public class Granularities public static final Granularity THIRTY_MINUTE = GranularityType.THIRTY_MINUTE.getDefaultGranularity(); public static final Granularity HOUR = GranularityType.HOUR.getDefaultGranularity(); public static final Granularity SIX_HOUR = GranularityType.SIX_HOUR.getDefaultGranularity(); + public static final Granularity EIGHT_HOUR = GranularityType.EIGHT_HOUR.getDefaultGranularity(); public static final Granularity DAY = GranularityType.DAY.getDefaultGranularity(); public static final Granularity WEEK = GranularityType.WEEK.getDefaultGranularity(); public static final Granularity MONTH = GranularityType.MONTH.getDefaultGranularity(); diff --git a/core/src/main/java/org/apache/druid/java/util/common/granularity/GranularityType.java b/core/src/main/java/org/apache/druid/java/util/common/granularity/GranularityType.java index ae3a277fa00..e2967476575 100644 --- a/core/src/main/java/org/apache/druid/java/util/common/granularity/GranularityType.java +++ b/core/src/main/java/org/apache/druid/java/util/common/granularity/GranularityType.java @@ -57,6 +57,7 @@ public enum GranularityType "PT1H" ), SIX_HOUR(HOUR, "PT6H"), + EIGHT_HOUR(HOUR, "PT8H"), DAY( "'dt'=yyyy-MM-dd", "'y'=yyyy/'m'=MM/'d'=dd", @@ -214,7 +215,9 @@ public enum GranularityType case 3: return GranularityType.DAY; case 4: - if (vals[index] == 6) { + if (vals[index] == 8) { + return GranularityType.EIGHT_HOUR; + } else if (vals[index] == 6) { return GranularityType.SIX_HOUR; } else if (vals[index] == 1) { return GranularityType.HOUR; diff --git a/core/src/test/java/org/apache/druid/java/util/common/GranularityTest.java b/core/src/test/java/org/apache/druid/java/util/common/GranularityTest.java index bc8ac3396a0..392a43149fb 100644 --- a/core/src/test/java/org/apache/druid/java/util/common/GranularityTest.java +++ b/core/src/test/java/org/apache/druid/java/util/common/GranularityTest.java @@ -46,6 +46,7 @@ public class GranularityTest final Granularity MINUTE = Granularities.MINUTE; final Granularity HOUR = Granularities.HOUR; final Granularity SIX_HOUR = Granularities.SIX_HOUR; + final Granularity EIGHT_HOUR = Granularities.EIGHT_HOUR; final Granularity FIFTEEN_MINUTE = Granularities.FIFTEEN_MINUTE; final Granularity DAY = Granularities.DAY; final Granularity WEEK = Granularities.WEEK; @@ -399,6 +400,90 @@ public class GranularityTest checkToDate(SIX_HOUR, Granularity.Formatter.DEFAULT, hourChecks); } + @Test + public void testEightHourToDate() + { + PathDate[] hourChecks = { + new PathDate( + new DateTime(2011, 3, 15, 16, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "y=2011/m=03/d=15/H=20/M=50/S=43/Test0" + ), + new PathDate( + new DateTime(2011, 3, 15, 16, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "/y=2011/m=03/d=15/H=20/M=50/S=43/Test0" + ), + new PathDate( + new DateTime(2011, 3, 15, 16, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "valid/y=2011/m=03/d=15/H=20/M=50/S=43/Test1" + ), + new PathDate( + new DateTime(2011, 3, 15, 16, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "valid/y=2011/m=03/d=15/H=20/M=50/Test2" + ), + new PathDate( + new DateTime(2011, 3, 15, 16, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "valid/y=2011/m=03/d=15/H=20/Test3" + ), + new PathDate(null, null, "valid/y=2011/m=03/d=15/Test4"), + new PathDate(null, null, "valid/y=2011/m=03/Test5"), + new PathDate(null, null, "valid/y=2011/Test6"), + new PathDate(null, null, "null/y=/m=/d=/Test7"), + new PathDate(null, null, "null/m=10/y=2011/d=23/Test8"), + new PathDate(null, null, "null/Test9"), + new PathDate(null, null, ""), //Test10 Intentionally empty. + new PathDate( + new DateTime(2011, 10, 20, 16, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=20/M=42/S=72/Test11" + ), + new PathDate( + new DateTime(2011, 10, 20, 16, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=20/M=90/S=24/Test12" + ), + new PathDate( + new DateTime(2011, 10, 20, 0, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=00/M=90/S=24/Test12" + ), + new PathDate( + new DateTime(2011, 10, 20, 0, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=02/M=90/S=24/Test12" + ), + new PathDate( + new DateTime(2011, 10, 20, 0, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=06/M=90/S=24/Test12" + ), + new PathDate( + new DateTime(2011, 10, 20, 8, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=11/M=90/S=24/Test12" + ), + new PathDate( + new DateTime(2011, 10, 20, 8, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=12/M=90/S=24/Test12" + ), + new PathDate( + new DateTime(2011, 10, 20, 8, 0, 0, 0, ISOChronology.getInstanceUTC()), + null, + "error/y=2011/m=10/d=20/H=13/M=90/S=24/Test12" + ), + new PathDate(null, IllegalFieldValueException.class, "error/y=2011/m=10/d=20/H=42/M=42/S=24/Test13"), + new PathDate(null, IllegalFieldValueException.class, "error/y=2011/m=10/d=33/H=20/M=42/S=24/Test14"), + new PathDate(null, IllegalFieldValueException.class, "error/y=2011/m=13/d=20/H=20/M=42/S=24/Test15") + }; + + checkToDate(EIGHT_HOUR, Granularity.Formatter.DEFAULT, hourChecks); + } + @Test public void testDayToDate() { @@ -886,6 +971,7 @@ public class GranularityTest Assert.assertEquals( ImmutableList.of( Granularities.DAY, + Granularities.EIGHT_HOUR, Granularities.SIX_HOUR, Granularities.HOUR, Granularities.THIRTY_MINUTE, @@ -927,6 +1013,7 @@ public class GranularityTest Granularities.MONTH, Granularities.WEEK, Granularities.DAY, + Granularities.EIGHT_HOUR, Granularities.SIX_HOUR, Granularities.HOUR, Granularities.THIRTY_MINUTE, diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/CompactionTaskTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/CompactionTaskTest.java index e1e8a80f7e4..69a17e6128f 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/CompactionTaskTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/CompactionTaskTest.java @@ -1632,6 +1632,7 @@ public class CompactionTaskTest Granularities.SECOND, Granularities.MINUTE, Granularities.SIX_HOUR, + Granularities.EIGHT_HOUR, Granularities.DAY, null, Granularities.ALL, @@ -1648,6 +1649,7 @@ public class CompactionTaskTest Granularities.SECOND, Granularities.MINUTE, Granularities.SIX_HOUR, + Granularities.EIGHT_HOUR, Granularities.NONE, Granularities.DAY, Granularities.NONE, diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java index aa7a8eb8856..9c0c6545ded 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java @@ -750,7 +750,7 @@ public class CalciteInsertDmlTest extends CalciteIngestionDmlTest ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString( "The granularity specified in PARTITIONED BY is not supported. " + "Please use an equivalent of these granularities: second, minute, five_minute, ten_minute, " - + "fifteen_minute, thirty_minute, hour, six_hour, day, week, month, quarter, year, all.")) + + "fifteen_minute, thirty_minute, hour, six_hour, eight_hour, day, week, month, quarter, year, all.")) ) ) .verify();