mirror of https://github.com/apache/druid.git
Fix SQL Innterval.of() error message (#15454)
Better error message for poorly constructed intervals
This commit is contained in:
parent
d359fb3d68
commit
072b16c6df
|
@ -20,6 +20,7 @@
|
||||||
package org.apache.druid.java.util.common;
|
package org.apache.druid.java.util.common;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.apache.druid.error.InvalidInput;
|
||||||
import org.apache.druid.java.util.common.guava.Comparators;
|
import org.apache.druid.java.util.common.guava.Comparators;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
|
@ -39,8 +40,13 @@ public final class Intervals
|
||||||
|
|
||||||
public static Interval of(String interval)
|
public static Interval of(String interval)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
return new Interval(interval, ISOChronology.getInstanceUTC());
|
return new Interval(interval, ISOChronology.getInstanceUTC());
|
||||||
}
|
}
|
||||||
|
catch (IllegalArgumentException e) {
|
||||||
|
throw InvalidInput.exception(e, "Bad Interval[%s]: [%s]", interval, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Interval of(String format, Object... formatArgs)
|
public static Interval of(String format, Object... formatArgs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.apache.druid.java.util.common;
|
package org.apache.druid.java.util.common;
|
||||||
|
|
||||||
|
import org.apache.druid.error.DruidExceptionMatcher;
|
||||||
import org.apache.druid.java.util.common.guava.Comparators;
|
import org.apache.druid.java.util.common.guava.Comparators;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -78,4 +79,11 @@ public class IntervalsTest
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidInterval()
|
||||||
|
{
|
||||||
|
DruidExceptionMatcher.invalidInput().assertThrowsAndMatches(
|
||||||
|
() -> Intervals.of("invalid string")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -697,25 +697,6 @@ public class SqlSegmentsMetadataManagerTest
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testMarkAsUsedNonOvershadowedSegmentsInIntervalWithInvalidInterval() throws IOException
|
|
||||||
{
|
|
||||||
sqlSegmentsMetadataManager.startPollingDatabasePeriodically();
|
|
||||||
sqlSegmentsMetadataManager.poll();
|
|
||||||
Assert.assertTrue(sqlSegmentsMetadataManager.isPollingDatabasePeriodically());
|
|
||||||
|
|
||||||
final String newDataSource = "wikipedia2";
|
|
||||||
final DataSegment newSegment1 = createNewSegment1(newDataSource);
|
|
||||||
|
|
||||||
final DataSegment newSegment2 = createNewSegment2(newDataSource);
|
|
||||||
|
|
||||||
publish(newSegment1, false);
|
|
||||||
publish(newSegment2, false);
|
|
||||||
// invalid interval start > end
|
|
||||||
final Interval theInterval = Intervals.of("2017-10-22T00:00:00.000/2017-10-02T00:00:00.000");
|
|
||||||
sqlSegmentsMetadataManager.markAsUsedNonOvershadowedSegmentsInInterval(newDataSource, theInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkAsUsedNonOvershadowedSegmentsInIntervalWithOverlappingInterval() throws IOException
|
public void testMarkAsUsedNonOvershadowedSegmentsInIntervalWithOverlappingInterval() throws IOException
|
||||||
{
|
{
|
||||||
|
@ -833,25 +814,6 @@ public class SqlSegmentsMetadataManagerTest
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testMarkAsUnusedSegmentsInIntervalWithInvalidInterval() throws IOException
|
|
||||||
{
|
|
||||||
sqlSegmentsMetadataManager.startPollingDatabasePeriodically();
|
|
||||||
sqlSegmentsMetadataManager.poll();
|
|
||||||
Assert.assertTrue(sqlSegmentsMetadataManager.isPollingDatabasePeriodically());
|
|
||||||
|
|
||||||
final String newDataSource = "wikipedia2";
|
|
||||||
final DataSegment newSegment1 = createNewSegment1(newDataSource);
|
|
||||||
|
|
||||||
final DataSegment newSegment2 = createNewSegment2(newDataSource);
|
|
||||||
|
|
||||||
publisher.publishSegment(newSegment1);
|
|
||||||
publisher.publishSegment(newSegment2);
|
|
||||||
// invalid interval start > end
|
|
||||||
final Interval theInterval = Intervals.of("2017-10-22T00:00:00.000/2017-10-02T00:00:00.000");
|
|
||||||
sqlSegmentsMetadataManager.markAsUnusedSegmentsInInterval(newDataSource, theInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkAsUnusedSegmentsInIntervalWithOverlappingInterval() throws IOException
|
public void testMarkAsUnusedSegmentsInIntervalWithOverlappingInterval() throws IOException
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.druid.client.DruidServer;
|
||||||
import org.apache.druid.client.ImmutableDruidDataSource;
|
import org.apache.druid.client.ImmutableDruidDataSource;
|
||||||
import org.apache.druid.client.ImmutableSegmentLoadInfo;
|
import org.apache.druid.client.ImmutableSegmentLoadInfo;
|
||||||
import org.apache.druid.client.SegmentLoadInfo;
|
import org.apache.druid.client.SegmentLoadInfo;
|
||||||
|
import org.apache.druid.error.DruidExceptionMatcher;
|
||||||
import org.apache.druid.java.util.common.Intervals;
|
import org.apache.druid.java.util.common.Intervals;
|
||||||
import org.apache.druid.metadata.MetadataRuleManager;
|
import org.apache.druid.metadata.MetadataRuleManager;
|
||||||
import org.apache.druid.metadata.SegmentsMetadataManager;
|
import org.apache.druid.metadata.SegmentsMetadataManager;
|
||||||
|
@ -611,19 +612,9 @@ public class DataSourcesResourceTest
|
||||||
EasyMock.replay(overlordClient, server);
|
EasyMock.replay(overlordClient, server);
|
||||||
DataSourcesResource dataSourcesResource =
|
DataSourcesResource dataSourcesResource =
|
||||||
new DataSourcesResource(inventoryView, null, null, overlordClient, null, null, auditManager);
|
new DataSourcesResource(inventoryView, null, null, overlordClient, null, null, auditManager);
|
||||||
try {
|
DruidExceptionMatcher.invalidInput().assertThrowsAndMatches(
|
||||||
Response response =
|
() -> dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???", request)
|
||||||
dataSourcesResource.markAsUnusedAllSegmentsOrKillUnusedSegmentsInInterval("datasource", "true", "???", request);
|
);
|
||||||
// 400 (Bad Request) or an IllegalArgumentException is expected.
|
|
||||||
Assert.assertEquals(400, response.getStatus());
|
|
||||||
Assert.assertNotNull(response.getEntity());
|
|
||||||
Assert.assertTrue(response.getEntity().toString().contains("java.lang.IllegalArgumentException"));
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ignore) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
EasyMock.verify(overlordClient, server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue