-
Notifications
You must be signed in to change notification settings - Fork 508
ORC-2022: [C++] Add support to use dictionary for IN expression #2453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1c5b06b
ORC-2022: [C++] Add support to use dictionary for IN expression
0e955cf
remove enableDictionaryFiltering in option.hh
be5dae6
add ut to test filtering with matching values
5e658a8
fix ut
22192c2
remove unnecessary changes
a7eac1a
remove unnecessary changes
736cd5d
format code
fb70a98
return TruthValue::YES_NO_NULL if dictionary entry matches any litera…
90cfdc8
Merge branch 'main' into ORC-2022
luffy-zh 23cf348
evaluate the dictionary based on the size of its intersection with th…
795850d
repalce matchingDictEntries with matchedEntriesCount
1ce8b6b
fix typo
bde7927
Update c++/src/ColumnReader.cc
wgtmac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
|
|
||
| #include "DictionaryLoader.hh" | ||
| #include "RLE.hh" | ||
|
|
||
| namespace orc { | ||
|
|
||
| namespace { | ||
|
|
||
| // Helper function to read data fully from a stream | ||
| void readFully(char* buffer, int64_t bufferSize, SeekableInputStream* stream) { | ||
| int64_t posn = 0; | ||
| while (posn < bufferSize) { | ||
| const void* chunk; | ||
| int length; | ||
| if (!stream->Next(&chunk, &length)) { | ||
| throw ParseError("bad read in readFully"); | ||
| } | ||
| if (posn + length > bufferSize) { | ||
| throw ParseError("Corrupt dictionary blob"); | ||
| } | ||
| memcpy(buffer + posn, chunk, static_cast<size_t>(length)); | ||
| posn += length; | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| std::shared_ptr<StringDictionary> loadStringDictionary(uint64_t columnId, StripeStreams& stripe, | ||
| MemoryPool& pool) { | ||
| // Get encoding information | ||
| proto::ColumnEncoding encoding = stripe.getEncoding(columnId); | ||
| RleVersion rleVersion = convertRleVersion(encoding.kind()); | ||
| uint32_t dictSize = encoding.dictionary_size(); | ||
|
|
||
| // Create the dictionary object | ||
| auto dictionary = std::make_shared<StringDictionary>(pool); | ||
|
|
||
| // Read LENGTH stream to get dictionary entry lengths | ||
| std::unique_ptr<SeekableInputStream> stream = | ||
| stripe.getStream(columnId, proto::Stream_Kind_LENGTH, false); | ||
| if (dictSize > 0 && stream == nullptr) { | ||
| std::stringstream ss; | ||
| ss << "LENGTH stream not found in StringDictionaryColumn for column " << columnId; | ||
| throw ParseError(ss.str()); | ||
| } | ||
| std::unique_ptr<RleDecoder> lengthDecoder = | ||
| createRleDecoder(std::move(stream), false, rleVersion, pool, stripe.getReaderMetrics()); | ||
|
|
||
| // Decode dictionary entry lengths | ||
| dictionary->dictionaryOffset.resize(dictSize + 1); | ||
| int64_t* lengthArray = dictionary->dictionaryOffset.data(); | ||
| lengthDecoder->next(lengthArray + 1, dictSize, nullptr); | ||
| lengthArray[0] = 0; | ||
|
|
||
| // Convert lengths to cumulative offsets | ||
| for (uint32_t i = 1; i < dictSize + 1; ++i) { | ||
| if (lengthArray[i] < 0) { | ||
| std::stringstream ss; | ||
| ss << "Negative dictionary entry length for column " << columnId; | ||
| throw ParseError(ss.str()); | ||
| } | ||
| lengthArray[i] += lengthArray[i - 1]; | ||
| } | ||
|
|
||
| int64_t blobSize = lengthArray[dictSize]; | ||
|
|
||
| // Read DICTIONARY_DATA stream to get dictionary content | ||
| dictionary->dictionaryBlob.resize(static_cast<uint64_t>(blobSize)); | ||
| std::unique_ptr<SeekableInputStream> blobStream = | ||
| stripe.getStream(columnId, proto::Stream_Kind_DICTIONARY_DATA, false); | ||
| if (blobSize > 0 && blobStream == nullptr) { | ||
| std::stringstream ss; | ||
| ss << "DICTIONARY_DATA stream not found in StringDictionaryColumn for column " << columnId; | ||
| throw ParseError(ss.str()); | ||
| } | ||
|
|
||
| // Read the dictionary blob | ||
| readFully(dictionary->dictionaryBlob.data(), blobSize, blobStream.get()); | ||
|
|
||
| return dictionary; | ||
| } | ||
|
|
||
| } // namespace orc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
|
|
||
| #ifndef ORC_DICTIONARY_LOADER_HH | ||
| #define ORC_DICTIONARY_LOADER_HH | ||
|
|
||
| #include "ColumnReader.hh" | ||
| #include "orc/Vector.hh" | ||
|
|
||
| namespace orc { | ||
|
|
||
| /** | ||
| * Load a string dictionary for a single column from a stripe. | ||
| * This function reads the LENGTH and DICTIONARY_DATA streams and populates | ||
| * the StringDictionary structure. It automatically uses ReadCache if available | ||
| * through the StripeStreams interface. | ||
| * | ||
| * @param columnId the column ID to load the dictionary for | ||
| * @param stripe the StripeStreams interface providing access to streams | ||
| * @param pool the memory pool to use for allocating the dictionary | ||
| * @return a shared pointer to the loaded StringDictionary, or nullptr if loading fails | ||
| */ | ||
| std::shared_ptr<StringDictionary> loadStringDictionary(uint64_t columnId, StripeStreams& stripe, | ||
| MemoryPool& pool); | ||
|
|
||
| // Helper function to convert encoding kind to RLE version | ||
| inline RleVersion convertRleVersion(proto::ColumnEncoding_Kind kind) { | ||
| switch (static_cast<int64_t>(kind)) { | ||
| case proto::ColumnEncoding_Kind_DIRECT: | ||
| case proto::ColumnEncoding_Kind_DICTIONARY: | ||
| return RleVersion_1; | ||
| case proto::ColumnEncoding_Kind_DIRECT_V2: | ||
| case proto::ColumnEncoding_Kind_DICTIONARY_V2: | ||
| return RleVersion_2; | ||
| default: | ||
| throw ParseError("Unknown encoding in convertRleVersion"); | ||
| } | ||
| } | ||
|
|
||
| } // namespace orc | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.