Skip to content

Commit d75869f

Browse files
macvincentfacebook-github-bot
authored andcommitted
Support Chunking StreamData (#248)
Summary: Another feature in the new chunking policy described in this [doc](https://fburl.com/gdoc/gkdwwju1) is the ability to split large streams above a specified limit into smaller chunks. In this diff, we implement a `popChunk` method in each `StreamData` class to handle this functionality. With this feature we are not forced to encode extremely large streams into a single chunk. Integration will happen in the next diff. Reviewed By: helfman Differential Revision: D81824143
1 parent 301e886 commit d75869f

File tree

5 files changed

+1670
-0
lines changed

5 files changed

+1670
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "dwio/nimble/velox/StreamChunker.h"
18+
19+
namespace facebook::nimble {
20+
template <typename T>
21+
std::unique_ptr<StreamChunker> getStreamChunkerTyped(
22+
StreamData& streamData,
23+
const StreamChunkerOptions& options) {
24+
if (auto* contentStreamChunker =
25+
dynamic_cast<ContentStreamData<T>*>(&streamData)) {
26+
return std::make_unique<ContentStreamChunker<T>>(
27+
*contentStreamChunker, options);
28+
} else if (
29+
auto* nullableContentStreamData =
30+
dynamic_cast<NullableContentStreamData<T>*>(&streamData)) {
31+
// When there are no nulls in the NullableContentStreamData stream, we treat
32+
// it as a regular ContentStreamData stream.
33+
if (!streamData.hasNulls()) {
34+
return std::make_unique<
35+
ContentStreamChunker<T, NullableContentStreamData<T>>>(
36+
*nullableContentStreamData, options);
37+
}
38+
return std::make_unique<NullableContentStreamChunker<T>>(
39+
*nullableContentStreamData, options);
40+
} else if (
41+
auto* nullsStreamData = dynamic_cast<NullsStreamData*>(&streamData)) {
42+
return std::make_unique<NullsStreamChunker>(*nullsStreamData, options);
43+
}
44+
NIMBLE_UNREACHABLE(fmt::format("Unsupported streamData type"))
45+
}
46+
47+
std::unique_ptr<StreamChunker> getStreamChunker(
48+
StreamData& streamData,
49+
const StreamChunkerOptions& options) {
50+
const auto scalarKind = streamData.descriptor().scalarKind();
51+
switch (scalarKind) {
52+
#define HANDLE_SCALAR_KIND(kind, type) \
53+
case ScalarKind::kind: \
54+
return getStreamChunkerTyped<type>(streamData, options);
55+
HANDLE_SCALAR_KIND(Bool, bool);
56+
HANDLE_SCALAR_KIND(Int8, int8_t);
57+
HANDLE_SCALAR_KIND(Int16, int16_t);
58+
HANDLE_SCALAR_KIND(Int32, int32_t);
59+
HANDLE_SCALAR_KIND(UInt32, uint32_t);
60+
HANDLE_SCALAR_KIND(Int64, int64_t);
61+
HANDLE_SCALAR_KIND(Float, float);
62+
HANDLE_SCALAR_KIND(Double, double);
63+
HANDLE_SCALAR_KIND(String, std::string_view);
64+
HANDLE_SCALAR_KIND(Binary, std::string_view);
65+
default:
66+
NIMBLE_UNREACHABLE(
67+
fmt::format("Unsupported scalar kind {}", toString(scalarKind)));
68+
}
69+
}
70+
} // namespace facebook::nimble

0 commit comments

Comments
 (0)