diff options
author | akozhikhov <akozhikhov@yandex-team.com> | 2023-09-27 19:50:59 +0300 |
---|---|---|
committer | akozhikhov <akozhikhov@yandex-team.com> | 2023-09-27 20:16:01 +0300 |
commit | fddb0f8c39b7d1913eb5161041eb3575aa5c29c6 (patch) | |
tree | 8035d464a23ed9511b95107ea3c3b7716461e311 | |
parent | 48a18a64bb612e73011e1c49aef96b8dad6bffba (diff) | |
download | ydb-fddb0f8c39b7d1913eb5161041eb3575aa5c29c6.tar.gz |
YT-20056: Key prefix filtering for range selects
-rw-r--r-- | yt/yt/client/table_client/config.cpp | 25 | ||||
-rw-r--r-- | yt/yt/client/table_client/config.h | 15 | ||||
-rw-r--r-- | yt/yt/client/table_client/public.h | 1 | ||||
-rw-r--r-- | yt/yt_proto/yt/client/table_chunk_format/proto/chunk_meta.proto | 1 |
4 files changed, 42 insertions, 0 deletions
diff --git a/yt/yt/client/table_client/config.cpp b/yt/yt/client/table_client/config.cpp index 3f4ec24ad64..b376c4ec985 100644 --- a/yt/yt/client/table_client/config.cpp +++ b/yt/yt/client/table_client/config.cpp @@ -162,6 +162,8 @@ void TChunkWriterConfig::Register(TRegistrar registrar) registrar.Parameter("key_filter", &TThis::KeyFilter) .DefaultNew(); + registrar.Parameter("key_prefix_filter", &TThis::KeyPrefixFilter) + .DefaultNew(); } //////////////////////////////////////////////////////////////////////////////// @@ -208,6 +210,29 @@ void TKeyFilterWriterConfig::Register(TRegistrar registrar) }); } +void TKeyPrefixFilterWriterConfig::Register(TRegistrar registrar) +{ + registrar.Parameter("prefix_lengths", &TThis::PrefixLengths) + .Default(); + + registrar.Postprocessor([] (TThis* config) { + if (config->Enable && config->PrefixLengths.empty()) { + THROW_ERROR_EXCEPTION("Parameter \"prefix_lengths\" cannot be empty"); + } + + for (auto length : config->PrefixLengths) { + if (length <= 0) { + THROW_ERROR_EXCEPTION("Values in \"prefix_lengths\" cannot be non-positive, found %v", + length); + } else if (length > MaxKeyColumnCountInDynamicTable) { + THROW_ERROR_EXCEPTION("Values in \"prefix_lengths\" cannot exceed %v, found %v", + MaxKeyColumnCountInDynamicTable, + length); + } + } + }); +} + /////////////////////////////////////////////////////////////////////////////// void TBatchHunkReaderConfig::Register(TRegistrar registrar) diff --git a/yt/yt/client/table_client/config.h b/yt/yt/client/table_client/config.h index 7c8a96f7b89..b209155d745 100644 --- a/yt/yt/client/table_client/config.h +++ b/yt/yt/client/table_client/config.h @@ -161,6 +161,7 @@ public: TChunkWriterTestingOptionsPtr TestingOptions; TKeyFilterWriterConfigPtr KeyFilter; + TKeyPrefixFilterWriterConfigPtr KeyPrefixFilter; REGISTER_YSON_STRUCT(TChunkWriterConfig); @@ -194,6 +195,20 @@ public: DEFINE_REFCOUNTED_TYPE(TKeyFilterWriterConfig) +class TKeyPrefixFilterWriterConfig + : public TKeyFilterWriterConfig +{ +public: + //! Will produce filters for key prefix of specified lengths. + THashSet<int> PrefixLengths; + + REGISTER_YSON_STRUCT(TKeyPrefixFilterWriterConfig); + + static void Register(TRegistrar registrar); +}; + +DEFINE_REFCOUNTED_TYPE(TKeyPrefixFilterWriterConfig) + //////////////////////////////////////////////////////////////////////////////// class TBatchHunkReaderConfig diff --git a/yt/yt/client/table_client/public.h b/yt/yt/client/table_client/public.h index 60745939770..da28a221a1b 100644 --- a/yt/yt/client/table_client/public.h +++ b/yt/yt/client/table_client/public.h @@ -326,6 +326,7 @@ DECLARE_REFCOUNTED_CLASS(TChunkReaderConfig) DECLARE_REFCOUNTED_CLASS(TChunkWriterConfig) DECLARE_REFCOUNTED_CLASS(TKeyFilterWriterConfig) +DECLARE_REFCOUNTED_CLASS(TKeyPrefixFilterWriterConfig) DECLARE_REFCOUNTED_CLASS(TBatchHunkReaderConfig) diff --git a/yt/yt_proto/yt/client/table_chunk_format/proto/chunk_meta.proto b/yt/yt_proto/yt/client/table_chunk_format/proto/chunk_meta.proto index 314f8a91c6b..dfd76990c09 100644 --- a/yt/yt_proto/yt/client/table_chunk_format/proto/chunk_meta.proto +++ b/yt/yt_proto/yt/client/table_chunk_format/proto/chunk_meta.proto @@ -190,6 +190,7 @@ message TXorFilterSystemBlockMeta } optional bytes last_key = 1; + optional int32 key_prefix_length = 2; } message TSystemBlockMeta |