diff options
author | sabdenovch <sabdenovch@yandex-team.com> | 2024-06-14 16:05:53 +0300 |
---|---|---|
committer | sabdenovch <sabdenovch@yandex-team.com> | 2024-06-14 16:26:15 +0300 |
commit | fa297dd4855aef4bd79faebb48120708d2f9249d (patch) | |
tree | c5307db922284f1a570df85bd1d213e87905f44a | |
parent | dfd152fa51d293739127df584e26ef8119f41d8c (diff) | |
download | ydb-fa297dd4855aef4bd79faebb48120708d2f9249d.tar.gz |
Cosmetics (post-commit)
a8acc946f5655170fc732816a8a8bc9e33388de3
-rw-r--r-- | yt/yt/client/table_client/check_schema_compatibility.cpp | 13 | ||||
-rw-r--r-- | yt/yt/client/table_client/check_schema_compatibility.h | 9 | ||||
-rw-r--r-- | yt/yt/client/table_client/schema.cpp | 16 | ||||
-rw-r--r-- | yt/yt/client/table_client/schema.h | 2 | ||||
-rw-r--r-- | yt/yt/client/unittests/check_schema_compatibility_ut.cpp | 46 |
5 files changed, 48 insertions, 38 deletions
diff --git a/yt/yt/client/table_client/check_schema_compatibility.cpp b/yt/yt/client/table_client/check_schema_compatibility.cpp index f9b4c566fd..6e7f7ddbc7 100644 --- a/yt/yt/client/table_client/check_schema_compatibility.cpp +++ b/yt/yt/client/table_client/check_schema_compatibility.cpp @@ -14,8 +14,7 @@ namespace NYT::NTableClient { std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibilityImpl( const TTableSchema& inputSchema, const TTableSchema& outputSchema, - bool ignoreSortOrder, - bool forbidExtraComputedColumns) + TTableSchemaCompatibilityOptions options) { // If output schema is strict, check that input columns are subset of output columns. if (outputSchema.GetStrict()) { @@ -93,7 +92,7 @@ std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibilityImpl( inputColumn->GetDiagnosticNameString()), }; } - } else if (forbidExtraComputedColumns && outputColumn.Expression()) { + } else if (options.ForbidExtraComputedColumns && outputColumn.Expression()) { return { ESchemaCompatibility::Incompatible, TError("Unexpected computed column %v in output schema", @@ -159,7 +158,7 @@ std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibilityImpl( } } - if (ignoreSortOrder) { + if (options.IgnoreSortOrder) { return result; } @@ -218,14 +217,12 @@ std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibilityImpl( std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibility( const TTableSchema& inputSchema, const TTableSchema& outputSchema, - bool ignoreSortOrder, - bool forbidExtraComputedColumns) + TTableSchemaCompatibilityOptions options) { auto result = CheckTableSchemaCompatibilityImpl( inputSchema, outputSchema, - ignoreSortOrder, - forbidExtraComputedColumns); + options); if (result.first != ESchemaCompatibility::FullyCompatible) { result.second = TError(NTableClient::EErrorCode::IncompatibleSchemas, "Table schemas are incompatible") << result.second diff --git a/yt/yt/client/table_client/check_schema_compatibility.h b/yt/yt/client/table_client/check_schema_compatibility.h index 4fa260bb8d..5f38be121f 100644 --- a/yt/yt/client/table_client/check_schema_compatibility.h +++ b/yt/yt/client/table_client/check_schema_compatibility.h @@ -6,6 +6,12 @@ namespace NYT::NTableClient { //////////////////////////////////////////////////////////////////////////////// +struct TTableSchemaCompatibilityOptions +{ + bool IgnoreSortOrder; + bool ForbidExtraComputedColumns = true; +}; + // Validates that values from table with inputSchema also match outputSchema. // // Result pair contains following elements: @@ -15,8 +21,7 @@ namespace NYT::NTableClient { std::pair<ESchemaCompatibility, TError> CheckTableSchemaCompatibility( const TTableSchema& inputSchema, const TTableSchema& outputSchema, - bool ignoreSortOrder, - bool forbidExtraComputedColumns = true); + TTableSchemaCompatibilityOptions options); //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/client/table_client/schema.cpp b/yt/yt/client/table_client/schema.cpp index c03818a999..b191f8c6b5 100644 --- a/yt/yt/client/table_client/schema.cpp +++ b/yt/yt/client/table_client/schema.cpp @@ -1564,6 +1564,16 @@ void ValidateKeyColumns(const TKeyColumns& keyColumns) //////////////////////////////////////////////////////////////////////////////// +void ValidateDynamicTableKeyColumnCount(int count) +{ + THROW_ERROR_EXCEPTION_IF(count > MaxKeyColumnCountInDynamicTable, + "Too many key columns: expected <= %v, got %v", + MaxKeyColumnCountInDynamicTable, + count); +} + +//////////////////////////////////////////////////////////////////////////////// + void ValidateSystemColumnSchema( const TColumnSchema& columnSchema, bool isTableSorted, @@ -1766,11 +1776,7 @@ void ValidateDynamicTableConstraints(const TTableSchema& schema) THROW_ERROR_EXCEPTION("There must be at least one non-key column"); } - if (schema.GetKeyColumnCount() > MaxKeyColumnCountInDynamicTable) { - THROW_ERROR_EXCEPTION("Too many key columns: limit %v, actual: %v", - MaxKeyColumnCountInDynamicTable, - schema.GetKeyColumnCount()); - } + ValidateDynamicTableKeyColumnCount(schema.GetKeyColumnCount()); for (const auto& column : schema.Columns()) { try { diff --git a/yt/yt/client/table_client/schema.h b/yt/yt/client/table_client/schema.h index 7813c7b888..4c7a8f0172 100644 --- a/yt/yt/client/table_client/schema.h +++ b/yt/yt/client/table_client/schema.h @@ -479,6 +479,8 @@ std::vector<TColumnStableName> MapNamesToStableNames( void ValidateKeyColumns(const TKeyColumns& keyColumns); +void ValidateDynamicTableKeyColumnCount(int count); + void ValidateColumnName(const TString& name); void ValidateColumnSchema( diff --git a/yt/yt/client/unittests/check_schema_compatibility_ut.cpp b/yt/yt/client/unittests/check_schema_compatibility_ut.cpp index c002a3b19c..aecb7029fe 100644 --- a/yt/yt/client/unittests/check_schema_compatibility_ut.cpp +++ b/yt/yt/client/unittests/check_schema_compatibility_ut.cpp @@ -34,7 +34,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", EValueType::Int64), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::FullyCompatible, @@ -45,7 +45,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", EValueType::Int64), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::Incompatible, @@ -57,7 +57,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", EValueType::Int64), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::Incompatible, @@ -68,7 +68,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", EValueType::Uint64), }), - /*ignoreSortOrder*/ true ).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::FullyCompatible, @@ -79,7 +79,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", ESimpleLogicalValueType::Int64), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::RequireValidation, @@ -90,7 +90,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", ESimpleLogicalValueType::Int8), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::FullyCompatible, @@ -101,7 +101,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", OptionalLogicalType(SimpleLogicalType(ESimpleLogicalValueType::Int64))), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::RequireValidation, @@ -112,7 +112,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", SimpleLogicalType(ESimpleLogicalValueType::Int64)), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); // Missing "foo" values are filled with nulls that's OK. EXPECT_EQ( @@ -122,7 +122,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", OptionalLogicalType(SimpleLogicalType(ESimpleLogicalValueType::Int64))), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); // First table might have column foo with value of any type EXPECT_EQ( @@ -132,7 +132,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", OptionalLogicalType(SimpleLogicalType(ESimpleLogicalValueType::Int64))), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); // Missing "foo" values are filled with nulls that's OK. EXPECT_EQ( @@ -142,7 +142,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("foo", ESimpleLogicalValueType::Int64), }), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); EXPECT_EQ( ESchemaCompatibility::Incompatible, @@ -154,7 +154,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TTableSchema({ TColumnSchema("b", ESimpleLogicalValueType::Int64), }, /*strict*/ false), - /*ignoreSortOrder*/ true).first); + {.IgnoreSortOrder=true}).first); // // ignoreSortOrder = false @@ -169,7 +169,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TColumnSchema("a", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), TColumnSchema("b", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), }), - /*ignoreSortOrder*/ false).first); + {.IgnoreSortOrder=false}).first); EXPECT_EQ( ESchemaCompatibility::Incompatible, @@ -182,7 +182,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TColumnSchema("a", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), TColumnSchema("b", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), }), - /*ignoreSortOrder*/ false).first); + {.IgnoreSortOrder=false}).first); EXPECT_EQ( ESchemaCompatibility::FullyCompatible, @@ -195,7 +195,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TColumnSchema("a", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), TColumnSchema("b", ESimpleLogicalValueType::Int64), }), - /*ignoreSortOrder*/ false).first); + {.IgnoreSortOrder=false}).first); EXPECT_EQ( ESchemaCompatibility::Incompatible, @@ -208,7 +208,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TColumnSchema("a", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), TColumnSchema("b", ESimpleLogicalValueType::Int64), }, /*strict*/ true, /*uniqueKeys*/ true), - /*ignoreSortOrder*/ false).first); + {.IgnoreSortOrder=false}).first); EXPECT_EQ( ESchemaCompatibility::FullyCompatible, @@ -221,7 +221,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TColumnSchema("a", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), TColumnSchema("b", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), }, /*strict*/ true, /*uniqueKeys*/ true), - /*ignoreSortOrder*/ false).first); + {.IgnoreSortOrder=false}).first); EXPECT_EQ( ESchemaCompatibility::Incompatible, @@ -234,7 +234,7 @@ TEST_F(TTableSchemaCompatibilityTest, CheckTableSchemaCompatibilityTest) TColumnSchema("b", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), TColumnSchema("a", ESimpleLogicalValueType::Int64, ESortOrder::Ascending), }), - /*ignoreSortOrder*/ false).first); + {.IgnoreSortOrder=false}).first); } TEST_F(TTableSchemaCompatibilityTest, TestCheckTableSchemaCompatibility) @@ -251,7 +251,7 @@ TEST_F(TTableSchemaCompatibilityTest, TestCheckTableSchemaCompatibility) TColumnSchema("key2", ESimpleLogicalValueType::String, ESortOrder::Descending), TColumnSchema("value", ESimpleLogicalValueType::String), }), - false).first); + {.IgnoreSortOrder=false}).first); EXPECT_EQ( ESchemaCompatibility::FullyCompatible, @@ -266,7 +266,7 @@ TEST_F(TTableSchemaCompatibilityTest, TestCheckTableSchemaCompatibility) TColumnSchema("key2", ESimpleLogicalValueType::String), TColumnSchema("value", ESimpleLogicalValueType::String), }), - false).first); + {.IgnoreSortOrder=false}).first); EXPECT_EQ( ESchemaCompatibility::Incompatible, @@ -281,7 +281,7 @@ TEST_F(TTableSchemaCompatibilityTest, TestCheckTableSchemaCompatibility) TColumnSchema("key2", ESimpleLogicalValueType::String, ESortOrder::Descending), TColumnSchema("value", ESimpleLogicalValueType::String), }), - false).first); + {.IgnoreSortOrder=false}).first); } TEST_F(TTableSchemaCompatibilityTest, DeletedColumns) @@ -299,7 +299,7 @@ TEST_F(TTableSchemaCompatibilityTest, DeletedColumns) TColumnSchema("value", ESimpleLogicalValueType::String), TColumnSchema("value1", ESimpleLogicalValueType::String), }, true, true, {}), - false); + {.IgnoreSortOrder=false}); EXPECT_EQ(ESchemaCompatibility::Incompatible, comp.first); EXPECT_EQ("Column \"value1\" in output schema was deleted in the input schema", @@ -318,7 +318,7 @@ TEST_F(TTableSchemaCompatibilityTest, DeletedColumns) { TDeletedColumn(TColumnStableName("value1")), }), - false); + {.IgnoreSortOrder=false}); EXPECT_EQ(ESchemaCompatibility::Incompatible, comp.first); EXPECT_EQ("Deleted column \"value1\" is missing in the input schema", |