-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Problem
The ydb-java-sdk does not allow to store a date, datetime or timestamp before 1.1.1970. In my opinion this does NOT make any sense. How do you suppose to store a birthdate before 1.1.1970.
How to reproduce
- Create a customer table
TableDescription customerTable = TableDescription.newBuilder()
.addNullableColumn("email", PrimitiveType.utf8())
.addNullableColumn("firstname", PrimitiveType.utf8())
.addNullableColumn("lastname", PrimitiveType.utf8())
.addNullableColumn("birthdate", PrimitiveType.date())
.addNullableColumn("modifier", PrimitiveType.utf8())
.addNullableColumn("lastupdate", PrimitiveType.timestamp())
.setPrimaryKey("email")
.build();
-
Store a birthdate before 1.1.1970 -> save birthdate 1.1.1930
-
Finally you get this exception
Exception in thread "main" java.lang.IllegalArgumentException: negative daysSinceEpoch: -354285
at com.yandex.ydb.table.values.PrimitiveValue.date(PrimitiveValue.java:205)
at com.yandex.ydb.table.values.PrimitiveValue.date(PrimitiveValue.java:215)
at com.yandex.ydb.examples.simple.BenchmarkDatabase.addDataToCustomerTable(BenchmarkDatabase.java:172)
at com.yandex.ydb.examples.simple.BenchmarkDatabase.fillData(BenchmarkDatabase.java:157)
Issue (weird restriction of negative days since Epoch)
Please check PrimitiveValue.java https://github.com/yandex-cloud/ydb-java-sdk/blob/master/table/src/main/java/com/yandex/ydb/table/values/PrimitiveValue.java
public static PrimitiveValue date(long daysSinceEpoch) {
if (daysSinceEpoch < 0) {
throw new IllegalArgumentException("negative daysSinceEpoch: " + daysSinceEpoch);
}
return new InstantValue(PrimitiveType.date(), TimeUnit.DAYS.toMicros(daysSinceEpoch));
}
public static PrimitiveValue date(LocalDate value) {
return date(value.toEpochDay());
}
public static PrimitiveValue date(Instant value) {
return date(TimeUnit.SECONDS.toDays(value.getEpochSecond()));
}
All dates are finally converted into a long but a negative long is not allowed, why?
Linux and Java can handle date before the epoch.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels