summaryrefslogtreecommitdiffstats
path: root/src/arrow/js/test/inference
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/arrow/js/test/inference
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/arrow/js/test/inference')
-rw-r--r--src/arrow/js/test/inference/column.ts62
-rw-r--r--src/arrow/js/test/inference/nested.ts62
-rw-r--r--src/arrow/js/test/inference/visitor/get.ts56
3 files changed, 180 insertions, 0 deletions
diff --git a/src/arrow/js/test/inference/column.ts b/src/arrow/js/test/inference/column.ts
new file mode 100644
index 000000000..440116b69
--- /dev/null
+++ b/src/arrow/js/test/inference/column.ts
@@ -0,0 +1,62 @@
+// 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.
+
+/* eslint-disable jest/no-standalone-expect */
+
+import { Data } from 'apache-arrow/data';
+import { Field } from 'apache-arrow/schema';
+import { Column } from 'apache-arrow/column';
+import { Vector } from 'apache-arrow/vector';
+import { Bool, Int8, Utf8, List, Dictionary, Struct } from 'apache-arrow/type';
+
+const boolType = new Bool();
+const boolVector = Vector.new(Data.Bool(boolType, 0, 10, 0, null, new Uint8Array(2)));
+
+const boolColumn = new Column(new Field('bool', boolType), [
+ Vector.new(Data.Bool(boolType, 0, 10, 0, null, new Uint8Array(2))),
+ Vector.new(Data.Bool(boolType, 0, 10, 0, null, new Uint8Array(2))),
+ Vector.new(Data.Bool(boolType, 0, 10, 0, null, new Uint8Array(2))),
+]);
+
+expect(typeof boolVector.get(0) === 'boolean').toBe(true);
+expect(typeof boolColumn.get(0) === 'boolean').toBe(true);
+
+type IndexSchema = {
+ 0: Int8;
+ 1: Utf8;
+ 2: Dictionary<List<Bool>>;
+};
+
+const structChildFields = [
+ { name: 0, type: new Int8() },
+ { name: 1, type: new Utf8() },
+ { name: 2, type: new Dictionary<List<Bool>>(null!, null!) }
+].map(({ name, type }) => new Field('' + name, type));
+
+const structType = new Struct<IndexSchema>(structChildFields);
+const structVector = Vector.new(Data.Struct(structType, 0, 0, 0, null, []));
+const structColumn = new Column(new Field('struct', structType), [
+ Vector.new(Data.Struct(structType, 0, 0, 0, null, [])),
+ Vector.new(Data.Struct(structType, 0, 0, 0, null, [])),
+ Vector.new(Data.Struct(structType, 0, 0, 0, null, [])),
+]);
+
+const [x1, y1, z1] = structVector.get(0)!;
+const [x2, y2, z2] = structColumn.get(0)!;
+
+console.log(x1, y1, z1);
+console.log(x2, y2, z2);
diff --git a/src/arrow/js/test/inference/nested.ts b/src/arrow/js/test/inference/nested.ts
new file mode 100644
index 000000000..0e3dc95e3
--- /dev/null
+++ b/src/arrow/js/test/inference/nested.ts
@@ -0,0 +1,62 @@
+// 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 { Data } from 'apache-arrow/data';
+import { Field } from 'apache-arrow/schema';
+import { DataType } from 'apache-arrow/type';
+import { Vector, BoolVector } from 'apache-arrow/vector/index';
+import { Bool, Int8, Utf8, List, Dictionary, Struct } from 'apache-arrow/type';
+
+type NamedSchema = { a: Int8; b: Utf8; c: Dictionary<List<Bool>>; [idx: string]: DataType };
+type IndexSchema = { 0: Int8; 1: Utf8; 2: Dictionary<List<Bool>>; [idx: number]: DataType };
+
+checkIndexTypes({ 0: new Int8(), 1: new Utf8(), 2: new Dictionary<List<Bool>>(null!, null!) } as IndexSchema);
+checkNamedTypes({ a: new Int8(), b: new Utf8(), c: new Dictionary<List<Bool>>(null!, null!) } as NamedSchema);
+
+function checkIndexTypes(schema: IndexSchema) {
+
+ const data = Data.Struct(new Struct<IndexSchema>(
+ Object.keys(schema).map((x) => new Field(x, schema[(<any> x)]))
+ ), 0, 0, 0, null, []);
+
+ const row = Vector.new(data).bind(0);
+
+ const check_0 = (x = row[0]) => expect(typeof x === 'number').toBe(true);
+ const check_1 = (x = row[1]) => expect(typeof x === 'string').toBe(true);
+ const check_2 = (x = row[2]) => expect(x instanceof BoolVector).toBe(true);
+
+ check_0(); check_0(row[0]); check_0(row.get(0));
+ check_1(); check_1(row[1]); check_1(row.get(1));
+ check_2(); check_2(row[2]); check_2(row.get(2));
+}
+
+function checkNamedTypes(schema: NamedSchema) {
+
+ const data = Data.Struct(new Struct<NamedSchema>(
+ Object.keys(schema).map((x) => new Field(x, schema[x]))
+ ), 0, 0, 0, null, []);
+
+ const row = Vector.new(data).bind(0);
+
+ const check_a = (x = row.a) => expect(typeof x === 'number').toBe(true);
+ const check_b = (x = row.b) => expect(typeof x === 'string').toBe(true);
+ const check_c = (x = row.c) => expect(x instanceof BoolVector).toBe(true);
+
+ check_a(); check_a(row.a); check_a(row.get('a'));
+ check_b(); check_b(row.b); check_b(row.get('b'));
+ check_c(); check_c(row.c); check_c(row.get('c'));
+}
diff --git a/src/arrow/js/test/inference/visitor/get.ts b/src/arrow/js/test/inference/visitor/get.ts
new file mode 100644
index 000000000..a983d94d1
--- /dev/null
+++ b/src/arrow/js/test/inference/visitor/get.ts
@@ -0,0 +1,56 @@
+// 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 {
+ Data, Vector,
+ Bool, List, Dictionary
+} from '../../Arrow';
+
+import { instance as getVisitor } from 'apache-arrow/visitor/get';
+
+const data_Bool = new Data(new Bool(), 0, 0);
+const data_List_Bool = new Data(new List<Bool>(null as any), 0, 0);
+const data_Dictionary_Bool = new Data(new Dictionary<Bool>(null!, null!), 0, 0);
+const data_Dictionary_List_Bool = new Data(new Dictionary<List<Bool>>(null!, null!), 0, 0);
+
+const boolVec = Vector.new(data_Bool);
+const boolVec_getRaw = boolVec.get(0);
+const boolVec_getVisit = getVisitor.visit(boolVec, 0);
+const boolVec_getFactory = getVisitor.getVisitFn(boolVec)(boolVec, 0);
+const boolVec_getFactoryData = getVisitor.getVisitFn(boolVec.data)(boolVec, 0);
+const boolVec_getFactoryType = getVisitor.getVisitFn(boolVec.type)(boolVec, 0);
+
+const listVec = Vector.new(data_List_Bool);
+const listVec_getRaw = listVec.get(0);
+const listVec_getVisit = getVisitor.visit(listVec, 0);
+const listVec_getFactory = getVisitor.getVisitFn(listVec)(listVec, 0);
+const listVec_getFactoryData = getVisitor.getVisitFn(listVec.data)(listVec, 0);
+const listVec_getFactoryType = getVisitor.getVisitFn(listVec.type)(listVec, 0);
+
+const dictVec = Vector.new(data_Dictionary_Bool);
+const dictVec_getRaw = dictVec.get(0);
+const dictVec_getVisit = getVisitor.visit(dictVec, 0);
+const dictVec_getFactory = getVisitor.getVisitFn(dictVec)(dictVec, 0);
+const dictVec_getFactoryData = getVisitor.getVisitFn(dictVec.data)(dictVec, 0);
+const dictVec_getFactoryType = getVisitor.getVisitFn(dictVec.type)(dictVec, 0);
+
+const dictOfListVec = Vector.new(data_Dictionary_List_Bool);
+const dictOfListVec_getRaw = dictOfListVec.get(0);
+const dictOfListVec_getVisit = getVisitor.visit(dictOfListVec, 0);
+const dictOfListVec_getFactory = getVisitor.getVisitFn(dictOfListVec)(dictOfListVec, 0);
+const dictOfListVec_getFactoryData = getVisitor.getVisitFn(dictOfListVec.data)(dictOfListVec, 0);
+const dictOfListVec_getFactoryType = getVisitor.getVisitFn(dictOfListVec.type)(dictOfListVec, 0);