]>
Commit | Line | Data |
---|---|---|
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 | ||
18 | import { Data } from '../data'; | |
19 | import { Type } from '../enum'; | |
20 | import { Visitor } from '../visitor'; | |
21 | import { VectorType } from '../interfaces'; | |
22 | import { instance as iteratorVisitor } from './iterator'; | |
23 | import { | |
24 | DataType, Dictionary, | |
25 | Bool, Null, Utf8, Binary, Decimal, FixedSizeBinary, List, FixedSizeList, Map_, Struct, | |
26 | Float, Float16, Float32, Float64, | |
27 | Int, Uint8, Uint16, Uint32, Uint64, Int8, Int16, Int32, Int64, | |
28 | Date_, DateDay, DateMillisecond, | |
29 | Interval, IntervalDayTime, IntervalYearMonth, | |
30 | Time, TimeSecond, TimeMillisecond, TimeMicrosecond, TimeNanosecond, | |
31 | Timestamp, TimestampSecond, TimestampMillisecond, TimestampMicrosecond, TimestampNanosecond, | |
32 | Union, DenseUnion, SparseUnion, | |
33 | } from '../type'; | |
34 | ||
35 | /** @ignore */ | |
36 | export interface ToArrayVisitor extends Visitor { | |
37 | visit<T extends VectorType>(node: T): T['TArray']; | |
38 | visitMany<T extends VectorType>(nodes: T[]): T['TArray'][]; | |
39 | getVisitFn<T extends Type>(node: T): (vector: VectorType<T>) => VectorType<T>['TArray']; | |
40 | getVisitFn<T extends DataType>(node: VectorType<T> | Data<T> | T): (vector: VectorType<T>) => VectorType<T>['TArray']; | |
41 | visitNull <T extends Null> (vector: VectorType<T>): VectorType<T>['TArray']; | |
42 | visitBool <T extends Bool> (vector: VectorType<T>): VectorType<T>['TArray']; | |
43 | visitInt <T extends Int> (vector: VectorType<T>): VectorType<T>['TArray']; | |
44 | visitInt8 <T extends Int8> (vector: VectorType<T>): VectorType<T>['TArray']; | |
45 | visitInt16 <T extends Int16> (vector: VectorType<T>): VectorType<T>['TArray']; | |
46 | visitInt32 <T extends Int32> (vector: VectorType<T>): VectorType<T>['TArray']; | |
47 | visitInt64 <T extends Int64> (vector: VectorType<T>): VectorType<T>['TArray']; | |
48 | visitUint8 <T extends Uint8> (vector: VectorType<T>): VectorType<T>['TArray']; | |
49 | visitUint16 <T extends Uint16> (vector: VectorType<T>): VectorType<T>['TArray']; | |
50 | visitUint32 <T extends Uint32> (vector: VectorType<T>): VectorType<T>['TArray']; | |
51 | visitUint64 <T extends Uint64> (vector: VectorType<T>): VectorType<T>['TArray']; | |
52 | visitFloat <T extends Float> (vector: VectorType<T>): VectorType<T>['TArray']; | |
53 | visitFloat16 <T extends Float16> (vector: VectorType<T>): VectorType<T>['TArray']; | |
54 | visitFloat32 <T extends Float32> (vector: VectorType<T>): VectorType<T>['TArray']; | |
55 | visitFloat64 <T extends Float64> (vector: VectorType<T>): VectorType<T>['TArray']; | |
56 | visitUtf8 <T extends Utf8> (vector: VectorType<T>): VectorType<T>['TArray']; | |
57 | visitBinary <T extends Binary> (vector: VectorType<T>): VectorType<T>['TArray']; | |
58 | visitFixedSizeBinary <T extends FixedSizeBinary> (vector: VectorType<T>): VectorType<T>['TArray']; | |
59 | visitDate <T extends Date_> (vector: VectorType<T>): VectorType<T>['TArray']; | |
60 | visitDateDay <T extends DateDay> (vector: VectorType<T>): VectorType<T>['TArray']; | |
61 | visitDateMillisecond <T extends DateMillisecond> (vector: VectorType<T>): VectorType<T>['TArray']; | |
62 | visitTimestamp <T extends Timestamp> (vector: VectorType<T>): VectorType<T>['TArray']; | |
63 | visitTimestampSecond <T extends TimestampSecond> (vector: VectorType<T>): VectorType<T>['TArray']; | |
64 | visitTimestampMillisecond <T extends TimestampMillisecond>(vector: VectorType<T>): VectorType<T>['TArray']; | |
65 | visitTimestampMicrosecond <T extends TimestampMicrosecond>(vector: VectorType<T>): VectorType<T>['TArray']; | |
66 | visitTimestampNanosecond <T extends TimestampNanosecond> (vector: VectorType<T>): VectorType<T>['TArray']; | |
67 | visitTime <T extends Time> (vector: VectorType<T>): VectorType<T>['TArray']; | |
68 | visitTimeSecond <T extends TimeSecond> (vector: VectorType<T>): VectorType<T>['TArray']; | |
69 | visitTimeMillisecond <T extends TimeMillisecond> (vector: VectorType<T>): VectorType<T>['TArray']; | |
70 | visitTimeMicrosecond <T extends TimeMicrosecond> (vector: VectorType<T>): VectorType<T>['TArray']; | |
71 | visitTimeNanosecond <T extends TimeNanosecond> (vector: VectorType<T>): VectorType<T>['TArray']; | |
72 | visitDecimal <T extends Decimal> (vector: VectorType<T>): VectorType<T>['TArray']; | |
73 | visitList <R extends DataType, T extends List<R>> (vector: VectorType<T>): VectorType<T>['TArray']; | |
74 | visitStruct <T extends Struct> (vector: VectorType<T>): VectorType<T>['TArray']; | |
75 | visitUnion <T extends Union> (vector: VectorType<T>): VectorType<T>['TArray']; | |
76 | visitDenseUnion <T extends DenseUnion> (vector: VectorType<T>): VectorType<T>['TArray']; | |
77 | visitSparseUnion <T extends SparseUnion> (vector: VectorType<T>): VectorType<T>['TArray']; | |
78 | visitDictionary <R extends DataType, T extends Dictionary<R>> (vector: VectorType<T>): VectorType<T>['TArray']; | |
79 | visitInterval <T extends Interval> (vector: VectorType<T>): VectorType<T>['TArray']; | |
80 | visitIntervalDayTime <T extends IntervalDayTime> (vector: VectorType<T>): VectorType<T>['TArray']; | |
81 | visitIntervalYearMonth <T extends IntervalYearMonth> (vector: VectorType<T>): VectorType<T>['TArray']; | |
82 | visitFixedSizeList <R extends DataType, T extends FixedSizeList<R>> (vector: VectorType<T>): VectorType<T>['TArray']; | |
83 | visitMap <T extends Map_> (vector: VectorType<T>): VectorType<T>['TArray']; | |
84 | } | |
85 | ||
86 | /** @ignore */ | |
87 | export class ToArrayVisitor extends Visitor {} | |
88 | ||
89 | /** @ignore */ | |
90 | function arrayOfVector<T extends DataType>(vector: VectorType<T>): T['TArray'] { | |
91 | ||
92 | const { type, length, stride } = vector; | |
93 | ||
94 | // Fast case, return subarray if possible | |
95 | switch (type.typeId) { | |
96 | case Type.Int: | |
97 | case Type.Float: case Type.Decimal: | |
98 | case Type.Time: case Type.Timestamp: | |
99 | return vector.data.values.subarray(0, length * stride); | |
100 | } | |
101 | ||
102 | // Otherwise if not primitive, slow copy | |
103 | return [...iteratorVisitor.visit(vector)] as T['TArray']; | |
104 | } | |
105 | ||
106 | ToArrayVisitor.prototype.visitNull = arrayOfVector; | |
107 | ToArrayVisitor.prototype.visitBool = arrayOfVector; | |
108 | ToArrayVisitor.prototype.visitInt = arrayOfVector; | |
109 | ToArrayVisitor.prototype.visitInt8 = arrayOfVector; | |
110 | ToArrayVisitor.prototype.visitInt16 = arrayOfVector; | |
111 | ToArrayVisitor.prototype.visitInt32 = arrayOfVector; | |
112 | ToArrayVisitor.prototype.visitInt64 = arrayOfVector; | |
113 | ToArrayVisitor.prototype.visitUint8 = arrayOfVector; | |
114 | ToArrayVisitor.prototype.visitUint16 = arrayOfVector; | |
115 | ToArrayVisitor.prototype.visitUint32 = arrayOfVector; | |
116 | ToArrayVisitor.prototype.visitUint64 = arrayOfVector; | |
117 | ToArrayVisitor.prototype.visitFloat = arrayOfVector; | |
118 | ToArrayVisitor.prototype.visitFloat16 = arrayOfVector; | |
119 | ToArrayVisitor.prototype.visitFloat32 = arrayOfVector; | |
120 | ToArrayVisitor.prototype.visitFloat64 = arrayOfVector; | |
121 | ToArrayVisitor.prototype.visitUtf8 = arrayOfVector; | |
122 | ToArrayVisitor.prototype.visitBinary = arrayOfVector; | |
123 | ToArrayVisitor.prototype.visitFixedSizeBinary = arrayOfVector; | |
124 | ToArrayVisitor.prototype.visitDate = arrayOfVector; | |
125 | ToArrayVisitor.prototype.visitDateDay = arrayOfVector; | |
126 | ToArrayVisitor.prototype.visitDateMillisecond = arrayOfVector; | |
127 | ToArrayVisitor.prototype.visitTimestamp = arrayOfVector; | |
128 | ToArrayVisitor.prototype.visitTimestampSecond = arrayOfVector; | |
129 | ToArrayVisitor.prototype.visitTimestampMillisecond = arrayOfVector; | |
130 | ToArrayVisitor.prototype.visitTimestampMicrosecond = arrayOfVector; | |
131 | ToArrayVisitor.prototype.visitTimestampNanosecond = arrayOfVector; | |
132 | ToArrayVisitor.prototype.visitTime = arrayOfVector; | |
133 | ToArrayVisitor.prototype.visitTimeSecond = arrayOfVector; | |
134 | ToArrayVisitor.prototype.visitTimeMillisecond = arrayOfVector; | |
135 | ToArrayVisitor.prototype.visitTimeMicrosecond = arrayOfVector; | |
136 | ToArrayVisitor.prototype.visitTimeNanosecond = arrayOfVector; | |
137 | ToArrayVisitor.prototype.visitDecimal = arrayOfVector; | |
138 | ToArrayVisitor.prototype.visitList = arrayOfVector; | |
139 | ToArrayVisitor.prototype.visitStruct = arrayOfVector; | |
140 | ToArrayVisitor.prototype.visitUnion = arrayOfVector; | |
141 | ToArrayVisitor.prototype.visitDenseUnion = arrayOfVector; | |
142 | ToArrayVisitor.prototype.visitSparseUnion = arrayOfVector; | |
143 | ToArrayVisitor.prototype.visitDictionary = arrayOfVector; | |
144 | ToArrayVisitor.prototype.visitInterval = arrayOfVector; | |
145 | ToArrayVisitor.prototype.visitIntervalDayTime = arrayOfVector; | |
146 | ToArrayVisitor.prototype.visitIntervalYearMonth = arrayOfVector; | |
147 | ToArrayVisitor.prototype.visitFixedSizeList = arrayOfVector; | |
148 | ToArrayVisitor.prototype.visitMap = arrayOfVector; | |
149 | ||
150 | /** @ignore */ | |
151 | export const instance = new ToArrayVisitor(); |