Skip to content

Commit

Permalink
MSQ ingestion: Improve error message on encountering non-long timesta…
Browse files Browse the repository at this point in the history
…mp column (#17411)

This PR improves the error message during MSQ ingestion if we encounter a non-long timestamp column.
  • Loading branch information
Akshat-Jain authored Oct 25, 2024
1 parent c4b513e commit fe0f415
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ public static long primaryTimestampFromObjectForInsert(final Object timestamp)
// 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
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;
Expand All @@ -46,6 +48,7 @@
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;
Expand Down Expand Up @@ -244,6 +247,42 @@ public void test_queryWithoutEnoughSlots_shouldThrowException()
}
}

@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
Expand Down

0 comments on commit fe0f415

Please sign in to comment.