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

KIKIMR-18545: do not set not_null for default values #3512

Merged
merged 1 commit into from
Apr 8, 2024
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
22 changes: 16 additions & 6 deletions ydb/core/kqp/ut/opt/kqp_not_null_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,8 +1966,8 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
{"Value3", "Pg('pgint2','',21,0,0)"}
};

const THashMap<std::string_view, bool> columnNullability = {
{"Key1", true},
const THashMap<std::string_view, bool> columnNonNullability = {
{"Key1", false},
{"Key2", false},
{"Value1", false},
{"Value2", false},
Expand All @@ -1977,7 +1977,12 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
const auto& columns = describeTableResult.GetTableDescription().GetTableColumns();
for (const auto& column : columns) {
UNIT_ASSERT_VALUES_EQUAL_C(column.Type.ToString(), columnTypes.at(column.Name), column.Name);
UNIT_ASSERT_VALUES_EQUAL_C(column.NotNull.value(), columnNullability.at(column.Name), column.Name);
bool isNotNull = columnNonNullability.at(column.Name);
if (isNotNull) {
UNIT_ASSERT_VALUES_EQUAL_C(column.NotNull.value(), true, column.Name);
} else {
UNIT_ASSERT_C(!column.NotNull.has_value() || !column.NotNull.value(), column.Name);
}
}
}

Expand All @@ -1997,16 +2002,21 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
}
auto describeTableResult = session.DescribeTable("/Root/NotNullCheck").GetValueSync();
UNIT_ASSERT_C(describeTableResult.IsSuccess(), describeTableResult.GetIssues().ToString());
const THashMap<std::string_view, bool> columnNullability = {
const THashMap<std::string_view, bool> columnNonNullability = {
{"1", false},
{"2", true},
{"2", false},
{"3", false},
{"4", true},
};

const auto& columns = describeTableResult.GetTableDescription().GetTableColumns();
for (const auto& column : columns) {
UNIT_ASSERT_VALUES_EQUAL_C(column.NotNull.value(), columnNullability.at(column.Name), column.Name);
bool isNotNull = columnNonNullability.at(column.Name);
if (isNotNull) {
UNIT_ASSERT_VALUES_EQUAL_C(column.NotNull.value(), true, column.Name);
} else {
UNIT_ASSERT_C(!column.NotNull.has_value() || !column.NotNull.value(), column.Name);
}
}

{
Expand Down
2 changes: 0 additions & 2 deletions ydb/core/tx/schemeshard/ut_export/ut_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ Y_UNIT_TEST_SUITE(TExportToS3Tests) {
}
}
}
not_null: false
from_literal {
type {
optional_type {
Expand All @@ -390,7 +389,6 @@ columns {
}
}
}
not_null: false
from_literal {
type {
optional_type {
Expand Down
10 changes: 6 additions & 4 deletions ydb/core/ydb_convert/table_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,15 @@ static Ydb::Type* AddColumn(Ydb::Table::ColumnMeta* newColumn, const TColumn& co
pg->set_oid(NPg::PgTypeIdFromTypeDesc(typeDesc));
pg->set_typlen(0);
pg->set_typmod(0);
if (column.GetNotNull()) {
newColumn->set_not_null(column.GetNotNull());
}
} else {
NYql::NProto::TypeIds protoType;
if (!NYql::NProto::TypeIds_Parse(column.GetType(), &protoType)) {
throw NYql::TErrorException(NKikimrIssues::TIssuesIds::DEFAULT_ERROR)
<< "Got invalid type: " << column.GetType() << " for column: " << column.GetName();
}

if (column.GetNotNull()) {
columnType = newColumn->mutable_type();
} else {
Expand All @@ -392,7 +394,6 @@ static Ydb::Type* AddColumn(Ydb::Table::ColumnMeta* newColumn, const TColumn& co
NMiniKQL::ExportPrimitiveTypeToProto(protoType, *columnType);
}
}
newColumn->set_not_null(column.GetNotNull());
return columnType;
}

Expand All @@ -410,13 +411,15 @@ Ydb::Type* AddColumn<NKikimrSchemeOp::TColumnDescription>(Ydb::Table::ColumnMeta
pg->set_oid(NPg::PgTypeIdFromTypeDesc(typeDesc));
pg->set_typlen(0);
pg->set_typmod(0);
if (column.GetNotNull()) {
newColumn->set_not_null(column.GetNotNull());
}
} else {
NYql::NProto::TypeIds protoType;
if (!NYql::NProto::TypeIds_Parse(column.GetType(), &protoType)) {
throw NYql::TErrorException(NKikimrIssues::TIssuesIds::DEFAULT_ERROR)
<< "Got invalid type: " << column.GetType() << " for column: " << column.GetName();
}

if (column.GetNotNull()) {
columnType = newColumn->mutable_type();
} else {
Expand All @@ -432,7 +435,6 @@ Ydb::Type* AddColumn<NKikimrSchemeOp::TColumnDescription>(Ydb::Table::ColumnMeta
NMiniKQL::ExportPrimitiveTypeToProto(protoType, *columnType);
}
}
newColumn->set_not_null(column.GetNotNull());
switch (column.GetDefaultValueCase()) {
case NKikimrSchemeOp::TColumnDescription::kDefaultFromLiteral: {
auto fromLiteral = newColumn->mutable_from_literal();
Expand Down
4 changes: 0 additions & 4 deletions ydb/services/ydb/ydb_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,6 @@ columns {
}
}
}
not_null: false
}
columns {
name: "Value"
Expand All @@ -1279,7 +1278,6 @@ columns {
}
}
}
not_null: false
}
primary_key: "Key"
partitioning_settings {
Expand Down Expand Up @@ -1607,7 +1605,6 @@ columns {
}
}
}
not_null: false
}
columns {
name: "IValue"
Expand All @@ -1618,7 +1615,6 @@ columns {
}
}
}
not_null: false
}
primary_key: "Key"
indexes {
Expand Down
Loading