Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading