Skip to content

Commit 5564d24

Browse files
authored
Merge 276da56 into 2ed4fb0
2 parents 2ed4fb0 + 276da56 commit 5564d24

File tree

5 files changed

+81
-22
lines changed

5 files changed

+81
-22
lines changed

ydb/core/grpc_services/rpc_create_table.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,28 @@ class TCreateTableRPC : public TRpcSchemeRequestActor<TCreateTableRPC, TEvCreate
181181
return;
182182
}
183183

184+
StatusIds::StatusCode code = StatusIds::SUCCESS;
185+
TString error;
186+
187+
bool hasSerial = false;
188+
for (const auto& column : req->columns()) {
189+
switch (column.default_value_case()) {
190+
case Ydb::Table::ColumnMeta::kFromSequence: {
191+
auto* seqDesc = modifyScheme->MutableCreateIndexedTable()->MutableSequenceDescription()->Add();
192+
if (!FillSequenceDescription(*seqDesc, column.from_sequence(), code, error)) {
193+
NYql::TIssues issues;
194+
issues.AddIssue(NYql::TIssue(error));
195+
return Reply(code, issues, ctx);
196+
}
197+
hasSerial = true;
198+
break;
199+
}
200+
default: break;
201+
}
202+
}
203+
184204
NKikimrSchemeOp::TTableDescription* tableDesc = nullptr;
185-
if (req->indexesSize()) {
205+
if (req->indexesSize() || hasSerial) {
186206
modifyScheme->SetOperationType(NKikimrSchemeOp::EOperationType::ESchemeOpCreateIndexedTable);
187207
tableDesc = modifyScheme->MutableCreateIndexedTable()->MutableTableDescription();
188208
} else {
@@ -192,9 +212,6 @@ class TCreateTableRPC : public TRpcSchemeRequestActor<TCreateTableRPC, TEvCreate
192212

193213
tableDesc->SetName(name);
194214

195-
StatusIds::StatusCode code = StatusIds::SUCCESS;
196-
TString error;
197-
198215
if (!FillColumnDescription(*tableDesc, req->columns(), code, error)) {
199216
NYql::TIssues issues;
200217
issues.AddIssue(NYql::TIssue(error));

ydb/core/ydb_convert/table_description.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,6 @@ bool FillTableDescription(NKikimrSchemeOp::TModifyScheme& out,
14231423
const Ydb::Table::CreateTableRequest& in, const TTableProfiles& profiles,
14241424
Ydb::StatusIds::StatusCode& status, TString& error, bool indexedTable)
14251425
{
1426-
14271426
NKikimrSchemeOp::TTableDescription* tableDesc = nullptr;
14281427
if (indexedTable) {
14291428
tableDesc = out.MutableCreateIndexedTable()->MutableTableDescription();

ydb/library/backup/backup.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,19 +742,26 @@ void BackupFolder(TDriver driver, const TString& database, const TString& relDbP
742742
// Restore
743743
////////////////////////////////////////////////////////////////////////////////
744744

745-
TString ProcessColumnType(const TString& name, TTypeParser parser, NTable::TTableBuilder *builder) {
745+
TString ProcessColumnType(const TString& name, TTypeParser parser, NTable::TTableBuilder *builder, bool isSerial) {
746746
TStringStream ss;
747747
ss << "name: " << name << "; ";
748748
if (parser.GetKind() == TTypeParser::ETypeKind::Optional) {
749749
ss << " optional; ";
750750
parser.OpenOptional();
751751
}
752+
if (isSerial) {
753+
ss << "serial; ";
754+
}
752755
ss << "kind: " << parser.GetKind() << "; ";
753756
switch (parser.GetKind()) {
754757
case TTypeParser::ETypeKind::Primitive:
755758
ss << " type_id: " << parser.GetPrimitive() << "; ";
756759
if (builder) {
757-
builder->AddNullableColumn(name, parser.GetPrimitive());
760+
if (isSerial) {
761+
builder->AddSerialColumn(name, parser.GetPrimitive());
762+
} else {
763+
builder->AddNullableColumn(name, parser.GetPrimitive());
764+
}
758765
}
759766
break;
760767
case TTypeParser::ETypeKind::Decimal:
@@ -776,7 +783,17 @@ NTable::TTableDescription TableDescriptionFromProto(const Ydb::Table::CreateTabl
776783
NTable::TTableBuilder builder;
777784

778785
for (const auto &col : proto.Getcolumns()) {
779-
LOG_DEBUG("AddNullableColumn: " << ProcessColumnType(col.Getname(), TType(col.Gettype()), &builder));
786+
bool isSerial = false;
787+
switch (col.default_value_case()) {
788+
case Ydb::Table::ColumnMeta::kFromSequence: {
789+
if (col.from_sequence().name() == "_serial_" + col.Getname()) {
790+
isSerial = true;
791+
}
792+
break;
793+
}
794+
default: break;
795+
}
796+
LOG_DEBUG("AddColumn: " << ProcessColumnType(col.Getname(), TType(col.Gettype()), &builder, isSerial));
780797
}
781798

782799
for (const auto &primary : proto.Getprimary_key()) {
@@ -805,7 +822,7 @@ TString SerializeColumnsToString(const TVector<TColumn>& columns, TVector<TStrin
805822
if (BinarySearch(primary.cbegin(), primary.cend(), col.Name)) {
806823
ss << "primary; ";
807824
}
808-
ss << ProcessColumnType(col.Name, col.Type, nullptr) << Endl;
825+
ss << ProcessColumnType(col.Name, col.Type, nullptr, false) << Endl;
809826
}
810827
// Cerr << "Parse column to : " << ss.Str() << Endl;
811828
return ss.Str();

ydb/public/sdk/cpp/client/ydb_table/table.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,17 @@ class TTableDescription::TImpl {
291291
if (col.has_not_null()) {
292292
not_null = col.not_null();
293293
}
294-
Columns_.emplace_back(col.name(), col.type(), col.family(), not_null);
294+
std::optional<bool> isSerial;
295+
switch (col.default_value_case()) {
296+
case Ydb::Table::ColumnMeta::kFromSequence: {
297+
if (col.from_sequence().name() == "_serial_column_" + col.name()) {
298+
isSerial = true;
299+
}
300+
break;
301+
}
302+
default: break;
303+
}
304+
Columns_.emplace_back(col.name(), col.type(), col.family(), not_null, isSerial);
295305
}
296306

297307
// indexes
@@ -453,8 +463,8 @@ class TTableDescription::TImpl {
453463
return Proto_;
454464
}
455465

456-
void AddColumn(const TString& name, const Ydb::Type& type, const TString& family, std::optional<bool> notNull) {
457-
Columns_.emplace_back(name, type, family, notNull);
466+
void AddColumn(const TString& name, const Ydb::Type& type, const TString& family, std::optional<bool> notNull, std::optional<bool> isSerial) {
467+
Columns_.emplace_back(name, type, family, notNull, isSerial);
458468
}
459469

460470
void SetPrimaryKeyColumns(const TVector<TString>& primaryKeyColumns) {
@@ -737,8 +747,8 @@ const TVector<TKeyRange>& TTableDescription::GetKeyRanges() const {
737747
return Impl_->GetKeyRanges();
738748
}
739749

740-
void TTableDescription::AddColumn(const TString& name, const Ydb::Type& type, const TString& family, std::optional<bool> notNull) {
741-
Impl_->AddColumn(name, type, family, notNull);
750+
void TTableDescription::AddColumn(const TString& name, const Ydb::Type& type, const TString& family, std::optional<bool> notNull, std::optional<bool> isSerial) {
751+
Impl_->AddColumn(name, type, family, notNull, isSerial);
742752
}
743753

744754
void TTableDescription::SetPrimaryKeyColumns(const TVector<TString>& primaryKeyColumns) {
@@ -914,6 +924,10 @@ void TTableDescription::SerializeTo(Ydb::Table::CreateTableRequest& request) con
914924
if (column.NotNull.has_value()) {
915925
protoColumn.set_not_null(column.NotNull.value());
916926
}
927+
if (column.IsSerial.has_value() && column.IsSerial.value()) {
928+
auto* fromSequence = protoColumn.mutable_from_sequence();
929+
fromSequence->set_name("_serial_column_" + column.Name);
930+
}
917931
}
918932

919933
for (const auto& pk : Impl_->GetPrimaryKeyColumns()) {
@@ -1121,7 +1135,7 @@ TTableBuilder& TTableBuilder::AddNullableColumn(const TString& name, const EPrim
11211135
.EndOptional()
11221136
.Build();
11231137

1124-
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false);
1138+
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false, false);
11251139
return *this;
11261140
}
11271141

@@ -1131,7 +1145,7 @@ TTableBuilder& TTableBuilder::AddNullableColumn(const TString& name, const TDeci
11311145
.Decimal(type)
11321146
.EndOptional()
11331147
.Build();
1134-
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false);
1148+
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false, false);
11351149
return *this;
11361150
}
11371151

@@ -1140,7 +1154,7 @@ TTableBuilder& TTableBuilder::AddNullableColumn(const TString& name, const TPgTy
11401154
.Pg(type)
11411155
.Build();
11421156

1143-
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false);
1157+
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false, false);
11441158
return *this;
11451159
}
11461160

@@ -1149,7 +1163,7 @@ TTableBuilder& TTableBuilder::AddNonNullableColumn(const TString& name, const EP
11491163
.Primitive(type)
11501164
.Build();
11511165

1152-
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true);
1166+
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, false);
11531167
return *this;
11541168
}
11551169

@@ -1158,7 +1172,7 @@ TTableBuilder& TTableBuilder::AddNonNullableColumn(const TString& name, const TD
11581172
.Decimal(type)
11591173
.Build();
11601174

1161-
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true);
1175+
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, false);
11621176
return *this;
11631177
}
11641178

@@ -1167,7 +1181,16 @@ TTableBuilder& TTableBuilder::AddNonNullableColumn(const TString& name, const TP
11671181
.Pg(type)
11681182
.Build();
11691183

1170-
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true);
1184+
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, false);
1185+
return *this;
1186+
}
1187+
1188+
TTableBuilder& TTableBuilder::AddSerialColumn(const TString& name, const EPrimitiveType& type, const TString& family) {
1189+
auto columnType = TTypeBuilder()
1190+
.Primitive(type)
1191+
.Build();
1192+
1193+
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, true);
11711194
return *this;
11721195
}
11731196

ydb/public/sdk/cpp/client/ydb_table/table.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,16 @@ struct TTableColumn {
105105
TType Type;
106106
TString Family;
107107
std::optional<bool> NotNull;
108+
std::optional<bool> IsSerial;
108109

109110
TTableColumn() = default;
110111

111-
TTableColumn(TString name, TType type, TString family = TString(), std::optional<bool> notNull = std::nullopt)
112+
TTableColumn(TString name, TType type, TString family, std::optional<bool> notNull, std::optional<bool> isSerial)
112113
: Name(std::move(name))
113114
, Type(std::move(type))
114115
, Family(std::move(family))
115116
, NotNull(std::move(notNull))
117+
, IsSerial(isSerial)
116118
{ }
117119

118120
// Conversion from TColumn for API compatibility
@@ -636,7 +638,7 @@ class TTableDescription {
636638
TTableDescription();
637639
explicit TTableDescription(const Ydb::Table::CreateTableRequest& request);
638640

639-
void AddColumn(const TString& name, const Ydb::Type& type, const TString& family, std::optional<bool> notNull);
641+
void AddColumn(const TString& name, const Ydb::Type& type, const TString& family, std::optional<bool> notNull, std::optional<bool> isSerial);
640642
void SetPrimaryKeyColumns(const TVector<TString>& primaryKeyColumns);
641643

642644
// common
@@ -854,6 +856,7 @@ class TTableBuilder {
854856
TTableBuilder& AddNonNullableColumn(const TString& name, const TPgType& type, const TString& family = TString());
855857
TTableBuilder& SetPrimaryKeyColumns(const TVector<TString>& primaryKeyColumns);
856858
TTableBuilder& SetPrimaryKeyColumn(const TString& primaryKeyColumn);
859+
TTableBuilder& AddSerialColumn(const TString& name, const EPrimitiveType& type, const TString& family = TString());
857860

858861
// common
859862
TTableBuilder& AddSecondaryIndex(const TIndexDescription& indexDescription);

0 commit comments

Comments
 (0)