hello-stephen commented on code in PR #71357:
URL: https://github.com/apache/doris/pull/71357#discussion_r4794421198
##########
be/src/format_v2/parquet/reader/native/decoder.h:
##########
@@ -190,8 +190,16 @@ class BaseDictDecoder : public Decoder {
constexpr size_t MIN_FRAGMENTED_RANGES = 8;
constexpr size_t MAX_AVERAGE_RANGE_VALUES = 4;
constexpr size_t MAX_DECODE_EXPANSION = 8;
+ // A selection such as one id in every 20 still requires decoding and
validating the
+ // other 19. When ranges split 32-value unpack batches, compact the
validated ids once.
+ // Limit the additional scratch for sparse inputs to 32 KiB per
decoder.
+ constexpr size_t UNPACK_VALUES = 32;
+ constexpr size_t MAX_SPARSE_BATCH_VALUES = 8192;
+ const bool short_gaps = selection.total_values <=
MAX_SPARSE_BATCH_VALUES &&
Review Comment:
[P2] Charge the expanded dictionary scratch to the query memory tracker. An
8,192-ID fragment that selects every 31st value previously needed at most 120
bytes of ID scratch per leaf. This branch grows `_skip_indices` to 32 KiB per
leaf, which can stay allocated for the row group. A scan with 256 such
dictionary-encoded output columns can therefore hold about 8 MiB of scratch per
active row group outside the query limit. `_skip_indices` uses `std::vector`,
and the scratch byte counters only drive reclamation. Backing the buffer with
`DorisVector<uint32_t>` would charge its allocation to the attached query
tracker.
##########
be/test/format_v2/parquet/native_decoder_test.cpp:
##########
@@ -2218,6 +2218,66 @@ TEST(ParquetV2NativeDecoderTest,
ByteArrayDictionaryReferencesOwnedPageAndValida
EXPECT_TRUE(decoder.set_data(&oversized_bit_width_slice).is<ErrorCode::CORRUPTION>());
}
+std::vector<uint8_t> make_sparse_dictionary_ids(size_t count, bool corrupt) {
+ faststring ids;
+ RleEncoder<uint32_t> encoder(&ids, 2);
+ for (size_t row = 0; row < count; ++row) {
+ encoder.Put(corrupt && row == 20 ? 3 : row % 2);
+ }
+ // Parquet bit-packed literal runs contain complete groups of eight values.
+ for (size_t padding = count; padding % 8 != 0; ++padding) {
+ encoder.Put(0);
+ }
+ encoder.Flush();
+ std::vector<uint8_t> payload(ids.size() + 1);
+ payload[0] = 2;
+ memcpy(payload.data() + 1, ids.data(), ids.size());
+ return payload;
+}
+
+void check_sparse_dictionary_selection(size_t count, bool corrupt) {
+ int32_t length = 0;
+ auto dictionary = make_byte_array_dictionary({"a", "b"}, &length);
+ ByteArrayDictDecoder decoder;
+ ASSERT_TRUE(decoder.set_dict(dictionary, length, 2).ok());
+
+ ParquetSelection selection {.total_values = count, .selected_values = 0,
.ranges = {}};
+ std::vector<uint32_t> expected;
+ for (size_t row = 1; row < count; row += 21) {
+ selection.ranges.push_back({.first = row, .count = 1});
+ expected.push_back(row % 2);
+ }
+ selection.selected_values = expected.size();
+
+ auto payload = make_sparse_dictionary_ids(count, corrupt);
+ Slice data(payload.data(), payload.size());
+ ASSERT_TRUE(decoder.set_data(&data).ok());
+ CaptureDictionaryConsumer consumer;
+ auto status = decoder.decode_selected_dictionary_values(selection,
consumer);
+ Slice replay(payload.data(), payload.size());
+ ASSERT_TRUE(decoder.set_data(&replay).ok());
+ std::vector<uint32_t> indices;
+ auto index_status = decoder.decode_selected_dictionary_indices(selection,
&indices);
+ if (corrupt) {
+ EXPECT_TRUE(status.is<ErrorCode::CORRUPTION>());
+ EXPECT_TRUE(index_status.is<ErrorCode::CORRUPTION>());
+ return;
+ }
+ ASSERT_TRUE(status.ok()) << status.to_string();
+ ASSERT_TRUE(index_status.ok()) << index_status.to_string();
+ EXPECT_EQ(consumer.consume_calls, count <= 8192 ? 1 : expected.size());
+ EXPECT_EQ(consumer.indices, expected);
+ EXPECT_EQ(indices, expected);
Review Comment:
[P3] Assert that the explicit-index call takes the new batch path. Its
current output and corruption checks also pass through the original per-range
loop, so the test would stay green if that call stopped batching. For these
fixtures, `active_scratch_bytes()` immediately after a successful index decode
would show 192 and 8,192 IDs of scratch in the batch cases and one ID of
scratch just above the cutoff.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]