-
Notifications
You must be signed in to change notification settings - Fork 12
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
#41 Replace TMaybe to std::optional after update #81
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Привет. Поздравляю с первым PR! 🙂
Из всех файлов отметил только одно критичное замечание (
В остальных местах всё достаточно одинаково — поменять названия, использовать аналогичный метод.
Местами неконсистентный стиль кода после рефакторинга, думаю, автор ишью посмотрит и скажет как сделать.
discoveryMode ? discoveryMode.GetRef() : DefaultDiscoveryMode_, | ||
sslCredentials ? sslCredentials.GetRef() : SslCredentials_, | ||
credentialsProviderFactory ? credentialsProviderFactory.GetRef() : DefaultCredentialsProviderFactory_); | ||
database.has_value() ? database.value() : DefaultDatabase_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Обычно предпочитают явное поведение, тут оно есть.
Но я бы уточнил у автора ишью о стиле. В оригинале используется operator bool.
Ещё есть вопрос поводу самой проверки. value()
внутри тоже проверяет has_value()
и в случае отсутствия выбрасывает исключение. Если мы и так до этого проверили has_value()
, зачем снова это делать?
У нас тут есть default значение ещё, я бы использовал value_or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено.
} else if (settings.RetentionPeriodHours_.Defined()) { | ||
req.set_retention_period_hours(*settings.RetentionPeriodHours_.Get()); | ||
if (settings.RetentionStorageMegabytes_.has_value()) { | ||
req.set_retention_storage_megabytes(settings.RetentionStorageMegabytes_.value()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь тоже двойная проверка, но в оригинале её не было.
Глянь: https://godbolt.org/z/sGccs6Eea
lea rdi, [rbp - 4] // Взять o
call O<int>::Get() const // Вызвать над ним Get
mov esi, dword ptr [rax] // Дереференс указателя
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено.
@@ -67,7 +67,7 @@ void TFederatedWriteSession::OpenSubSessionImpl(std::shared_ptr<TDbInfo> db) { | |||
.ReadyToAcceptHander([self = shared_from_this()](NTopic::TWriteSessionEvent::TReadyToAcceptEvent& ev){ | |||
TDeferredWrite deferred(self->Subsession); | |||
with_lock(self->Lock) { | |||
Y_ABORT_UNLESS(self->PendingToken.Empty()); | |||
Y_ABORT_UNLESS(!(self->PendingToken.has_value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Скобочки лишние как по мне
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрал, но по-идее они есть ещё в коде. В спешке почему-то подумалось, что такой явный стиль (если это можно так назвать) будет уместным. Исправлено.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upd. Постарался убрать по всему своему коду.
@@ -4,6 +4,8 @@ | |||
|
|||
#include <client/ydb_types/fluent_settings_helpers.h> | |||
|
|||
#include <util/stream/output.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему здесь output понадобился?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error: unknown type name 'IOutputStream'
на 41 строке. В свою очередь output.h был включен в maybe.h (возможно вложенно, через ещё один заголовочный файл). Я убрал включение maybe.h и добавил напрямую output.h соответственно в tx.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
О как. Спасибо, что пояснил
@@ -1135,19 +1135,19 @@ void TTableClient::TImpl::SetQuery(const TDataQuery& queryData, Ydb::Table::Quer | |||
void TTableClient::TImpl::SetQueryCachePolicy(const std::string&, const TExecDataQuerySettings& settings, | |||
Ydb::Table::QueryCachePolicy* queryCachePolicy) | |||
{ | |||
queryCachePolicy->set_keep_in_cache(settings.KeepInQueryCache_ ? settings.KeepInQueryCache_.GetRef() : false); | |||
queryCachePolicy->set_keep_in_cache(settings.KeepInQueryCache_ ? settings.KeepInQueryCache_.value() : false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Теоретически может стать value_or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил.
client/ydb_table/table.cpp
Outdated
} | ||
for (const auto& familyPolicy : policy.ColumnFamilies_) { | ||
auto* familyProto = proto->mutable_storage_policy()->add_column_families(); | ||
if (familyPolicy.Name_) { | ||
familyProto->set_name(familyPolicy.Name_.GetRef()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Непростительный фэйл так сказать, из-за спешки к сожалению допустил подобное. Исправлено.
if (QueryStats_.Defined()) { | ||
return NYdb::TProtoAccessor::GetProto(*QueryStats_.Get()).query_plan(); | ||
if (QueryStats_.has_value()) { | ||
return NYdb::TProtoAccessor::GetProto(*QueryStats_).query_plan(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -2,6 +2,8 @@ | |||
|
|||
#include "fluent_settings_helpers.h" | |||
|
|||
#include <string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Откуда пришёл?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не знаю как правильно здесь поступить, ошибки error: use of undeclared identifier 'std'
при компиляции в строка 18, 20 - 22. Решил включением string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Скорее всего тоже транзитивно
@@ -6,6 +6,7 @@ | |||
#include <library/cpp/colorizer/colors.h> | |||
#include <library/cpp/string_utils/misc/misc.h> | |||
|
|||
#include <util/generic/algorithm.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
С main ветки пришло?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет, я добавил из-за error: use of undeclared identifier 'IsIn'
в строках 111, 120, 129, 138. Опять же algorithm.h до этого был неявно включён через maybe.h, который я убрал.
EXPECT_EQ(GtestPrint(TMaybe<std::string>("hello world")), "\"hello world\""); | ||
EXPECT_EQ(GtestPrint(TMaybe<std::string>()), "nothing"); | ||
EXPECT_EQ(GtestPrint(Nothing()), "nothing"); | ||
EXPECT_EQ(GtestPrint(std::optional<std::string>("hello world")), "\"hello world\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А остался ли смысл в этом тесте, если optional часть STL? TMaybe был классом библиотеки, теперь нет
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрал.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Действительно, этот тест можно убрать
@GitSparTV Спасибо за ревью. Сделал все исправления, откомментировал. Постарался убрать по всему своему коду подобное написание |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поменяй на value_or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как говорится — LGTM :)
Всё исправлено и готово к просмотру заказчиком
@Gazizonoki Спасибо за ревью. Исправил замечания. |
Новая попытка PR после апдэйта: