-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
Copy pathArrowArrayFactory.cs
121 lines (118 loc) · 5.14 KB
/
ArrowArrayFactory.cs
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
// 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.
using Apache.Arrow.Arrays;
using Apache.Arrow.Types;
using System;
namespace Apache.Arrow
{
public static class ArrowArrayFactory
{
public static IArrowArray BuildArray(ArrayData data)
{
switch (data.DataType.TypeId)
{
case ArrowTypeId.Null:
return new NullArray(data);
case ArrowTypeId.Boolean:
return new BooleanArray(data);
case ArrowTypeId.UInt8:
return new UInt8Array(data);
case ArrowTypeId.Int8:
return new Int8Array(data);
case ArrowTypeId.UInt16:
return new UInt16Array(data);
case ArrowTypeId.Int16:
return new Int16Array(data);
case ArrowTypeId.UInt32:
return new UInt32Array(data);
case ArrowTypeId.Int32:
return new Int32Array(data);
case ArrowTypeId.UInt64:
return new UInt64Array(data);
case ArrowTypeId.Int64:
return new Int64Array(data);
case ArrowTypeId.Float:
return new FloatArray(data);
case ArrowTypeId.Double:
return new DoubleArray(data);
case ArrowTypeId.String:
return new StringArray(data);
case ArrowTypeId.StringView:
return new StringViewArray(data);
case ArrowTypeId.LargeString:
return new LargeStringArray(data);
case ArrowTypeId.FixedSizedBinary:
return new FixedSizeBinaryArray(data);
case ArrowTypeId.Binary:
return new BinaryArray(data);
case ArrowTypeId.BinaryView:
return new BinaryViewArray(data);
case ArrowTypeId.LargeBinary:
return new LargeBinaryArray(data);
case ArrowTypeId.Timestamp:
return new TimestampArray(data);
case ArrowTypeId.List:
return new ListArray(data);
case ArrowTypeId.ListView:
return new ListViewArray(data);
case ArrowTypeId.LargeList:
return new LargeListArray(data);
case ArrowTypeId.Map:
return new MapArray(data);
case ArrowTypeId.Struct:
return new StructArray(data);
case ArrowTypeId.Union:
return UnionArray.Create(data);
case ArrowTypeId.Date64:
return new Date64Array(data);
case ArrowTypeId.Date32:
return new Date32Array(data);
case ArrowTypeId.Time32:
return new Time32Array(data);
case ArrowTypeId.Time64:
return new Time64Array(data);
case ArrowTypeId.Duration:
return new DurationArray(data);
case ArrowTypeId.Decimal32:
return new Decimal32Array(data);
case ArrowTypeId.Decimal64:
return new Decimal64Array(data);
case ArrowTypeId.Decimal128:
return new Decimal128Array(data);
case ArrowTypeId.Decimal256:
return new Decimal256Array(data);
case ArrowTypeId.Dictionary:
return new DictionaryArray(data);
case ArrowTypeId.HalfFloat:
#if NET5_0_OR_GREATER
return new HalfFloatArray(data);
#else
throw new NotSupportedException("Half-float arrays are not supported by this target framework.");
#endif
case ArrowTypeId.FixedSizeList:
return new FixedSizeListArray(data);
case ArrowTypeId.Interval:
return IntervalArray.Create(data);
default:
throw new NotSupportedException($"An ArrowArray cannot be built for type {data.DataType.TypeId}.");
}
}
public static IArrowArray Slice(IArrowArray array, int offset, int length)
{
ArrayData newData = array.Data.Slice(offset, length);
return BuildArray(newData);
}
}
}