-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
datatype_binary.go
139 lines (123 loc) · 5.79 KB
/
datatype_binary.go
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
// 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.
package arrow
// OffsetTraits is a convenient interface over the various type traits
// constants such as arrow.Int32Traits allowing types with offsets, like
// BinaryType, StringType, LargeBinaryType and LargeStringType to have
// a method to return information about their offset type and how many bytes
// would be required to allocate an offset buffer for them.
type OffsetTraits interface {
// BytesRequired returns the number of bytes required to be allocated
// in order to hold the passed in number of elements of this type.
BytesRequired(int) int
}
type BinaryType struct{}
func (t *BinaryType) ID() Type { return BINARY }
func (t *BinaryType) Name() string { return "binary" }
func (t *BinaryType) String() string { return "binary" }
func (t *BinaryType) binary() {}
func (t *BinaryType) Fingerprint() string { return typeFingerprint(t) }
func (t *BinaryType) Layout() DataTypeLayout {
return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
SpecFixedWidth(Int32SizeBytes), SpecVariableWidth()}}
}
func (t *BinaryType) OffsetTypeTraits() OffsetTraits { return Int32Traits }
func (BinaryType) IsUtf8() bool { return false }
type StringType struct{}
func (t *StringType) ID() Type { return STRING }
func (t *StringType) Name() string { return "utf8" }
func (t *StringType) String() string { return "utf8" }
func (t *StringType) binary() {}
func (t *StringType) Fingerprint() string { return typeFingerprint(t) }
func (t *StringType) Layout() DataTypeLayout {
return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
SpecFixedWidth(Int32SizeBytes), SpecVariableWidth()}}
}
func (t *StringType) OffsetTypeTraits() OffsetTraits { return Int32Traits }
func (StringType) IsUtf8() bool { return true }
type LargeBinaryType struct{}
func (t *LargeBinaryType) ID() Type { return LARGE_BINARY }
func (t *LargeBinaryType) Name() string { return "large_binary" }
func (t *LargeBinaryType) String() string { return "large_binary" }
func (t *LargeBinaryType) binary() {}
func (t *LargeBinaryType) Fingerprint() string { return typeFingerprint(t) }
func (t *LargeBinaryType) Layout() DataTypeLayout {
return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
SpecFixedWidth(Int64SizeBytes), SpecVariableWidth()}}
}
func (t *LargeBinaryType) OffsetTypeTraits() OffsetTraits { return Int64Traits }
func (LargeBinaryType) IsUtf8() bool { return false }
type LargeStringType struct{}
func (t *LargeStringType) ID() Type { return LARGE_STRING }
func (t *LargeStringType) Name() string { return "large_utf8" }
func (t *LargeStringType) String() string { return "large_utf8" }
func (t *LargeStringType) binary() {}
func (t *LargeStringType) Fingerprint() string { return typeFingerprint(t) }
func (t *LargeStringType) Layout() DataTypeLayout {
return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
SpecFixedWidth(Int64SizeBytes), SpecVariableWidth()}}
}
func (t *LargeStringType) OffsetTypeTraits() OffsetTraits { return Int64Traits }
func (LargeStringType) IsUtf8() bool { return true }
type BinaryViewType struct{}
func (*BinaryViewType) ID() Type { return BINARY_VIEW }
func (*BinaryViewType) Name() string { return "binary_view" }
func (*BinaryViewType) String() string { return "binary_view" }
func (*BinaryViewType) IsUtf8() bool { return false }
func (*BinaryViewType) binary() {}
func (*BinaryViewType) view() {}
func (t *BinaryViewType) Fingerprint() string { return typeFingerprint(t) }
func (*BinaryViewType) Layout() DataTypeLayout {
variadic := SpecVariableWidth()
return DataTypeLayout{
Buffers: []BufferSpec{SpecBitmap(), SpecFixedWidth(ViewHeaderSizeBytes)},
VariadicSpec: &variadic,
}
}
type StringViewType struct{}
func (*StringViewType) ID() Type { return STRING_VIEW }
func (*StringViewType) Name() string { return "string_view" }
func (*StringViewType) String() string { return "string_view" }
func (*StringViewType) IsUtf8() bool { return true }
func (*StringViewType) binary() {}
func (*StringViewType) view() {}
func (t *StringViewType) Fingerprint() string { return typeFingerprint(t) }
func (*StringViewType) Layout() DataTypeLayout {
variadic := SpecVariableWidth()
return DataTypeLayout{
Buffers: []BufferSpec{SpecBitmap(), SpecFixedWidth(ViewHeaderSizeBytes)},
VariadicSpec: &variadic,
}
}
var (
BinaryTypes = struct {
Binary BinaryDataType
String BinaryDataType
LargeBinary BinaryDataType
LargeString BinaryDataType
BinaryView BinaryDataType
StringView BinaryDataType
}{
Binary: &BinaryType{},
String: &StringType{},
LargeBinary: &LargeBinaryType{},
LargeString: &LargeStringType{},
BinaryView: &BinaryViewType{},
StringView: &StringViewType{},
}
_ BinaryViewDataType = (*StringViewType)(nil)
_ BinaryViewDataType = (*BinaryViewType)(nil)
)