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_STRIPE_STREAM_HH
20#define ORC_STRIPE_STREAM_HH
21
22#include "orc/Int128.hh"
23#include "orc/OrcFile.hh"
24#include "orc/Reader.hh"
25
26#include "Timezone.hh"
27#include "TypeImpl.hh"
28
29namespace orc {
30
31 class RowReaderImpl;
32
33 /**
34 * StripeStream Implementation
35 */
36
37 class StripeStreamsImpl: public StripeStreams {
38 private:
39 const RowReaderImpl& reader;
40 const proto::StripeFooter& footer;
41 const uint64_t stripeStart;
42 InputStream& input;
43 const Timezone& writerTimezone;
44
45 public:
46 StripeStreamsImpl(const RowReaderImpl& reader,
47 const proto::StripeFooter& footer,
48 uint64_t stripeStart,
49 InputStream& input,
50 const Timezone& writerTimezone);
51
52 virtual ~StripeStreamsImpl() override;
53
54 virtual const std::vector<bool> getSelectedColumns() const override;
55
56 virtual proto::ColumnEncoding getEncoding(uint64_t columnId
57 ) const override;
58
59 virtual std::unique_ptr<SeekableInputStream>
60 getStream(uint64_t columnId,
61 proto::Stream_Kind kind,
62 bool shouldStream) const override;
63
64 MemoryPool& getMemoryPool() const override;
65
66 const Timezone& getWriterTimezone() const override;
67
68 std::ostream* getErrorStream() const override;
69
70 bool getThrowOnHive11DecimalOverflow() const override;
71
72 int32_t getForcedScaleOnHive11Decimal() const override;
73 };
74
75 /**
76 * StreamInformation Implementation
77 */
78
79 class StreamInformationImpl: public StreamInformation {
80 private:
81 StreamKind kind;
82 uint64_t column;
83 uint64_t offset;
84 uint64_t length;
85 public:
86 StreamInformationImpl(uint64_t _offset,
87 const proto::Stream& stream
88 ): kind(static_cast<StreamKind>(stream.kind())),
89 column(stream.column()),
90 offset(_offset),
91 length(stream.length()) {
92 // PASS
93 }
94
95 ~StreamInformationImpl() override;
96
97 StreamKind getKind() const override {
98 return kind;
99 }
100
101 uint64_t getColumnId() const override {
102 return column;
103 }
104
105 uint64_t getOffset() const override {
106 return offset;
107 }
108
109 uint64_t getLength() const override {
110 return length;
111 }
112 };
113
114 /**
115 * StripeInformation Implementation
116 */
117
118 class StripeInformationImpl : public StripeInformation {
119 uint64_t offset;
120 uint64_t indexLength;
121 uint64_t dataLength;
122 uint64_t footerLength;
123 uint64_t numRows;
124 InputStream* stream;
125 MemoryPool& memory;
126 CompressionKind compression;
127 uint64_t blockSize;
128 mutable std::unique_ptr<proto::StripeFooter> stripeFooter;
129 void ensureStripeFooterLoaded() const;
130 public:
131
132 StripeInformationImpl(uint64_t _offset,
133 uint64_t _indexLength,
134 uint64_t _dataLength,
135 uint64_t _footerLength,
136 uint64_t _numRows,
137 InputStream* _stream,
138 MemoryPool& _memory,
139 CompressionKind _compression,
140 uint64_t _blockSize
141 ) : offset(_offset),
142 indexLength(_indexLength),
143 dataLength(_dataLength),
144 footerLength(_footerLength),
145 numRows(_numRows),
146 stream(_stream),
147 memory(_memory),
148 compression(_compression),
149 blockSize(_blockSize) {
150 // PASS
151 }
152
153 virtual ~StripeInformationImpl() override {
154 // PASS
155 }
156
157 uint64_t getOffset() const override {
158 return offset;
159 }
160
161 uint64_t getLength() const override {
162 return indexLength + dataLength + footerLength;
163 }
164 uint64_t getIndexLength() const override {
165 return indexLength;
166 }
167
168 uint64_t getDataLength()const override {
169 return dataLength;
170 }
171
172 uint64_t getFooterLength() const override {
173 return footerLength;
174 }
175
176 uint64_t getNumberOfRows() const override {
177 return numRows;
178 }
179
180 uint64_t getNumberOfStreams() const override {
181 ensureStripeFooterLoaded();
182 return static_cast<uint64_t>(stripeFooter->streams_size());
183 }
184
185 std::unique_ptr<StreamInformation> getStreamInformation(uint64_t streamId
186 ) const override;
187
188 ColumnEncodingKind getColumnEncoding(uint64_t colId) const override {
189 ensureStripeFooterLoaded();
190 return static_cast<ColumnEncodingKind>(stripeFooter->
191 columns(static_cast<int>(colId))
192 .kind());
193 }
194
195 uint64_t getDictionarySize(uint64_t colId) const override {
196 ensureStripeFooterLoaded();
197 return static_cast<ColumnEncodingKind>(stripeFooter->
198 columns(static_cast<int>(colId))
199 .dictionarysize());
200 }
201
202 const std::string& getWriterTimezone() const override {
203 ensureStripeFooterLoaded();
204 return stripeFooter->writertimezone();
205 }
206 };
207
208}
209
210#endif
211