-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
losing precision in converting TIMESTAMP and INT64 to Javascript Number #1681
Comments
Thank you for opening this, @c0b! I think we're okay on integer & timestamp precision, since it is available through the raw @callmehiphop what do you think? |
Maybe in the docs we could recommend/show examples for precision using an int64 lib? We use node-int64 in Bigtable. |
Based on the discussion in the Node.js standup today, we are deciding this is not release blocking. A user who needs the full precision can get it from the raw API response in the third callback argument. |
I don't believe there is a good solution for this without introducing complexity. TIMESTAMPThe docs say that TIMESTAMPs are stored internally with microsecond precision, however, the raw API response seems to be returning the value in seconds. INT64The solution for this would be a bit more complex for the user. Currently, if you read one of these values, you get the native JS "Number" type. For our function Int(value) {
this.value = value.toString();
}
Int.prototype.valueOf = function() {
var number = Number(this.value);
if (number > Number.MAX_SAFE_INTEGER) {
throw new Error('Integer ' + this.value + ' is out of bounds.');
}
return number;
}; table.read(query, function(err, rows) {
var row = rows[0]
row = [
{
name: 'SafeInt',
value: {
value: '2' // string
}
},
{
name: 'OutOfBoundsInt',
value: {
value: '--out-of-bounds-integer--' // string
}
}
]
var safeInt = row[0].value
typeof safeInt === Spanner.Int
console.log(safeInt.value)
// '2' (String)
console.log(safeInt)
// 2 (Number type)
var outOfBoundsInt = row[1].value
typeof outOfBoundsInt === Spanner.Int
console.log(outOfBoundsInt.value)
// '--out-of-bounds-integer--' (String)
console.log(outOfBoundsInt)
// throws 'Integer '--out-of-bounds-integer-as-string--' is out of bounds.'
}) @lukesneeringer how should we determine if the precision is worth the complexity? |
This issue was moved to googleapis/nodejs-bigquery#6 |
#1648 (comment)
The BigQuery TIMESTAMP has up to microseconds precision, but when converting to a JavaScript Date, it becomes up to milliseconds
#1648 (comment)
A JavaScript Number is really only a FLOAT64, there is no real INT64, so during conversion some precision is lost:
I don't really have a solution, please suggest when application need this much precision
The text was updated successfully, but these errors were encountered: