diff --git a/core/src/main/java/com/scalar/db/common/error/CoreError.java b/core/src/main/java/com/scalar/db/common/error/CoreError.java index 6185493f20..8743c35b1e 100644 --- a/core/src/main/java/com/scalar/db/common/error/CoreError.java +++ b/core/src/main/java/com/scalar/db/common/error/CoreError.java @@ -896,6 +896,12 @@ public enum CoreError implements ScalarDbError { DATA_LOADER_FILE_PATH_IS_BLANK( Category.USER_ERROR, "0197", "File path must not be blank.", "", ""), DATA_LOADER_FILE_NOT_FOUND(Category.USER_ERROR, "0198", "File not found: %s", "", ""), + DATA_LOADER_INVALID_DATE_TIME_FOR_COLUMN_VALUE( + Category.USER_ERROR, + "0199", + "Invalid date time value specified for column %s in table %s in namespace %s.", + "", + ""), // // Errors for the concurrency error category diff --git a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/util/ColumnUtils.java b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/util/ColumnUtils.java index 0907388978..d6a653cced 100644 --- a/data-loader/core/src/main/java/com/scalar/db/dataloader/core/util/ColumnUtils.java +++ b/data-loader/core/src/main/java/com/scalar/db/dataloader/core/util/ColumnUtils.java @@ -25,6 +25,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Base64; import java.util.HashSet; @@ -135,6 +136,11 @@ public static Column createColumnFromValue( CoreError.DATA_LOADER_INVALID_NUMBER_FORMAT_FOR_COLUMN_VALUE.buildMessage( columnName, columnInfo.getTableName(), columnInfo.getNamespace()), e); + } catch (DateTimeParseException e) { + throw new ColumnParsingException( + CoreError.DATA_LOADER_INVALID_DATE_TIME_FOR_COLUMN_VALUE.buildMessage( + columnName, columnInfo.getTableName(), columnInfo.getNamespace()), + e); } catch (IllegalArgumentException e) { throw new ColumnParsingException( CoreError.DATA_LOADER_INVALID_BASE64_ENCODING_FOR_COLUMN_VALUE.buildMessage( diff --git a/data-loader/core/src/test/java/com/scalar/db/dataloader/core/util/ColumnUtilsTest.java b/data-loader/core/src/test/java/com/scalar/db/dataloader/core/util/ColumnUtilsTest.java index 09c94b3844..49616cb02e 100644 --- a/data-loader/core/src/test/java/com/scalar/db/dataloader/core/util/ColumnUtilsTest.java +++ b/data-loader/core/src/test/java/com/scalar/db/dataloader/core/util/ColumnUtilsTest.java @@ -184,6 +184,25 @@ void createColumnFromValue_invalidBase64_throwsBase64Exception() { columnName, "table", "ns"), exception.getMessage()); } + /** + * Tests that attempting to create a date time column with an invalid format throws a + * DateTimeParseException with appropriate error message. + */ + @Test + void createColumnFromValue_invalidDateTimeFormat_throwsDateTimeParseException() { + String columnName = "timestampColumn"; + String value = "not_a_timestamp"; + ColumnInfo columnInfo = + ColumnInfo.builder().namespace("ns").tableName("table").columnName(columnName).build(); + ColumnParsingException exception = + assertThrows( + ColumnParsingException.class, + () -> ColumnUtils.createColumnFromValue(DataType.TIMESTAMP, columnInfo, value)); + assertEquals( + CoreError.DATA_LOADER_INVALID_DATE_TIME_FOR_COLUMN_VALUE.buildMessage( + columnName, "table", "ns"), + exception.getMessage()); + } /** * Tests the extraction of columns from a ScalarDB Result object. Verifies that all columns are