Skip to content

BigQuery: FieldValue.getTimestamp() use of Double causes precision loss in some cases. #16

@slilichenko

Description

@slilichenko

Environment details

  1. Specify the API at the beginning of the title (for example, "BigQuery: ...")
    General, Core, and Other are also allowed as types
  2. OS type and version: any
  3. Java version: any
  4. google-cloud-java version(s): 1.96.0

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.

Metadata

Metadata

Labels

🚨This issue needs some love.api: bigqueryIssues related to the googleapis/java-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.status: blockedResolving the issue is dependent on other work.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions