-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Presto serde bug when deserializing large payload
- Loading branch information
1 parent
96944d5
commit 46f36f4
Showing
7 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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,36 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed 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 "velox/common/base/IOUtils.h" | ||
#include "velox/common/memory/ByteStream.h" | ||
|
||
namespace facebook::velox::common { | ||
|
||
std::vector<ByteRange> byteRangesFromIOBuf(folly::IOBuf* iobuf) { | ||
if (iobuf == nullptr) { | ||
return {}; | ||
} | ||
std::vector<ByteRange> byteRanges; | ||
auto* current = iobuf; | ||
do { | ||
byteRanges.push_back( | ||
{current->writableData(), (int32_t)current->length(), 0}); | ||
current = current->next(); | ||
} while (current != iobuf); | ||
return byteRanges; | ||
} | ||
|
||
} // namespace facebook::velox::common |
This file contains 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 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 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,65 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed 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 <gtest/gtest.h> | ||
|
||
#include "velox/common/base/IOUtils.h" | ||
#include "velox/common/memory/ByteStream.h" | ||
|
||
namespace facebook::velox::common { | ||
|
||
class IOUtilsTest : public testing::Test { | ||
public: | ||
std::unique_ptr<folly::IOBuf> createIOBuf(uint64_t size) { | ||
auto buf = folly::IOBuf::create(size); | ||
auto* writableData = buf->writableData(); | ||
std::memset(writableData, '6', size); | ||
buf->append(size); | ||
return buf; | ||
} | ||
}; | ||
|
||
TEST_F(IOUtilsTest, iobufConsume) { | ||
// Empty buffer test | ||
auto emptyBufList = byteRangesFromIOBuf(nullptr); | ||
ASSERT_TRUE(emptyBufList.empty()); | ||
|
||
// Single buffer test | ||
const uint64_t bufCapacity = 1024; | ||
auto iobuf = createIOBuf(bufCapacity); | ||
auto oneBufList = byteRangesFromIOBuf(iobuf.get()); | ||
ASSERT_EQ(oneBufList.size(), 1); | ||
ASSERT_EQ(oneBufList[0].size, bufCapacity); | ||
|
||
// Multiple buffer test | ||
const uint64_t numChainedBuf = 64; | ||
auto head = createIOBuf(bufCapacity); | ||
uint32_t count{1}; | ||
folly::IOBuf* cur = head.get(); | ||
while (count < numChainedBuf) { | ||
cur->insertAfterThisOne(createIOBuf(bufCapacity)); | ||
cur = cur->next(); | ||
count++; | ||
} | ||
|
||
auto rangeList = byteRangesFromIOBuf(head.get()); | ||
ASSERT_EQ(rangeList.size(), numChainedBuf); | ||
for (const auto& range : rangeList) { | ||
ASSERT_EQ(range.size, bufCapacity); | ||
} | ||
} | ||
|
||
} // namespace facebook::velox::common |
This file contains 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 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