Skip to content

Commit d7c9a50

Browse files
xiaoxmengfacebook-github-bot
authored andcommitted
Spill prefix sort related code cleanup plus test improvement (#11508)
Summary: Pull Request resolved: #11508 The followup is to add session property at Prestissimo to allow configure in Presto Reviewed By: tanjialiang Differential Revision: D65791663 fbshipit-source-id: 59c37c543aa763030968fe9dea94e6c6ad820175
1 parent afa6572 commit d7c9a50

File tree

4 files changed

+57
-22
lines changed

4 files changed

+57
-22
lines changed

velox/core/QueryConfig.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ class QueryConfig {
234234
"spill_compression_codec";
235235

236236
/// Enable the prefix sort or fallback to timsort in spill. The prefix sort is
237-
/// faster than timsort but requires the memory to build prefix data, which
238-
/// may cause out of memory.
239-
static constexpr const char* kSpillEnablePrefixSort =
240-
"spill_enable_prefix_sort";
237+
/// faster than std::sort but requires the memory to build normalized prefix
238+
/// keys, which might have potential risk of running out of server memory.
239+
static constexpr const char* kSpillPrefixSortEnabled =
240+
"spill_prefixsort_enabled";
241241

242242
/// Specifies spill write buffer size in bytes. The spiller tries to buffer
243243
/// serialized spill data up to the specified size before write to storage
@@ -641,8 +641,8 @@ class QueryConfig {
641641
return get<std::string>(kSpillCompressionKind, "none");
642642
}
643643

644-
bool spillEnablePrefixSort() const {
645-
return get<bool>(kSpillEnablePrefixSort, false);
644+
bool spillPrefixSortEnabled() const {
645+
return get<bool>(kSpillPrefixSortEnabled, false);
646646
}
647647

648648
uint64_t spillWriteBufferSize() const {

velox/docs/configs.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@ Spilling
349349
- Specifies the compression algorithm type to compress the spilled data before write to disk to trade CPU for IO
350350
efficiency. The supported compression codecs are: ZLIB, SNAPPY, LZO, ZSTD, LZ4 and GZIP.
351351
NONE means no compression.
352-
* - spill_enable_prefix_sort
352+
* - spill_prefixsort_enabled
353353
- bool
354354
- false
355-
- Enable the prefix sort or fallback to timsort in spill. The prefix sort is faster than timsort but requires the
356-
memory to build prefix data, which might have potential risk of running out of server memory.
355+
- Enable the prefix sort or fallback to timsort in spill. The prefix sort is faster than std::sort but requires the
356+
memory to build normalized prefix keys, which might have potential risk of running out of server memory.
357357
* - spiller_start_partition_bit
358358
- integer
359359
- 29

velox/exec/Driver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ std::optional<common::SpillConfig> DriverCtx::makeSpillConfig(
141141
queryConfig.maxSpillRunRows(),
142142
queryConfig.writerFlushThresholdBytes(),
143143
queryConfig.spillCompressionKind(),
144-
queryConfig.spillEnablePrefixSort()
144+
queryConfig.spillPrefixSortEnabled()
145145
? std::optional<common::PrefixSortConfig>(prefixSortConfig())
146146
: std::nullopt,
147147
queryConfig.spillFileCreateConfig());

velox/exec/tests/SpillTest.cpp

+47-12
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,30 @@ class TestRuntimeStatWriter : public BaseRuntimeStatWriter {
5454
} // namespace
5555

5656
struct TestParam {
57-
common::CompressionKind compressionKind;
58-
bool enablePrefixSort;
57+
const common::CompressionKind compressionKind;
58+
const bool enablePrefixSort;
5959

6060
TestParam(common::CompressionKind _compressionKind, bool _enablePrefixSort)
6161
: compressionKind(_compressionKind),
6262
enablePrefixSort(_enablePrefixSort) {}
63+
64+
TestParam(uint32_t value)
65+
: compressionKind(static_cast<common::CompressionKind>(value >> 1)),
66+
enablePrefixSort(!!(value & 1)) {}
67+
68+
uint32_t value() const {
69+
return static_cast<uint32_t>(compressionKind) << 1 | enablePrefixSort;
70+
}
71+
72+
std::string toString() const {
73+
return fmt::format(
74+
"compressionKind: {}, enablePrefixSort: {}",
75+
compressionKind,
76+
enablePrefixSort);
77+
}
6378
};
6479

65-
class SpillTest : public ::testing::TestWithParam<common::CompressionKind>,
80+
class SpillTest : public ::testing::TestWithParam<uint32_t>,
6681
public facebook::velox::test::VectorTestBase {
6782
public:
6883
explicit SpillTest()
@@ -75,13 +90,33 @@ class SpillTest : public ::testing::TestWithParam<common::CompressionKind>,
7590
setThreadLocalRunTimeStatWriter(nullptr);
7691
}
7792

78-
static std::vector<common::CompressionKind> getTestParams() {
79-
std::vector<common::CompressionKind> testParams;
80-
testParams.emplace_back(common::CompressionKind::CompressionKind_NONE);
81-
testParams.emplace_back(common::CompressionKind::CompressionKind_ZLIB);
82-
testParams.emplace_back(common::CompressionKind::CompressionKind_SNAPPY);
83-
testParams.emplace_back(common::CompressionKind::CompressionKind_ZSTD);
84-
testParams.emplace_back(common::CompressionKind::CompressionKind_LZ4);
93+
static std::vector<uint32_t> getTestParams() {
94+
std::vector<uint32_t> testParams;
95+
testParams.emplace_back(
96+
TestParam{common::CompressionKind::CompressionKind_NONE, false}
97+
.value());
98+
testParams.emplace_back(
99+
TestParam{common::CompressionKind::CompressionKind_ZLIB, false}
100+
.value());
101+
testParams.emplace_back(
102+
TestParam{common::CompressionKind::CompressionKind_SNAPPY, false}
103+
.value());
104+
testParams.emplace_back(
105+
TestParam{common::CompressionKind::CompressionKind_ZSTD, false}
106+
.value());
107+
testParams.emplace_back(
108+
TestParam{common::CompressionKind::CompressionKind_LZ4, false}.value());
109+
testParams.emplace_back(
110+
TestParam{common::CompressionKind::CompressionKind_NONE, true}.value());
111+
testParams.emplace_back(
112+
TestParam{common::CompressionKind::CompressionKind_ZLIB, true}.value());
113+
testParams.emplace_back(
114+
TestParam{common::CompressionKind::CompressionKind_SNAPPY, true}
115+
.value());
116+
testParams.emplace_back(
117+
TestParam{common::CompressionKind::CompressionKind_ZSTD, true}.value());
118+
testParams.emplace_back(
119+
TestParam{common::CompressionKind::CompressionKind_LZ4, true}.value());
85120
return testParams;
86121
}
87122

@@ -103,8 +138,8 @@ class SpillTest : public ::testing::TestWithParam<common::CompressionKind>,
103138
tempDir_ = exec::test::TempDirectoryPath::create();
104139
filesystems::registerLocalFileSystem();
105140
rng_.seed(1);
106-
compressionKind_ = GetParam();
107-
enablePrefixSort_ = true;
141+
compressionKind_ = TestParam{GetParam()}.compressionKind;
142+
enablePrefixSort_ = TestParam{GetParam()}.enablePrefixSort;
108143
}
109144

110145
uint8_t randPartitionBitOffset() {

0 commit comments

Comments
 (0)