MSQ: Improve InsertTimeOutOfBounds error message. (#14511)

Nicer and actionable error message for `InsertTimeOutOfBounds` fault
This commit is contained in:
Gian Merlino 2023-07-01 13:14:19 -07:00 committed by GitHub
parent 67fbd8e7fc
commit 048dbcee88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 7 deletions

View File

@ -1007,7 +1007,7 @@ public class ControllerImpl implements Controller
// Validate interval against the replaceTimeChunks set of intervals.
if (destination.getReplaceTimeChunks().stream().noneMatch(chunk -> chunk.contains(interval))) {
throw new MSQException(new InsertTimeOutOfBoundsFault(interval));
throw new MSQException(new InsertTimeOutOfBoundsFault(interval, destination.getReplaceTimeChunks()));
}
final List<Pair<Integer, ClusterByPartition>> ranges = bucketEntry.getValue();

View File

@ -22,6 +22,7 @@ package org.apache.druid.msq.indexing.error;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.joda.time.Interval;
import java.util.List;
import java.util.Objects;
public class InsertTimeOutOfBoundsFault extends BaseMSQFault
@ -29,11 +30,23 @@ public class InsertTimeOutOfBoundsFault extends BaseMSQFault
static final String CODE = "InsertTimeOutOfBounds";
private final Interval interval;
private final List<Interval> intervalBounds;
public InsertTimeOutOfBoundsFault(@JsonProperty("interval") Interval interval)
public InsertTimeOutOfBoundsFault(
@JsonProperty("interval") Interval interval,
@JsonProperty("intervalBounds") List<Interval> intervalBounds
)
{
super(CODE, "Query generated time chunk [%s] out of bounds specified by replaceExistingTimeChunks", interval);
super(
CODE,
"Inserted data contains time chunk[%s] outside of bounds specified by OVERWRITE WHERE[%s]. "
+ "If you want to include this data, expand your OVERWRITE WHERE. "
+ "If you do not want to include this data, use SELECT ... WHERE to filter it from your inserted data.",
interval,
intervalBounds
);
this.interval = interval;
this.intervalBounds = intervalBounds;
}
@JsonProperty
@ -42,6 +55,12 @@ public class InsertTimeOutOfBoundsFault extends BaseMSQFault
return interval;
}
@JsonProperty
public List<Interval> getIntervalBounds()
{
return intervalBounds;
}
@Override
public boolean equals(Object o)
{
@ -55,12 +74,24 @@ public class InsertTimeOutOfBoundsFault extends BaseMSQFault
return false;
}
InsertTimeOutOfBoundsFault that = (InsertTimeOutOfBoundsFault) o;
return Objects.equals(interval, that.interval);
return Objects.equals(interval, that.interval) && Objects.equals(
intervalBounds,
that.intervalBounds
);
}
@Override
public int hashCode()
{
return Objects.hash(super.hashCode(), interval);
return Objects.hash(super.hashCode(), interval, intervalBounds);
}
@Override
public String toString()
{
return "InsertTimeOutOfBoundsFault{" +
"interval=" + interval +
", intervalBounds=" + intervalBounds +
'}';
}
}

View File

@ -153,7 +153,12 @@ public class MSQFaultsTest extends MSQTestBase
"replace into foo1 overwrite where __time >= TIMESTAMP '2002-01-02 00:00:00' and __time < TIMESTAMP '2002-01-03 00:00:00' select __time, dim1 , count(*) as cnt from foo where dim1 is not null group by 1, 2 PARTITIONED by day clustered by dim1")
.setExpectedDataSource("foo1")
.setExpectedRowSignature(rowSignature)
.setExpectedMSQFault(new InsertTimeOutOfBoundsFault(Intervals.of("2000-01-02T00:00:00.000Z/2000-01-03T00:00:00.000Z")))
.setExpectedMSQFault(
new InsertTimeOutOfBoundsFault(
Intervals.of("2000-01-02T00:00:00.000Z/2000-01-03T00:00:00.000Z"),
Collections.singletonList(Intervals.of("2002-01-02/2002-01-03"))
)
)
.verifyResults();
}

View File

@ -32,6 +32,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
public class MSQFaultSerdeTest
{
@ -63,7 +64,10 @@ public class MSQFaultSerdeTest
assertFaultSerde(new InsertCannotBeEmptyFault("the datasource"));
assertFaultSerde(InsertLockPreemptedFault.INSTANCE);
assertFaultSerde(InsertTimeNullFault.INSTANCE);
assertFaultSerde(new InsertTimeOutOfBoundsFault(Intervals.ETERNITY));
assertFaultSerde(new InsertTimeOutOfBoundsFault(
Intervals.of("2001/2002"),
Collections.singletonList(Intervals.of("2000/2001"))
));
assertFaultSerde(new InvalidNullByteFault("the source", 1, "the column", "the value", 2));
assertFaultSerde(new NotEnoughMemoryFault(1000, 1000, 900, 1, 2));
assertFaultSerde(QueryNotSupportedFault.INSTANCE);