BigQuery: FieldValue.getTimestamp() use of Double causes precision loss in some cases. #16
Labels
api: bigquery
Issues related to the googleapis/java-bigquery API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
🚨
This issue needs some love.
status: blocked
Resolving the issue is dependent on other work.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Environment details
General, Core, and Other are also allowed as types
Steps to reproduce
Create a row with this timestamp: 1337-09-02 11:43:21.622894 UTC, query and use fieldValue.getTimestamp(). Microseconds wouldn't be equal.
Code example
@test
public void testFloatingPointPrecisionLoss() {
FieldValue fieldValue = FieldValue.of(Attribute.PRIMITIVE, "-1.9954383398377106E10");
long received = fieldValue.getTimestampValue();
long expected = -19954383398377106L;
assertEquals(expected, received);
}
Any additional information below
Cause - floating point conversation causes it; need to use BigDecimal (or equivalent) to perform lossless conversion.
The text was updated successfully, but these errors were encountered: