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
|
// 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 { util, Vector, DataType, Int64 } from 'apache-arrow';
import {
validateVector,
encodeAll, encodeEach, encodeEachDOM, encodeEachNode,
int64sNoNulls, int64sWithNulls, int64sWithMaxInts,
} from './utils';
const testDOMStreams = process.env.TEST_DOM_STREAMS === 'true';
const testNodeStreams = process.env.TEST_NODE_STREAMS === 'true';
const typeFactory = () => new Int64();
const valueName = `Int64`.toLowerCase();
const encode0 = encodeAll(typeFactory);
const encode1 = encodeEach(typeFactory);
const encode2 = encodeEach(typeFactory, 5);
const encode3 = encodeEach(typeFactory, 25);
const encode4 = encodeEachDOM(typeFactory, 25);
const encode5 = encodeEachNode(typeFactory, 25);
const nulls0: any[] = [0x7fffffff];
const nulls1: any[] = [0x7fffffff];
nulls0[0] = new Uint32Array([0x7fffffff, 0x7fffffff]);
nulls1[0] = util.BN.new(nulls0[0])[Symbol.toPrimitive]();
type EncodeValues<T extends DataType> = (values: (T['TValue'] | null)[], nullVals?: any[]) => Promise<Vector<T>>;
function encodeAndValidate<T extends DataType>(encode: EncodeValues<T>, providedNulls: any[] = [], expectedNulls = providedNulls) {
return (values: any[]) => {
return async () => {
const vector = await encode(values, providedNulls);
const expected = values.map((x) => {
switch (typeof x) {
case 'number': return new Int32Array([x, 0]);
case 'bigint': return new Int32Array(new BigInt64Array([x]).buffer);
}
return x ? x.slice() : x;
});
return validateVector(expected, vector, expectedNulls);
};
};
}
describe(`Int64Builder`, () => {
describe(`encode single chunk`, () => {
it(`encodes ${valueName} no nulls`, encodeAndValidate(encode0, [], [])(int64sNoNulls(20)));
it(`encodes ${valueName} with nulls`, encodeAndValidate(encode0, [null], [null])(int64sWithNulls(20)));
it(`encodes ${valueName} with MAX_INT`, encodeAndValidate(encode0, nulls0, nulls1)(int64sWithMaxInts(20)));
});
describe(`encode chunks length default`, () => {
it(`encodes ${valueName} no nulls`, encodeAndValidate(encode1, [], [])(int64sNoNulls(20)));
it(`encodes ${valueName} with nulls`, encodeAndValidate(encode1, [null], [null])(int64sWithNulls(20)));
it(`encodes ${valueName} with MAX_INT`, encodeAndValidate(encode1, nulls0, nulls1)(int64sWithMaxInts(20)));
});
describe(`encode chunks length 5`, () => {
it(`encodes ${valueName} no nulls`, encodeAndValidate(encode2, [], [])(int64sNoNulls(20)));
it(`encodes ${valueName} with nulls`, encodeAndValidate(encode2, [null], [null])(int64sWithNulls(20)));
it(`encodes ${valueName} with MAX_INT`, encodeAndValidate(encode2, nulls0, nulls1)(int64sWithMaxInts(20)));
});
describe(`encode chunks length 25`, () => {
it(`encodes ${valueName} no nulls`, encodeAndValidate(encode3, [], [])(int64sNoNulls(20)));
it(`encodes ${valueName} with nulls`, encodeAndValidate(encode3, [null], [null])(int64sWithNulls(20)));
it(`encodes ${valueName} with MAX_INT`, encodeAndValidate(encode3, nulls0, nulls1)(int64sWithMaxInts(20)));
});
testDOMStreams && describe(`encode chunks length 25, WhatWG stream`, () => {
it(`encodes ${valueName} no nulls`, encodeAndValidate(encode4, [], [])(int64sNoNulls(20)));
it(`encodes ${valueName} with nulls`, encodeAndValidate(encode4, [null], [null])(int64sWithNulls(20)));
it(`encodes ${valueName} with MAX_INT`, encodeAndValidate(encode4, nulls0, nulls1)(int64sWithMaxInts(20)));
});
testNodeStreams && describe(`encode chunks length 25, NodeJS stream`, () => {
it(`encodes ${valueName} no nulls`, encodeAndValidate(encode5, [], [])(int64sNoNulls(20)));
it(`encodes ${valueName} with nulls`, encodeAndValidate(encode5, [null], [null])(int64sWithNulls(20)));
it(`encodes ${valueName} with MAX_INT`, encodeAndValidate(encode5, nulls0, nulls1)(int64sWithMaxInts(20)));
});
});
|