forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date-vector-tests.ts
111 lines (104 loc) · 3.75 KB
/
date-vector-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import { DateDay, DateMillisecond, RecordBatchReader, Table, vectorFromArray } from 'apache-arrow';
describe(`DateVector`, () => {
it('returns days since the epoch as correct JS Dates', () => {
const table = new Table(RecordBatchReader.from(test_data));
const expectedMillis = expectedMillis32();
const date32 = table.getChildAt<DateDay>(0)!;
for (const date of date32) {
const millis = expectedMillis.shift();
expect(date).toEqual(millis === null ? null : new Date(millis!));
}
});
it('returns millisecond longs since the epoch as correct JS Dates', () => {
const table = new Table(RecordBatchReader.from(test_data));
const expectedMillis = expectedMillis64();
const date64 = table.getChildAt<DateMillisecond>(1)!;
for (const date of date64) {
const millis = expectedMillis.shift();
expect(date).toEqual(millis === null ? null : new Date(millis!));
}
});
it('returns the same date that was in the vector', () => {
const dates = [new Date(1950, 1, 0)];
const vec = vectorFromArray(dates);
for (const date of vec) {
expect(date).toEqual(dates.shift());
}
});
});
const expectedMillis32 = () => [
165247430400000, 34582809600000, 232604524800000, null,
199808812800000, 165646771200000, 209557238400000, null
];
const expectedMillis64 = () => [
27990830234011, -41278585914325, 12694624797111,
null, null, 10761360520213, null, 1394015437000
];
const test_data = {
'schema': {
'fields': [
{
'name': 'f0',
'type': {
'name': 'date',
'unit': 'DAY'
},
'nullable': true,
'children': []
},
{
'name': 'f1',
'type': {
'name': 'date',
'unit': 'MILLISECOND'
},
'nullable': true,
'children': []
}
]
},
'batches': [
{
'count': 8,
'columns': [
{
'name': 'f0',
'count': 8,
'VALIDITY': [1, 1, 1, 0, 1, 1, 1, 0],
'DATA': [1912586, 400264, 2692182, 2163746, 2312602, 1917208, 2425431]
},
{
'name': 'f1',
'count': 8,
'VALIDITY': [1, 1, 1, 0, 0, 1, 0, 1],
'DATA': [
27990830234011,
-41278585914325,
12694624797111,
-38604948562547,
-37802308043516,
10761360520213,
-25129181633384,
1394015437000 // <-- the tricky one
]
}
]
}
]
};