Skip to content

Sync sdks 8 #320

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

Merged
merged 6 commits into from
Sep 23, 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
1 change: 1 addition & 0 deletions examples/secondary_index/secondary_index_generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <util/thread/pool.h>

#include <mutex>
#include <random>

using namespace NLastGetopt;
Expand Down
5 changes: 5 additions & 0 deletions include/ydb-cpp-sdk/client/rate_limiter/rate_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ class TRateLimiterClient {
TAsyncDescribeResourceResult DescribeResource(const std::string& coordinationNodePath, const std::string& resourcePath, const TDescribeResourceSettings& = {});

// Acquire resources's units inside a coordination node.
// If CancelAfter is set greater than zero and less than OperationTimeout
// and resource is not ready after CancelAfter time,
// the result code of this operation will be CANCELLED and resource will not be spent.
// It is recommended to specify both OperationTimeout and CancelAfter.
// CancelAfter should be less than OperationTimeout.
TAsyncStatus AcquireResource(const std::string& coordinationNodePath, const std::string& resourcePath, const TAcquireResourceSettings& = {});

private:
Expand Down
20 changes: 18 additions & 2 deletions include/ydb-cpp-sdk/client/table/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,33 @@ class TKeyRange {
std::optional<TKeyBound> To_;
};

struct TSequenceDescription {
struct TSetVal {
int64_t NextValue;
bool NextUsed;
};
std::optional<TSetVal> SetVal;
};

struct TTableColumn {
std::string Name;
TType Type;
std::string Family;
std::optional<bool> NotNull;
std::optional<TSequenceDescription> SequenceDescription;

TTableColumn() = default;

TTableColumn(std::string name, TType type, std::string family = std::string(), std::optional<bool> notNull = std::nullopt)
TTableColumn(std::string name,
TType type,
std::string family = std::string(),
std::optional<bool> notNull = std::nullopt,
std::optional<TSequenceDescription> sequenceDescription = std::nullopt)
: Name(std::move(name))
, Type(std::move(type))
, Family(std::move(family))
, NotNull(std::move(notNull))
, SequenceDescription(std::move(sequenceDescription))
{ }

// Conversion from TColumn for API compatibility
Expand Down Expand Up @@ -634,7 +648,7 @@ class TTableDescription {
TTableDescription();
explicit TTableDescription(const Ydb::Table::CreateTableRequest& request);

void AddColumn(const std::string& name, const Ydb::Type& type, const std::string& family, std::optional<bool> notNull);
void AddColumn(const std::string& name, const Ydb::Type& type, const std::string& family, std::optional<bool> notNull, std::optional<TSequenceDescription> sequenceDescription);
void SetPrimaryKeyColumns(const std::vector<std::string>& primaryKeyColumns);

// common
Expand Down Expand Up @@ -852,6 +866,7 @@ class TTableBuilder {
TTableBuilder& AddNonNullableColumn(const std::string& name, const TPgType& type, const std::string& family = std::string());
TTableBuilder& SetPrimaryKeyColumns(const std::vector<std::string>& primaryKeyColumns);
TTableBuilder& SetPrimaryKeyColumn(const std::string& primaryKeyColumn);
TTableBuilder& AddSerialColumn(const std::string& name, const EPrimitiveType& type, TSequenceDescription sequenceDescription, const std::string& family = std::string());

// common
TTableBuilder& AddSecondaryIndex(const TIndexDescription& indexDescription);
Expand Down Expand Up @@ -1627,6 +1642,7 @@ struct TDescribeTableSettings : public TOperationRequestSettings<TDescribeTableS
FLUENT_SETTING_DEFAULT(bool, WithKeyShardBoundary, false);
FLUENT_SETTING_DEFAULT(bool, WithTableStatistics, false);
FLUENT_SETTING_DEFAULT(bool, WithPartitionStatistics, false);
FLUENT_SETTING_DEFAULT(bool, WithSetVal, false);
};

struct TExplainDataQuerySettings : public TOperationRequestSettings<TExplainDataQuerySettings> {
Expand Down
5 changes: 5 additions & 0 deletions src/api/protos/ydb_rate_limiter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ message DescribeResourceResult {
//

message AcquireResourceRequest {
// If cancel_after is set greater than zero and less than operation_timeout
// and resource is not ready after cancel_after time,
// the result code of this operation will be CANCELLED and resource will not be spent.
// It is recommended to specify both operation_timeout and cancel_after.
// cancel_after should be less than operation_timeout and non zero.
Ydb.Operations.OperationParams operation_params = 1;

// Path of a coordination node.
Expand Down
2 changes: 2 additions & 0 deletions src/api/protos/ydb_table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ message DescribeTableRequest {
bool include_table_stats = 6;
// Includes partition statistics (required include_table_statistics)
bool include_partition_stats = 7;
// Includes set_val settings for sequences
bool include_set_val = 8;
}

message DescribeTableResponse {
Expand Down
4 changes: 4 additions & 0 deletions src/client/table/impl/table_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ TAsyncDescribeTableResult TTableClient::TImpl::DescribeTable(const std::string&
request.set_include_partition_stats(true);
}

if (settings.WithSetVal_) {
request.set_include_set_val(true);
}

auto promise = NewPromise<TDescribeTableResult>();

auto extractor = [promise, settings]
Expand Down
57 changes: 46 additions & 11 deletions src/client/table/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,24 @@ class TTableDescription::TImpl {
if (col.has_not_null()) {
not_null = col.not_null();
}
Columns_.emplace_back(col.name(), col.type(), col.family(), not_null);
std::optional<TSequenceDescription> sequenceDescription;
switch (col.default_value_case()) {
case Ydb::Table::ColumnMeta::kFromSequence: {
if (col.from_sequence().name() == "_serial_column_" + col.name()) {
TSequenceDescription currentSequenceDescription;
if (col.from_sequence().has_set_val()) {
TSequenceDescription::TSetVal setVal;
setVal.NextUsed = col.from_sequence().set_val().next_used();
setVal.NextValue = col.from_sequence().set_val().next_value();
currentSequenceDescription.SetVal = std::move(setVal);
}
sequenceDescription = std::move(currentSequenceDescription);
}
break;
}
default: break;
}
Columns_.emplace_back(col.name(), col.type(), col.family(), not_null, std::move(sequenceDescription));
}

// indexes
Expand Down Expand Up @@ -453,8 +470,8 @@ class TTableDescription::TImpl {
return Proto_;
}

void AddColumn(const std::string& name, const Ydb::Type& type, const std::string& family, std::optional<bool> notNull) {
Columns_.emplace_back(name, type, family, notNull);
void AddColumn(const std::string& name, const Ydb::Type& type, const std::string& family, std::optional<bool> notNull, std::optional<TSequenceDescription> sequenceDescription) {
Columns_.emplace_back(name, type, family, notNull, std::move(sequenceDescription));
}

void SetPrimaryKeyColumns(const std::vector<std::string>& primaryKeyColumns) {
Expand Down Expand Up @@ -738,8 +755,8 @@ const std::vector<TKeyRange>& TTableDescription::GetKeyRanges() const {
return Impl_->GetKeyRanges();
}

void TTableDescription::AddColumn(const std::string& name, const Ydb::Type& type, const std::string& family, std::optional<bool> notNull) {
Impl_->AddColumn(name, type, family, notNull);
void TTableDescription::AddColumn(const std::string& name, const Ydb::Type& type, const std::string& family, std::optional<bool> notNull, std::optional<TSequenceDescription> sequenceDescription) {
Impl_->AddColumn(name, type, family, notNull, std::move(sequenceDescription));
}

void TTableDescription::SetPrimaryKeyColumns(const std::vector<std::string>& primaryKeyColumns) {
Expand Down Expand Up @@ -915,6 +932,15 @@ void TTableDescription::SerializeTo(Ydb::Table::CreateTableRequest& request) con
if (column.NotNull.has_value()) {
protoColumn.set_not_null(column.NotNull.value());
}
if (column.SequenceDescription.has_value()) {
auto* fromSequence = protoColumn.mutable_from_sequence();
if (column.SequenceDescription->SetVal.has_value()) {
auto* setVal = fromSequence->mutable_set_val();
setVal->set_next_value(column.SequenceDescription->SetVal->NextValue);
setVal->set_next_used(column.SequenceDescription->SetVal->NextUsed);
}
fromSequence->set_name("_serial_column_" + column.Name);
}
}

for (const auto& pk : Impl_->GetPrimaryKeyColumns()) {
Expand Down Expand Up @@ -1122,7 +1148,7 @@ TTableBuilder& TTableBuilder::AddNullableColumn(const std::string& name, const E
.EndOptional()
.Build();

TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false);
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false, std::nullopt);
return *this;
}

Expand All @@ -1132,7 +1158,7 @@ TTableBuilder& TTableBuilder::AddNullableColumn(const std::string& name, const T
.Decimal(type)
.EndOptional()
.Build();
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false);
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false, std::nullopt);
return *this;
}

Expand All @@ -1141,7 +1167,7 @@ TTableBuilder& TTableBuilder::AddNullableColumn(const std::string& name, const T
.Pg(type)
.Build();

TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false);
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, false, std::nullopt);
return *this;
}

Expand All @@ -1150,7 +1176,7 @@ TTableBuilder& TTableBuilder::AddNonNullableColumn(const std::string& name, cons
.Primitive(type)
.Build();

TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true);
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, std::nullopt);
return *this;
}

Expand All @@ -1159,7 +1185,7 @@ TTableBuilder& TTableBuilder::AddNonNullableColumn(const std::string& name, cons
.Decimal(type)
.Build();

TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true);
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, std::nullopt);
return *this;
}

Expand All @@ -1168,7 +1194,16 @@ TTableBuilder& TTableBuilder::AddNonNullableColumn(const std::string& name, cons
.Pg(type)
.Build();

TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true);
TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, std::nullopt);
return *this;
}

TTableBuilder& TTableBuilder::AddSerialColumn(const std::string& name, const EPrimitiveType& type, TSequenceDescription sequenceDescription, const std::string& family) {
auto columnType = TTypeBuilder()
.Primitive(type)
.Build();

TableDescription_.AddColumn(name, TProtoAccessor::GetProto(columnType), family, true, std::move(sequenceDescription));
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/topic/ut/local_partition_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace NYdb::NTopic::NTests {

private:
Ydb::Discovery::ListEndpointsResult MockResults;
TString DiscoveryAddr = 0;
TString DiscoveryAddr;
std::unique_ptr<grpc::Server> Server;
TAdaptiveLock Lock;

Expand Down
Loading
Loading