diff --git a/ydb/apps/ydb/ut/ya.make b/ydb/apps/ydb/ut/ya.make index 6f672b2784c5..f73cdbcff05e 100644 --- a/ydb/apps/ydb/ut/ya.make +++ b/ydb/apps/ydb/ut/ya.make @@ -16,6 +16,7 @@ SRCS( run_ydb.cpp supported_codecs.cpp supported_codecs_fixture.cpp + ydb-dump.cpp ) PEERDIR( diff --git a/ydb/apps/ydb/ut/ydb-dump.cpp b/ydb/apps/ydb/ut/ydb-dump.cpp new file mode 100644 index 000000000000..5fc7d15f8d83 --- /dev/null +++ b/ydb/apps/ydb/ut/ydb-dump.cpp @@ -0,0 +1,72 @@ +#include "run_ydb.h" + +#include + +#include +#include + +#include + +#include + +Y_UNIT_TEST_SUITE(YdbDump) { + +Y_UNIT_TEST(NotNullTypeDump) { + RunYdb({"-v", "yql", "-s", + R"(CREATE TABLE TableWithNotNullTypeForDump ( + k Uint32 NOT NULL, + v String NOT NULL, + ov String, + PRIMARY KEY(k)); + )"}, + TList()); + + const TString output = RunYdb({"-v", "tools", "dump", "--scheme-only"}, TList()); + + struct TFlags { + const bool HasNullFlag; + const bool IsOptionalType; + }; + + TVector column_flags; + auto fillFlag = [&column_flags](const TString& str) { + Ydb::Table::ColumnMeta meta; + google::protobuf::TextFormat::ParseFromString(str, &meta); + column_flags.emplace_back(TFlags{meta.has_not_null(), meta.type().has_optional_type()}); + }; + + const TString token = "columns {"; + size_t start = 0; + while (true) { + start = output.find(token, start); + if (start != TString::npos) { + int scope = 1; + start += token.size(); + size_t pos = start; + while (pos < output.size() && scope != 0) { + if (output[pos] == '{') { + scope++; + } else if (output[pos] == '}') { + scope--; + } + pos++; + } + Y_ABORT_UNLESS(pos > start); + fillFlag(output.substr(start, pos - start - 1)); + start = pos; + } else { + break; + } + } + + // For compatibility reason we do not show not null flag + UNIT_ASSERT_VALUES_EQUAL(column_flags.size(), 3); + UNIT_ASSERT_VALUES_EQUAL(column_flags[0].HasNullFlag, false); + UNIT_ASSERT_VALUES_EQUAL(column_flags[0].IsOptionalType, false); + UNIT_ASSERT_VALUES_EQUAL(column_flags[1].HasNullFlag, false); + UNIT_ASSERT_VALUES_EQUAL(column_flags[1].IsOptionalType, false); + UNIT_ASSERT_VALUES_EQUAL(column_flags[2].HasNullFlag, false); + UNIT_ASSERT_VALUES_EQUAL(column_flags[2].IsOptionalType, true); +} + +} diff --git a/ydb/public/sdk/cpp/client/ydb_table/table.cpp b/ydb/public/sdk/cpp/client/ydb_table/table.cpp index 647cae8973d1..b8b1c00a31a7 100644 --- a/ydb/public/sdk/cpp/client/ydb_table/table.cpp +++ b/ydb/public/sdk/cpp/client/ydb_table/table.cpp @@ -268,7 +268,11 @@ class TTableDescription::TImpl { // columns for (const auto& col : proto.columns()) { - Columns_.emplace_back(col.name(), col.type(), col.family(), col.not_null()); + std::optional not_null; + if (col.has_not_null()) { + not_null = col.not_null(); + } + Columns_.emplace_back(col.name(), col.type(), col.family(), not_null); } // indexes