|
40 | 40 | #include "velox/dwio/nimble/common/Types.h" |
41 | 41 | #include "velox/dwio/nimble/common/Vector.h" |
42 | 42 | #include "velox/dwio/nimble/encodings/DictionaryEncoding.h" |
| 43 | +#include "velox/dwio/nimble/encodings/NullableEncoding.h" |
43 | 44 | #include "velox/dwio/nimble/encodings/common/Encoding.h" |
44 | 45 | #include "velox/dwio/nimble/encodings/common/EncodingFactory.h" |
45 | 46 | #include "velox/dwio/nimble/encodings/common/EncodingPrefix.h" |
@@ -298,6 +299,11 @@ class SharedDictionaryAlphabet { |
298 | 299 | return encodingType_; |
299 | 300 | } |
300 | 301 |
|
| 302 | + /// Returns the encoded alphabet stream passed to create(). |
| 303 | + std::string_view encodedAlphabet() const { |
| 304 | + return encodedAlphabet_; |
| 305 | + } |
| 306 | + |
301 | 307 | /// Returns the entry stored at index. T must match dataType(). |
302 | 308 | template <typename T> |
303 | 309 | typename TypeTraits<T>::physicalType physicalValueAt(uint32_t index) const { |
@@ -432,6 +438,7 @@ class SharedDictionaryAlphabet { |
432 | 438 |
|
433 | 439 | // Keeps borrowed encoded bytes alive when create() receives an owner. |
434 | 440 | const std::shared_ptr<const void> encodedAlphabetOwner_; |
| 441 | + const std::string_view encodedAlphabet_; |
435 | 442 | const DataType dataType_; |
436 | 443 | const EncodingType encodingType_; |
437 | 444 | uint32_t entryCount_{0}; |
@@ -503,6 +510,13 @@ class SharedDictionaryEncoding |
503 | 510 | Buffer& buffer, |
504 | 511 | const Encoding::Options& options = {}); |
505 | 512 |
|
| 513 | + static std::string_view encodeNullable( |
| 514 | + EncodingSelection<physicalType>&& selection, |
| 515 | + std::span<const physicalType> values, |
| 516 | + std::span<const bool> nulls, |
| 517 | + Buffer& buffer, |
| 518 | + const Encoding::Options& options = {}); |
| 519 | + |
506 | 520 | static std::string_view slice( |
507 | 521 | std::string_view encoded, |
508 | 522 | uint32_t offset, |
@@ -666,6 +680,34 @@ std::string_view SharedDictionaryEncoding<T>::encode( |
666 | 680 | return {reserved, encodingSize}; |
667 | 681 | } |
668 | 682 |
|
| 683 | +template <typename T> |
| 684 | +std::string_view SharedDictionaryEncoding<T>::encodeNullable( |
| 685 | + EncodingSelection<physicalType>&& selection, |
| 686 | + std::span<const physicalType> values, |
| 687 | + std::span<const bool> nulls, |
| 688 | + Buffer& buffer, |
| 689 | + const Encoding::Options& options) { |
| 690 | + static_assert(isIntegralType<T>() && !std::is_same_v<T, bool>); |
| 691 | + |
| 692 | + auto nullsPolicy = selection.template createNestedPolicy<bool>( |
| 693 | + EncodingType::Nullable, EncodingIdentifiers::Nullable::Nulls); |
| 694 | + NIMBLE_CHECK_NOT_NULL(nullsPolicy); |
| 695 | + auto typedNullsPolicy = std::unique_ptr<EncodingSelectionPolicy<bool>>( |
| 696 | + static_cast<EncodingSelectionPolicy<bool>*>(nullsPolicy.release())); |
| 697 | + auto* pool = &buffer.getMemoryPool(); |
| 698 | + ScopedEncodingBuffer scopedBuffer{pool, options.encodingBufferPool}; |
| 699 | + const auto serializedValues = EncodingFactory::encode<T>( |
| 700 | + std::move(selection), values, scopedBuffer.get(), options); |
| 701 | + const auto serializedNulls = EncodingFactory::encode<bool>( |
| 702 | + std::move(typedNullsPolicy), nulls, scopedBuffer.get(), options); |
| 703 | + return NullableEncoding<T>::encodeNullable( |
| 704 | + static_cast<uint32_t>(nulls.size()), |
| 705 | + serializedValues, |
| 706 | + serializedNulls, |
| 707 | + buffer, |
| 708 | + options); |
| 709 | +} |
| 710 | + |
669 | 711 | template <typename T> |
670 | 712 | std::string_view SharedDictionaryEncoding<T>::encodeIndices( |
671 | 713 | std::span<const uint32_t> indices, |
|
0 commit comments