-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtypeassembler.ts
More file actions
177 lines (171 loc) · 6.93 KB
/
typeassembler.ts
File metadata and controls
177 lines (171 loc) · 6.93 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// 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 * as flatbuffers from 'flatbuffers';
import Builder = flatbuffers.Builder;
import * as type from '../type.js';
import { Visitor } from '../visitor.js';
import { Null } from '../fb/null.js';
import { Int } from '../fb/int.js';
import { FloatingPoint } from '../fb/floating-point.js';
import { Binary } from '../fb/binary.js';
import { LargeBinary } from '../fb/large-binary.js';
import { Bool } from '../fb/bool.js';
import { Utf8 } from '../fb/utf8.js';
import { LargeUtf8 } from '../fb/large-utf8.js';
import { Decimal } from '../fb/decimal.js';
import { Date } from '../fb/date.js';
import { Time } from '../fb/time.js';
import { Timestamp } from '../fb/timestamp.js';
import { Interval } from '../fb/interval.js';
import { Duration } from '../fb/duration.js';
import { List } from '../fb/list.js';
import { LargeList } from '../fb/large-list.js';
import { Struct_ as Struct } from '../fb/struct-.js';
import { Union } from '../fb/union.js';
import { DictionaryEncoding } from '../fb/dictionary-encoding.js';
import { FixedSizeBinary } from '../fb/fixed-size-binary.js';
import { FixedSizeList } from '../fb/fixed-size-list.js';
import { Map as Map_ } from '../fb/map.js';
/** @ignore */
export interface TypeAssembler extends Visitor {
visit<T extends type.DataType>(node: T, builder: Builder): number | undefined;
}
/** @ignore */
export class TypeAssembler extends Visitor {
public visit<T extends type.DataType>(node: T, builder: Builder): number | undefined {
return (node == null || builder == null) ? undefined : super.visit(node, builder);
}
public visitNull<T extends type.Null>(_node: T, b: Builder) {
Null.startNull(b);
return Null.endNull(b);
}
public visitInt<T extends type.Int>(node: T, b: Builder) {
Int.startInt(b);
Int.addBitWidth(b, node.bitWidth);
Int.addIsSigned(b, node.isSigned);
return Int.endInt(b);
}
public visitFloat<T extends type.Float>(node: T, b: Builder) {
FloatingPoint.startFloatingPoint(b);
FloatingPoint.addPrecision(b, node.precision);
return FloatingPoint.endFloatingPoint(b);
}
public visitBinary<T extends type.Binary>(_node: T, b: Builder) {
Binary.startBinary(b);
return Binary.endBinary(b);
}
public visitLargeBinary<T extends type.LargeBinary>(_node: T, b: Builder) {
LargeBinary.startLargeBinary(b);
return LargeBinary.endLargeBinary(b);
}
public visitBool<T extends type.Bool>(_node: T, b: Builder) {
Bool.startBool(b);
return Bool.endBool(b);
}
public visitUtf8<T extends type.Utf8>(_node: T, b: Builder) {
Utf8.startUtf8(b);
return Utf8.endUtf8(b);
}
public visitLargeUtf8<T extends type.LargeUtf8>(_node: T, b: Builder) {
LargeUtf8.startLargeUtf8(b);
return LargeUtf8.endLargeUtf8(b);
}
public visitDecimal<T extends type.Decimal>(node: T, b: Builder) {
Decimal.startDecimal(b);
Decimal.addScale(b, node.scale);
Decimal.addPrecision(b, node.precision);
Decimal.addBitWidth(b, node.bitWidth);
return Decimal.endDecimal(b);
}
public visitDate<T extends type.Date_>(node: T, b: Builder) {
Date.startDate(b);
Date.addUnit(b, node.unit);
return Date.endDate(b);
}
public visitTime<T extends type.Time>(node: T, b: Builder) {
Time.startTime(b);
Time.addUnit(b, node.unit);
Time.addBitWidth(b, node.bitWidth);
return Time.endTime(b);
}
public visitTimestamp<T extends type.Timestamp>(node: T, b: Builder) {
const timezone = (node.timezone && b.createString(node.timezone)) || undefined;
Timestamp.startTimestamp(b);
Timestamp.addUnit(b, node.unit);
if (timezone !== undefined) {
Timestamp.addTimezone(b, timezone);
}
return Timestamp.endTimestamp(b);
}
public visitInterval<T extends type.Interval>(node: T, b: Builder) {
Interval.startInterval(b);
Interval.addUnit(b, node.unit);
return Interval.endInterval(b);
}
public visitDuration<T extends type.Duration>(node: T, b: Builder) {
Duration.startDuration(b);
Duration.addUnit(b, node.unit);
return Duration.endDuration(b);
}
public visitList<T extends type.List>(_node: T, b: Builder) {
List.startList(b);
return List.endList(b);
}
public visitLargeList<T extends type.LargeList>(_node: T, b: Builder) {
LargeList.startLargeList(b);
return LargeList.endLargeList(b);
}
public visitStruct<T extends type.Struct>(_node: T, b: Builder) {
Struct.startStruct_(b);
return Struct.endStruct_(b);
}
public visitUnion<T extends type.Union>(node: T, b: Builder) {
Union.startTypeIdsVector(b, node.typeIds.length);
const typeIds = Union.createTypeIdsVector(b, node.typeIds);
Union.startUnion(b);
Union.addMode(b, node.mode);
Union.addTypeIds(b, typeIds);
return Union.endUnion(b);
}
public visitDictionary<T extends type.Dictionary>(node: T, b: Builder) {
const indexType = this.visit(node.indices, b);
DictionaryEncoding.startDictionaryEncoding(b);
DictionaryEncoding.addId(b, BigInt(node.id));
DictionaryEncoding.addIsOrdered(b, node.isOrdered);
if (indexType !== undefined) {
DictionaryEncoding.addIndexType(b, indexType);
}
return DictionaryEncoding.endDictionaryEncoding(b);
}
public visitFixedSizeBinary<T extends type.FixedSizeBinary>(node: T, b: Builder) {
FixedSizeBinary.startFixedSizeBinary(b);
FixedSizeBinary.addByteWidth(b, node.byteWidth);
return FixedSizeBinary.endFixedSizeBinary(b);
}
public visitFixedSizeList<T extends type.FixedSizeList>(node: T, b: Builder) {
FixedSizeList.startFixedSizeList(b);
FixedSizeList.addListSize(b, node.listSize);
return FixedSizeList.endFixedSizeList(b);
}
public visitMap<T extends type.Map_>(node: T, b: Builder) {
Map_.startMap(b);
Map_.addKeysSorted(b, node.keysSorted);
return Map_.endMap(b);
}
}
/** @ignore */
export const instance = new TypeAssembler();