MSQ ingestion: Improve error message on encountering non-long timestamp column (#17411)

This PR improves the error message during MSQ ingestion if we encounter a non-long timestamp column.
This commit is contained in:
Akshat Jain 2024-10-25 15:02:32 +05:30 committed by GitHub
parent c4b513e599
commit fe0f4150c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 1 deletions

View File

@ -114,7 +114,13 @@ public class MSQTasks
// be a long at execution time. So a nice user-friendly message isn't needed here: it would only happen
// if the SQL layer is bypassed. Nice, friendly users wouldn't do that :)
final UnknownFault fault =
UnknownFault.forMessage(StringUtils.format("Incorrect type for [%s]", ColumnHolder.TIME_COLUMN_NAME));
UnknownFault.forMessage(
StringUtils.format(
"Incorrect type for column [%s]. Expected LONG but got type [%s]. Please ensure that the value is cast to LONG.",
ColumnHolder.TIME_COLUMN_NAME,
timestamp.getClass().getSimpleName()
)
);
throw new MSQException(fault);
}
}

View File

@ -34,8 +34,10 @@ import org.apache.druid.indexer.TaskStatus;
import org.apache.druid.indexer.TaskStatusPlus;
import org.apache.druid.java.util.common.DateTimes;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.msq.indexing.MSQWorkerTask;
import org.apache.druid.msq.indexing.MSQWorkerTaskLauncher;
import org.apache.druid.msq.indexing.error.InsertTimeNullFault;
import org.apache.druid.msq.indexing.error.MSQErrorReport;
import org.apache.druid.msq.indexing.error.MSQException;
import org.apache.druid.msq.indexing.error.MSQFaultUtils;
@ -46,6 +48,7 @@ import org.apache.druid.msq.indexing.error.TooManyColumnsFault;
import org.apache.druid.msq.indexing.error.TooManyWorkersFault;
import org.apache.druid.msq.indexing.error.UnknownFault;
import org.apache.druid.msq.indexing.error.WorkerRpcFailedFault;
import org.apache.druid.segment.column.ColumnHolder;
import org.apache.druid.utils.CollectionUtils;
import org.junit.Assert;
import org.junit.Test;
@ -244,6 +247,42 @@ public class MSQTasksTest
}
}
@Test
public void test_getPrimaryTimestampFromObjectForInsert_longValue()
{
Assert.assertEquals(100, MSQTasks.primaryTimestampFromObjectForInsert(100L));
}
@Test
public void test_getPrimaryTimestampFromObjectForInsert_nullValueShouldThrowError()
{
final MSQException e = Assert.assertThrows(
MSQException.class,
() -> MSQTasks.primaryTimestampFromObjectForInsert(null)
);
Assert.assertEquals(InsertTimeNullFault.INSTANCE, e.getFault());
}
@Test
public void test_getPrimaryTimestampFromObjectForInsert_DoubleValueShouldThrowError()
{
final Object timestamp = 1.693837200123456E15;
final MSQException e = Assert.assertThrows(
MSQException.class,
() -> MSQTasks.primaryTimestampFromObjectForInsert(timestamp)
);
Assert.assertEquals(
UnknownFault.forMessage(
StringUtils.format(
"Incorrect type for column [%s]. Expected LONG but got type [%s]. Please ensure that the value is cast to LONG.",
ColumnHolder.TIME_COLUMN_NAME,
timestamp.getClass().getSimpleName()
)
),
e.getFault()
);
}
static class TasksTestOverlordClient extends NoopOverlordClient
{
// Num of slots available for tasks