diff --git a/ydb/core/kqp/ut/common/columnshard.cpp b/ydb/core/kqp/ut/common/columnshard.cpp index fa68d4a84ffa..d00ccf2044e8 100644 --- a/ydb/core/kqp/ut/common/columnshard.cpp +++ b/ydb/core/kqp/ut/common/columnshard.cpp @@ -1,6 +1,8 @@ #include "columnshard.h" -#include + #include +#include +#include extern "C" { #include @@ -143,6 +145,13 @@ namespace NKqp { } } + void TTestHelper::SetCompression( + const TColumnTableBase& columnTable, const TString& columnName, const TCompression& compression, const NYdb::EStatus expectedStatus) { + auto alterQuery = columnTable.BuildAlterCompressionQuery(columnName, compression); + auto result = GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), expectedStatus, result.GetIssues().ToString()); + } + TString TTestHelper::TColumnSchema::BuildQuery() const { TStringBuilder str; str << Name << ' '; @@ -185,6 +194,16 @@ namespace NKqp { return str; } + TString TTestHelper::TColumnTableBase::BuildAlterCompressionQuery(const TString& columnName, const TCompression& compression) const { + auto str = TStringBuilder() << "ALTER OBJECT `" << Name << "` (TYPE " << GetObjectType() << ") SET"; + str << " (ACTION=ALTER_COLUMN, NAME=" << columnName << ", `SERIALIZER.CLASS_NAME`=`" << compression.GetSerializerName() << "`,"; + str << " `COMPRESSION.TYPE`=`" << NArrow::CompressionToString(compression.GetType()) << "`"; + if (compression.GetCompressionLevel() != Max()) { + str << "`COMPRESSION.LEVEL`=" << compression.GetCompressionLevel(); + } + str << ");"; + return str; + } std::shared_ptr TTestHelper::TColumnTableBase::GetArrowSchema(const TVector& columns) { std::vector> result; diff --git a/ydb/core/kqp/ut/common/columnshard.h b/ydb/core/kqp/ut/common/columnshard.h index 83dd86d3d98b..8c4bc0fed6fd 100644 --- a/ydb/core/kqp/ut/common/columnshard.h +++ b/ydb/core/kqp/ut/common/columnshard.h @@ -1,88 +1,102 @@ #pragma once #include "kqp_ut_common.h" + +#include + #include -#include #include #include +#include #include #include #include -#include #include namespace NKikimr { namespace NKqp { - class TTestHelper { +class TTestHelper { +public: + class TCompression { + YDB_ACCESSOR(TString, SerializerName, "ARROW_SERIALIZER"); + YDB_ACCESSOR(arrow::Compression::type, Type, arrow::Compression::type::UNCOMPRESSED); + YDB_ACCESSOR(i32, CompressionLevel, Max()); + }; + + class TColumnSchema { + YDB_ACCESSOR_DEF(TString, Name); + YDB_ACCESSOR_DEF(NScheme::TTypeInfo, TypeInfo); + YDB_FLAG_ACCESSOR(Nullable, true); + public: - class TColumnSchema { - YDB_ACCESSOR_DEF(TString, Name); - YDB_ACCESSOR_DEF(NScheme::TTypeInfo, TypeInfo); - YDB_FLAG_ACCESSOR(Nullable, true); - public: - TString BuildQuery() const; - - TColumnSchema& SetType(NScheme::TTypeId typeId); - }; - - using TUpdatesBuilder = NColumnShard::TTableUpdatesBuilder; - - class TColumnTableBase { - YDB_ACCESSOR_DEF(TString, Name); - YDB_ACCESSOR_DEF(TVector, Schema); - YDB_ACCESSOR_DEF(TVector, PrimaryKey); - YDB_ACCESSOR_DEF(TVector, Sharding); - YDB_ACCESSOR(ui32, MinPartitionsCount, 1); - - std::optional> TTLConf; - public: - TString BuildQuery() const; - std::shared_ptr GetArrowSchema(const TVector& columns); - - TColumnTableBase& SetTTL(const TString& columnName, const TString& ttlConf) { - TTLConf = std::make_pair(columnName, ttlConf); - return *this; - } - - private: - virtual TString GetObjectType() const = 0; - TString BuildColumnsStr(const TVector& clumns) const; - std::shared_ptr BuildField(const TString name, const NScheme::TTypeInfo& typeInfo, bool nullable) const; - }; - - class TColumnTable : public TColumnTableBase { - private: - TString GetObjectType() const override; - }; - - class TColumnTableStore : public TColumnTableBase { - private: - TString GetObjectType() const override; - }; + TString BuildQuery() const; - private: - std::unique_ptr Kikimr; - std::unique_ptr TableClient; - std::unique_ptr Session; + TColumnSchema& SetType(NScheme::TTypeId typeId); + }; + + using TUpdatesBuilder = NColumnShard::TTableUpdatesBuilder; + + class TColumnTableBase { + YDB_ACCESSOR_DEF(TString, Name); + YDB_ACCESSOR_DEF(TVector, Schema); + YDB_ACCESSOR_DEF(TVector, PrimaryKey); + YDB_ACCESSOR_DEF(TVector, Sharding); + YDB_ACCESSOR(ui32, MinPartitionsCount, 1); + + std::optional> TTLConf; public: - TTestHelper(const TKikimrSettings& settings); - TKikimrRunner& GetKikimr(); - TTestActorRuntime& GetRuntime(); - NYdb::NTable::TSession& GetSession(); - void CreateTable(const TColumnTableBase& table, const NYdb::EStatus expectedStatus = NYdb::EStatus::SUCCESS); - void DropTable(const TString& tableName); - void CreateTier(const TString& tierName); - TString CreateTieringRule(const TString& tierName, const TString& columnName); - void SetTiering(const TString& tableName, const TString& ruleName); - void ResetTiering(const TString& tableName); - void BulkUpsert(const TColumnTable& table, TTestHelper::TUpdatesBuilder& updates, const Ydb::StatusIds_StatusCode& opStatus = Ydb::StatusIds::SUCCESS); - void BulkUpsert(const TColumnTable& table, std::shared_ptr batch, const Ydb::StatusIds_StatusCode& opStatus = Ydb::StatusIds::SUCCESS); - void ReadData(const TString& query, const TString& expected, const NYdb::EStatus opStatus = NYdb::EStatus::SUCCESS); - void RebootTablets(const TString& tableName); - void WaitTabletDeletionInHive(ui64 tabletId, TDuration duration); + TString BuildQuery() const; + TString BuildAlterCompressionQuery(const TString& columnName, const TCompression& compression) const; + std::shared_ptr GetArrowSchema(const TVector& columns); + + TColumnTableBase& SetTTL(const TString& columnName, const TString& ttlConf) { + TTLConf = std::make_pair(columnName, ttlConf); + return *this; + } + + private: + virtual TString GetObjectType() const = 0; + TString BuildColumnsStr(const TVector& clumns) const; + std::shared_ptr BuildField(const TString name, const NScheme::TTypeInfo& typeInfo, bool nullable) const; + }; + + class TColumnTable: public TColumnTableBase { + private: + TString GetObjectType() const override; + }; + + class TColumnTableStore: public TColumnTableBase { + private: + TString GetObjectType() const override; }; +private: + std::unique_ptr Kikimr; + std::unique_ptr TableClient; + std::unique_ptr Session; + +public: + TTestHelper(const TKikimrSettings& settings); + TKikimrRunner& GetKikimr(); + TTestActorRuntime& GetRuntime(); + NYdb::NTable::TSession& GetSession(); + void CreateTable(const TColumnTableBase& table, const NYdb::EStatus expectedStatus = NYdb::EStatus::SUCCESS); + void DropTable(const TString& tableName); + void CreateTier(const TString& tierName); + TString CreateTieringRule(const TString& tierName, const TString& columnName); + void SetTiering(const TString& tableName, const TString& ruleName); + void ResetTiering(const TString& tableName); + void BulkUpsert( + const TColumnTable& table, TTestHelper::TUpdatesBuilder& updates, const Ydb::StatusIds_StatusCode& opStatus = Ydb::StatusIds::SUCCESS); + void BulkUpsert(const TColumnTable& table, std::shared_ptr batch, + const Ydb::StatusIds_StatusCode& opStatus = Ydb::StatusIds::SUCCESS); + void ReadData(const TString& query, const TString& expected, const NYdb::EStatus opStatus = NYdb::EStatus::SUCCESS); + void RebootTablets(const TString& tableName); + void WaitTabletDeletionInHive(ui64 tabletId, TDuration duration); + void SetCompression(const TColumnTableBase& columnTable, const TString& columnName, const TCompression& compression, + const NYdb::EStatus expectedStatus = NYdb::EStatus::SUCCESS); +}; } } diff --git a/ydb/core/kqp/ut/olap/compression_ut.cpp b/ydb/core/kqp/ut/olap/compression_ut.cpp new file mode 100644 index 000000000000..3745809b05c5 --- /dev/null +++ b/ydb/core/kqp/ut/olap/compression_ut.cpp @@ -0,0 +1,30 @@ +#include + +namespace NKikimr::NKqp { + +Y_UNIT_TEST_SUITE(KqpOlapCompression) { + Y_UNIT_TEST(DisabledAlterCompression) { + TKikimrSettings settings = TKikimrSettings().SetWithSampleTables(false).SetEnableOlapCompression(false); + TTestHelper testHelper(settings); + TVector schema = { + TTestHelper::TColumnSchema().SetName("pk_int").SetType(NScheme::NTypeIds::Uint64).SetNullable(false) + }; + TTestHelper::TCompression compression = TTestHelper::TCompression().SetType(arrow::Compression::type::ZSTD); + + TTestHelper::TColumnTable standaloneTable; + standaloneTable.SetName("/Root/StandaloneTable").SetPrimaryKey({ "pk_int" }).SetSharding({ "pk_int" }).SetSchema(schema); + testHelper.CreateTable(standaloneTable); + testHelper.SetCompression(standaloneTable, "pk_int", compression, NYdb::EStatus::SCHEME_ERROR); + + TTestHelper::TColumnTableStore testTableStore; + testTableStore.SetName("/Root/TableStoreTest").SetPrimaryKey({ "pk_int" }).SetSchema(schema); + testHelper.CreateTable(testTableStore); + testHelper.SetCompression(testTableStore, "pk_int", compression, NYdb::EStatus::PRECONDITION_FAILED); + + TTestHelper::TColumnTable testTable; + testTable.SetName("/Root/TableStoreTest/ColumnTableTest").SetPrimaryKey({ "pk_int" }).SetSharding({ "pk_int" }).SetSchema(schema); + testHelper.CreateTable(testTable); + testHelper.SetCompression(testTable, "pk_int", compression, NYdb::EStatus::SCHEME_ERROR); + } +} +} diff --git a/ydb/core/kqp/ut/olap/sys_view_ut.cpp b/ydb/core/kqp/ut/olap/sys_view_ut.cpp index 581384ba4450..27820452542e 100644 --- a/ydb/core/kqp/ut/olap/sys_view_ut.cpp +++ b/ydb/core/kqp/ut/olap/sys_view_ut.cpp @@ -219,17 +219,6 @@ Y_UNIT_TEST_SUITE(KqpOlapSysView) { } } - Y_UNIT_TEST(DisabledAlterCompression) { - TKikimrSettings settings = TKikimrSettings().SetWithSampleTables(false).SetEnableOlapCompression(false); - TKikimrRunner kikimr(settings); - TTypedLocalHelper helper("", kikimr, "olapTable", "olapStore"); - helper.CreateTestOlapTable(); - helper.FillPKOnly(0, 1); - helper.ExecuteSchemeQuery( - "ALTER OBJECT `/Root/olapStore` (TYPE TABLESTORE) SET (ACTION=ALTER_COLUMN, NAME=pk_int, " - "`SERIALIZER.CLASS_NAME`=`ARROW_SERIALIZER`, `COMPRESSION.TYPE`=`zstd`);", NYdb::EStatus::PRECONDITION_FAILED); - } - Y_UNIT_TEST(StatsSysViewBytesColumnActualization) { ui64 rawBytes1; ui64 bytes1; diff --git a/ydb/core/kqp/ut/olap/ya.make b/ydb/core/kqp/ut/olap/ya.make index e324116597eb..92ec60d6a8b8 100644 --- a/ydb/core/kqp/ut/olap/ya.make +++ b/ydb/core/kqp/ut/olap/ya.make @@ -26,6 +26,7 @@ SRCS( sparsed_ut.cpp tiering_ut.cpp decimal_ut.cpp + compression_ut.cpp ) PEERDIR(