Skip to content

Commit 190add8

Browse files
Backport to branch(3.15) : Add exception handling for DateTimeParseException (#2676)
Co-authored-by: inv-jishnu <[email protected]>
1 parent c60deee commit 190add8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

core/src/main/java/com/scalar/db/common/error/CoreError.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,12 @@ public enum CoreError implements ScalarDbError {
886886
DATA_LOADER_FILE_PATH_IS_BLANK(
887887
Category.USER_ERROR, "0197", "File path must not be blank.", "", ""),
888888
DATA_LOADER_FILE_NOT_FOUND(Category.USER_ERROR, "0198", "File not found: %s", "", ""),
889+
DATA_LOADER_INVALID_DATE_TIME_FOR_COLUMN_VALUE(
890+
Category.USER_ERROR,
891+
"0199",
892+
"Invalid date time value specified for column %s in table %s in namespace %s.",
893+
"",
894+
""),
889895

890896
//
891897
// Errors for the concurrency error category

data-loader/core/src/main/java/com/scalar/db/dataloader/core/util/ColumnUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.time.LocalDate;
2626
import java.time.LocalDateTime;
2727
import java.time.LocalTime;
28+
import java.time.format.DateTimeParseException;
2829
import java.util.ArrayList;
2930
import java.util.Base64;
3031
import java.util.HashSet;
@@ -135,6 +136,11 @@ public static Column<?> createColumnFromValue(
135136
CoreError.DATA_LOADER_INVALID_NUMBER_FORMAT_FOR_COLUMN_VALUE.buildMessage(
136137
columnName, columnInfo.getTableName(), columnInfo.getNamespace()),
137138
e);
139+
} catch (DateTimeParseException e) {
140+
throw new ColumnParsingException(
141+
CoreError.DATA_LOADER_INVALID_DATE_TIME_FOR_COLUMN_VALUE.buildMessage(
142+
columnName, columnInfo.getTableName(), columnInfo.getNamespace()),
143+
e);
138144
} catch (IllegalArgumentException e) {
139145
throw new ColumnParsingException(
140146
CoreError.DATA_LOADER_INVALID_BASE64_ENCODING_FOR_COLUMN_VALUE.buildMessage(

data-loader/core/src/test/java/com/scalar/db/dataloader/core/util/ColumnUtilsTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,25 @@ void createColumnFromValue_invalidBase64_throwsBase64Exception() {
184184
columnName, "table", "ns"),
185185
exception.getMessage());
186186
}
187+
/**
188+
* Tests that attempting to create a date time column with an invalid format throws a
189+
* DateTimeParseException with appropriate error message.
190+
*/
191+
@Test
192+
void createColumnFromValue_invalidDateTimeFormat_throwsDateTimeParseException() {
193+
String columnName = "timestampColumn";
194+
String value = "not_a_timestamp";
195+
ColumnInfo columnInfo =
196+
ColumnInfo.builder().namespace("ns").tableName("table").columnName(columnName).build();
197+
ColumnParsingException exception =
198+
assertThrows(
199+
ColumnParsingException.class,
200+
() -> ColumnUtils.createColumnFromValue(DataType.TIMESTAMP, columnInfo, value));
201+
assertEquals(
202+
CoreError.DATA_LOADER_INVALID_DATE_TIME_FOR_COLUMN_VALUE.buildMessage(
203+
columnName, "table", "ns"),
204+
exception.getMessage());
205+
}
187206

188207
/**
189208
* Tests the extraction of columns from a ScalarDB Result object. Verifies that all columns are

0 commit comments

Comments
 (0)