1 | /** |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | */ |
18 | |
19 | #ifndef ORC_OPTIONS_HH |
20 | #define ORC_OPTIONS_HH |
21 | |
22 | #include "orc/Int128.hh" |
23 | #include "orc/OrcFile.hh" |
24 | #include "orc/Reader.hh" |
25 | |
26 | #include <limits> |
27 | |
28 | namespace orc { |
29 | |
30 | enum ColumnSelection { |
31 | ColumnSelection_NONE = 0, |
32 | ColumnSelection_NAMES = 1, |
33 | ColumnSelection_FIELD_IDS = 2, |
34 | ColumnSelection_TYPE_IDS = 3, |
35 | }; |
36 | |
37 | /** |
38 | * ReaderOptions Implementation |
39 | */ |
40 | struct ReaderOptionsPrivate { |
41 | uint64_t tailLocation; |
42 | std::ostream* errorStream; |
43 | MemoryPool* memoryPool; |
44 | std::string serializedTail; |
45 | |
46 | ReaderOptionsPrivate() { |
47 | tailLocation = std::numeric_limits<uint64_t>::max(); |
48 | errorStream = &std::cerr; |
49 | memoryPool = getDefaultPool(); |
50 | } |
51 | }; |
52 | |
53 | ReaderOptions::ReaderOptions(): |
54 | privateBits(std::unique_ptr<ReaderOptionsPrivate> |
55 | (new ReaderOptionsPrivate())) { |
56 | // PASS |
57 | } |
58 | |
59 | ReaderOptions::ReaderOptions(const ReaderOptions& rhs): |
60 | privateBits(std::unique_ptr<ReaderOptionsPrivate> |
61 | (new ReaderOptionsPrivate(*(rhs.privateBits.get())))) { |
62 | // PASS |
63 | } |
64 | |
65 | ReaderOptions::ReaderOptions(ReaderOptions& rhs) { |
66 | // swap privateBits with rhs |
67 | ReaderOptionsPrivate* l = privateBits.release(); |
68 | privateBits.reset(rhs.privateBits.release()); |
69 | rhs.privateBits.reset(l); |
70 | } |
71 | |
72 | ReaderOptions& ReaderOptions::operator=(const ReaderOptions& rhs) { |
73 | if (this != &rhs) { |
74 | privateBits.reset(new ReaderOptionsPrivate(*(rhs.privateBits.get()))); |
75 | } |
76 | return *this; |
77 | } |
78 | |
79 | ReaderOptions::~ReaderOptions() { |
80 | // PASS |
81 | } |
82 | |
83 | ReaderOptions& ReaderOptions::setMemoryPool(MemoryPool& pool) { |
84 | privateBits->memoryPool = &pool; |
85 | return *this; |
86 | } |
87 | |
88 | MemoryPool* ReaderOptions::getMemoryPool() const{ |
89 | return privateBits->memoryPool; |
90 | } |
91 | |
92 | ReaderOptions& ReaderOptions::setTailLocation(uint64_t offset) { |
93 | privateBits->tailLocation = offset; |
94 | return *this; |
95 | } |
96 | |
97 | uint64_t ReaderOptions::getTailLocation() const { |
98 | return privateBits->tailLocation; |
99 | } |
100 | |
101 | ReaderOptions& ReaderOptions::setSerializedFileTail(const std::string& value |
102 | ) { |
103 | privateBits->serializedTail = value; |
104 | return *this; |
105 | } |
106 | |
107 | std::string ReaderOptions::getSerializedFileTail() const { |
108 | return privateBits->serializedTail; |
109 | } |
110 | |
111 | ReaderOptions& ReaderOptions::setErrorStream(std::ostream& stream) { |
112 | privateBits->errorStream = &stream; |
113 | return *this; |
114 | } |
115 | |
116 | std::ostream* ReaderOptions::getErrorStream() const { |
117 | return privateBits->errorStream; |
118 | } |
119 | |
120 | /** |
121 | * RowReaderOptions Implementation |
122 | */ |
123 | |
124 | struct RowReaderOptionsPrivate { |
125 | ColumnSelection selection; |
126 | std::list<uint64_t> includedColumnIndexes; |
127 | std::list<std::string> includedColumnNames; |
128 | uint64_t dataStart; |
129 | uint64_t dataLength; |
130 | bool throwOnHive11DecimalOverflow; |
131 | int32_t forcedScaleOnHive11Decimal; |
132 | |
133 | RowReaderOptionsPrivate() { |
134 | selection = ColumnSelection_NONE; |
135 | dataStart = 0; |
136 | dataLength = std::numeric_limits<uint64_t>::max(); |
137 | throwOnHive11DecimalOverflow = true; |
138 | forcedScaleOnHive11Decimal = 6; |
139 | } |
140 | }; |
141 | |
142 | RowReaderOptions::RowReaderOptions(): |
143 | privateBits(std::unique_ptr<RowReaderOptionsPrivate> |
144 | (new RowReaderOptionsPrivate())) { |
145 | // PASS |
146 | } |
147 | |
148 | RowReaderOptions::RowReaderOptions(const RowReaderOptions& rhs): |
149 | privateBits(std::unique_ptr<RowReaderOptionsPrivate> |
150 | (new RowReaderOptionsPrivate(*(rhs.privateBits.get())))) { |
151 | // PASS |
152 | } |
153 | |
154 | RowReaderOptions::RowReaderOptions(RowReaderOptions& rhs) { |
155 | // swap privateBits with rhs |
156 | RowReaderOptionsPrivate* l = privateBits.release(); |
157 | privateBits.reset(rhs.privateBits.release()); |
158 | rhs.privateBits.reset(l); |
159 | } |
160 | |
161 | RowReaderOptions& RowReaderOptions::operator=(const RowReaderOptions& rhs) { |
162 | if (this != &rhs) { |
163 | privateBits.reset(new RowReaderOptionsPrivate(*(rhs.privateBits.get()))); |
164 | } |
165 | return *this; |
166 | } |
167 | |
168 | RowReaderOptions::~RowReaderOptions() { |
169 | // PASS |
170 | } |
171 | |
172 | RowReaderOptions& RowReaderOptions::include(const std::list<uint64_t>& include) { |
173 | privateBits->selection = ColumnSelection_FIELD_IDS; |
174 | privateBits->includedColumnIndexes.assign(include.begin(), include.end()); |
175 | privateBits->includedColumnNames.clear(); |
176 | return *this; |
177 | } |
178 | |
179 | RowReaderOptions& RowReaderOptions::include(const std::list<std::string>& include) { |
180 | privateBits->selection = ColumnSelection_NAMES; |
181 | privateBits->includedColumnNames.assign(include.begin(), include.end()); |
182 | privateBits->includedColumnIndexes.clear(); |
183 | return *this; |
184 | } |
185 | |
186 | RowReaderOptions& RowReaderOptions::includeTypes(const std::list<uint64_t>& types) { |
187 | privateBits->selection = ColumnSelection_TYPE_IDS; |
188 | privateBits->includedColumnIndexes.assign(types.begin(), types.end()); |
189 | privateBits->includedColumnNames.clear(); |
190 | return *this; |
191 | } |
192 | |
193 | RowReaderOptions& RowReaderOptions::range(uint64_t offset, uint64_t length) { |
194 | privateBits->dataStart = offset; |
195 | privateBits->dataLength = length; |
196 | return *this; |
197 | } |
198 | |
199 | bool RowReaderOptions::getIndexesSet() const { |
200 | return privateBits->selection == ColumnSelection_FIELD_IDS; |
201 | } |
202 | |
203 | bool RowReaderOptions::getTypeIdsSet() const { |
204 | return privateBits->selection == ColumnSelection_TYPE_IDS; |
205 | } |
206 | |
207 | const std::list<uint64_t>& RowReaderOptions::getInclude() const { |
208 | return privateBits->includedColumnIndexes; |
209 | } |
210 | |
211 | bool RowReaderOptions::getNamesSet() const { |
212 | return privateBits->selection == ColumnSelection_NAMES; |
213 | } |
214 | |
215 | const std::list<std::string>& RowReaderOptions::getIncludeNames() const { |
216 | return privateBits->includedColumnNames; |
217 | } |
218 | |
219 | uint64_t RowReaderOptions::getOffset() const { |
220 | return privateBits->dataStart; |
221 | } |
222 | |
223 | uint64_t RowReaderOptions::getLength() const { |
224 | return privateBits->dataLength; |
225 | } |
226 | |
227 | RowReaderOptions& RowReaderOptions::throwOnHive11DecimalOverflow(bool shouldThrow){ |
228 | privateBits->throwOnHive11DecimalOverflow = shouldThrow; |
229 | return *this; |
230 | } |
231 | |
232 | bool RowReaderOptions::getThrowOnHive11DecimalOverflow() const { |
233 | return privateBits->throwOnHive11DecimalOverflow; |
234 | } |
235 | |
236 | RowReaderOptions& RowReaderOptions::forcedScaleOnHive11Decimal(int32_t forcedScale |
237 | ) { |
238 | privateBits->forcedScaleOnHive11Decimal = forcedScale; |
239 | return *this; |
240 | } |
241 | |
242 | int32_t RowReaderOptions::getForcedScaleOnHive11Decimal() const { |
243 | return privateBits->forcedScaleOnHive11Decimal; |
244 | } |
245 | } |
246 | |
247 | #endif |
248 | |