]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/js/test/unit/builders/dictionary-tests.ts
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / js / test / unit / builders / dictionary-tests.ts
CommitLineData
1d09f67e
TL
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18import { validateVector } from './utils';
19import { Dictionary, Utf8, Int32, Vector } from 'apache-arrow';
20import {
21 encodeAll,
22 encodeEach,
23 encodeEachDOM,
24 encodeEachNode,
25 duplicateItems,
26 stringsNoNulls,
27 stringsWithNAs,
28 stringsWithNulls,
29 stringsWithEmpties
30} from './utils';
31
32const testDOMStreams = process.env.TEST_DOM_STREAMS === 'true';
33const testNodeStreams = process.env.TEST_NODE_STREAMS === 'true';
34
35describe('DictionaryBuilder', () => {
36 describe('<Utf8, Int32>', () => {
37 runTestsWithEncoder('encodeAll', encodeAll(() => new Dictionary(new Utf8(), new Int32())));
38 runTestsWithEncoder('encodeEach: 5', encodeEach(() => new Dictionary(new Utf8(), new Int32()), 5));
39 runTestsWithEncoder('encodeEach: 25', encodeEach(() => new Dictionary(new Utf8(), new Int32()), 25));
40 runTestsWithEncoder('encodeEach: undefined', encodeEach(() => new Dictionary(new Utf8(), new Int32()), void 0));
41 testDOMStreams && runTestsWithEncoder('encodeEachDOM: 25', encodeEachDOM(() => new Dictionary(new Utf8(), new Int32()), 25));
42 testNodeStreams && runTestsWithEncoder('encodeEachNode: 25', encodeEachNode(() => new Dictionary(new Utf8(), new Int32()), 25));
43 });
44});
45
46function runTestsWithEncoder(name: string, encode: (vals: (string | null)[], nullVals?: any[]) => Promise<Vector<Dictionary<Utf8, Int32>>>) {
47 describe(`${encode.name} ${name}`, () => {
48 it(`dictionary-encodes strings no nulls`, async () => {
49 const vals = duplicateItems(20, stringsNoNulls(10));
50 validateVector(vals, await encode(vals, []), []);
51 });
52 it(`dictionary-encodes strings with nulls`, async () => {
53 const vals = duplicateItems(20, stringsWithNulls(10));
54 validateVector(vals, await encode(vals, [null]), [null]);
55 });
56 it(`dictionary-encodes strings using n/a as the null value rep`, async () => {
57 const vals = duplicateItems(20, stringsWithNAs(10));
58 validateVector(vals, await encode(vals, ['n/a']), ['n/a']);
59 });
60 it(`dictionary-encodes strings using \\0 as the null value rep`, async () => {
61 const vals = duplicateItems(20, stringsWithEmpties(10));
62 validateVector(vals, await encode(vals, ['\0']), ['\0']);
63 });
64 });
65}