Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optional<bool> flag for c++ sdk. #5160

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ydb/apps/ydb/ut/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SRCS(
run_ydb.cpp
supported_codecs.cpp
supported_codecs_fixture.cpp
ydb-dump.cpp
)

PEERDIR(
Expand Down
72 changes: 72 additions & 0 deletions ydb/apps/ydb/ut/ydb-dump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "run_ydb.h"

#include <util/string/split.h>

#include <library/cpp/testing/common/env.h>
#include <library/cpp/testing/unittest/registar.h>

#include <ydb/public/sdk/cpp/client/ydb_table/table.h>

#include <ydb/public/api/protos/ydb_table.pb.h>

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<TString>());

const TString output = RunYdb({"-v", "tools", "dump", "--scheme-only"}, TList<TString>());

struct TFlags {
const bool HasNullFlag;
const bool IsOptionalType;
};

TVector<TFlags> 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);
}

}
6 changes: 5 additions & 1 deletion ydb/public/sdk/cpp/client/ydb_table/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> not_null;
if (col.has_not_null()) {
not_null = col.not_null();
}
Columns_.emplace_back(col.name(), col.type(), col.family(), not_null);
}

// indexes
Expand Down
Loading