[JS] pre-epoch Timestamps are off by a fixed amount
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- data
调研方向
首先,使用当前的 apache-arrow 包运行提供的 test.mjs 复现代码。跟踪 Timestamp 和 Date_ 值的 makeBuilder 路径,重点关注 epoch 之前的输入及其在 JavaScript 中表示的 64-bit 值。完成的标准是:epoch 之前的 Timestamp 值不再接收固定偏移量,Date_ 值具有一致的按天舍入,并为所示案例提供回归覆盖。
由索引模型根据 Issue 内容生成。
描述
Describe the bug, including details regarding any error messages, version, and platform.
While constructing a Vector of Timestamp values, any pre-epoch values end up offset by approximately 2^32 * 10^(3n), where n depends on the precision.
I've written a script for minimal repro using the latest version of the apache-arrow NPM package (12.0.0).
// test.mjs
import {
Date_,
makeBuilder,
Timestamp,
TimeUnit,
DateUnit,
} from "apache-arrow";
/**
* @param {Date} value
* @param {TimeUnit} precision
* @returns {number}
*/
const testTimestamp = (value, precision) => {
const columnBuilder = makeBuilder({ type: new Timestamp(precision) });
columnBuilder.append(value);
const vec = columnBuilder.finish().toVector();
const valueInVec = Array.from(vec)[0];
return +value - +valueInVec;
};
console.log("Testing TIMESTAMP\n");
[
["2000-01-01", TimeUnit.NANOSECOND],
["2000-01-01", TimeUnit.MICROSECOND],
["2000-01-01", TimeUnit.MILLISECOND],
["2000-01-01", TimeUnit.SECOND],
[],
["1900-01-01", TimeUnit.NANOSECOND],
["1900-01-01", TimeUnit.MICROSECOND],
["1900-01-01", TimeUnit.MILLISECOND],
["1900-01-01", TimeUnit.SECOND],
[],
["1969-12-31 23:59:59Z", TimeUnit.NANOSECOND],
["1969-01-01", TimeUnit.NANOSECOND],
["1900-01-01", TimeUnit.NANOSECOND],
["1800-01-01", TimeUnit.NANOSECOND],
["1700-01-01", TimeUnit.NANOSECOND],
].forEach(([dateStr, precision]) => {
if (!dateStr) {
console.log();
return;
}
const outcome = testTimestamp(new Date(dateStr), precision);
const label = `${dateStr} w/ ${TimeUnit[precision]}`;
console.log(`${label.padEnd(40)} => ${outcome}`);
});
console.log("\n\nTesting DATE\n");
/**
* @param {Date} value
* @returns {Date}
*/
const testDate = (value, precision) => {
const columnBuilder = makeBuilder({ type: new Date_(DateUnit.DAY) });
columnBuilder.append(value);
const vec = columnBuilder.finish().toVector();
const valueInVec = Array.from(vec)[0];
return valueInVec;
};
[
["1969-12-15 01:00:00Z", "rounded up"],
["1969-12-31 01:00:00Z", "rounded up"],
["1970-01-01 00:00:00Z", "rounded down"],
["1970-01-01 23:00:00Z", "rounded down"],
["1970-01-15 01:00:00Z", "rounded down"],
].forEach(([dateStr, label]) => {
const date = new Date(dateStr);
const outcome = testDate(date);
console.log(`${date.toISOString()} => ${outcome.toISOString()} (${label})`);
});
Here's the output:
Testing TIMESTAMP
2000-01-01 w/ NANOSECOND => 0
2000-01-01 w/ MICROSECOND => 0
2000-01-01 w/ MILLISECOND => 0
2000-01-01 w/ SECOND => 0
1900-01-01 w/ NANOSECOND => -4294.96728515625
1900-01-01 w/ MICROSECOND => -4294967.2958984375
1900-01-01 w/ MILLISECOND => -4294967296
1900-01-01 w/ SECOND => -4294967296000
1969-12-31 23:59:59Z w/ NANOSECOND => -4294.967296
1969-01-01 w/ NANOSECOND => -4294.967296600342
1900-01-01 w/ NANOSECOND => -4294.96728515625
1800-01-01 w/ NANOSECOND => -4294.9677734375
1700-01-01 w/ NANOSECOND => -4294.966796875
Testing DATE
1969-12-15T01:00:00.000Z => 1969-12-16T00:00:00.000Z (rounded up)
1969-12-31T01:00:00.000Z => 1970-01-01T00:00:00.000Z (rounded up)
1970-01-01T00:00:00.000Z => 1970-01-01T00:00:00.000Z (rounded down)
1970-01-01T23:00:00.000Z => 1970-01-01T00:00:00.000Z (rounded down)
1970-01-15T01:00:00.000Z => 1970-01-15T00:00:00.000Z (rounded down)
As you can see, for the Timestamp type, values post-epoch pass through unscathed, but values pre-epoch end up off by a fixed increment of:
- approximately
2^32 / 1,000,000forNANOSECONDprecision - approximately
2^32 / 1,000forMICROSECONDprecision 2^32forMILLISECONDprecision2^32 * 1,000forSECONDprecision
Note: I say "fixed", but the amount actually varies slightly when it's a float (for NANOSECOND and MICROSECOND precisions), as you can see in the last block of tests for Timestamp -- it varies a bit, seemingly varying more as the value gets further from the epoch.
It seems like the Arrow Timestamp type is a 64-bit int of {precision} since the epoch, but is represented as two 32-bit ints in JS. Something is getting messed up for pre-epoch timestamps, which have a negative number for their internal representation. I'm guessing it has to do with 32bit arithmetic and/or float precision issues.
Additionally, for the Date_ type, values post-epoch seem to "round down" to the nearest day properly, but values pre-epoch seem to "round up" to the next day. I'm guessing that this is a related issue.
Component(s)
JavaScript
- 主要语言
- TypeScript
- 星标
- 114
- 派生
- 35
- 平均合并
- 13 小时 35 分钟
- 30 天内合并 PR
- 5
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/arrow-js 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
The IPC reader accepts a column that is shorter than its RecordBatch, and fills the missing rows with nulls可能已有人在做 @Sealdot 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
The IPC reader ignores Schema.endianness: a big-endian stream reads 1, 2, 3 as 16777216, 33554432, 50331648可能已有人在做 @aniket-r2Dev2 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
tableFromIPC loops with no end on a file whose RecordBatch block points at a DictionaryBatch可能已有人在做 @aniket-r2Dev2 于 4 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
The stream reader drops a message of an unexpected type but not its body, and parses the body as the next messages可能已有人在做 @Umer-Butt07 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
earendil-works/gondolin#222 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
endora-commerce/endora-commerce#2203 ·
维护者通常 1 天内回复
-
enhancement priority:medium ready-for-human
难度 2/5 1-3 小时 新手友好度 66/100
wondermoney/wondermoney#1079 ·
维护者通常 1 天内回复