Skip to content

Commit e79df44

Browse files
sabdenovchblinkov
authored andcommitted
Introduce YT_OPTIONAL_TO_PROTO and YT_OPTIONAL_SET_PROTO
commit_hash:3aea20eea3362520dc0fbf62187141e581dafc06
1 parent 8cbacda commit e79df44

File tree

10 files changed

+194
-608
lines changed

10 files changed

+194
-608
lines changed

yt/yt/client/api/rpc_proxy/client_base.cpp

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ TFuture<ITransactionPtr> TClientBase::StartTransaction(
137137

138138
req->set_type(static_cast<NProto::ETransactionType>(type));
139139
req->set_timeout(ToProto(timeout));
140-
if (options.Deadline) {
141-
req->set_deadline(ToProto(*options.Deadline));
142-
}
140+
YT_OPTIONAL_SET_PROTO(req, deadline, options.Deadline);
143141
if (options.Id) {
144142
ToProto(req->mutable_id(), options.Id);
145143
}
@@ -251,9 +249,7 @@ TFuture<TYsonString> TClientBase::GetNode(
251249
req->mutable_legacy_attributes()->set_all(true);
252250
}
253251

254-
if (options.MaxSize) {
255-
req->set_max_size(*options.MaxSize);
256-
}
252+
YT_OPTIONAL_SET_PROTO(req, max_size, options.MaxSize);
257253

258254
ToProto(req->mutable_complexity_limits(), options.ComplexityLimits);
259255

@@ -289,9 +285,7 @@ TFuture<TYsonString> TClientBase::ListNode(
289285
req->mutable_legacy_attributes()->set_all(true);
290286
}
291287

292-
if (options.MaxSize) {
293-
req->set_max_size(*options.MaxSize);
294-
}
288+
YT_OPTIONAL_SET_PROTO(req, max_size, options.MaxSize);
295289

296290
ToProto(req->mutable_complexity_limits(), options.ComplexityLimits);
297291

@@ -423,12 +417,8 @@ TFuture<TLockNodeResult> TClientBase::LockNode(
423417
req->set_mode(ToProto(mode));
424418

425419
req->set_waitable(options.Waitable);
426-
if (options.ChildKey) {
427-
req->set_child_key(*options.ChildKey);
428-
}
429-
if (options.AttributeKey) {
430-
req->set_attribute_key(*options.AttributeKey);
431-
}
420+
YT_OPTIONAL_TO_PROTO(req, child_key, options.ChildKey);
421+
YT_OPTIONAL_TO_PROTO(req, attribute_key, options.AttributeKey);
432422

433423
ToProto(req->mutable_transactional_options(), options);
434424
ToProto(req->mutable_prerequisite_options(), options);
@@ -642,12 +632,8 @@ TFuture<IFileReaderPtr> TClientBase::CreateFileReader(
642632
InitStreamingRequest(*req);
643633

644634
req->set_path(path);
645-
if (options.Offset) {
646-
req->set_offset(*options.Offset);
647-
}
648-
if (options.Length) {
649-
req->set_length(*options.Length);
650-
}
635+
YT_OPTIONAL_SET_PROTO(req, offset, options.Offset);
636+
YT_OPTIONAL_SET_PROTO(req, length, options.Length);
651637
if (options.Config) {
652638
req->set_config(ConvertToYsonString(*options.Config).ToString());
653639
}
@@ -691,12 +677,8 @@ IJournalReaderPtr TClientBase::CreateJournalReader(
691677

692678
req->set_path(path);
693679

694-
if (options.FirstRowIndex) {
695-
req->set_first_row_index(*options.FirstRowIndex);
696-
}
697-
if (options.RowCount) {
698-
req->set_row_count(*options.RowCount);
699-
}
680+
YT_OPTIONAL_SET_PROTO(req, first_row_index, options.FirstRowIndex);
681+
YT_OPTIONAL_SET_PROTO(req, row_count, options.RowCount);
700682
if (options.Config) {
701683
req->set_config(ConvertToYsonString(*options.Config).ToString());
702684
}
@@ -868,9 +850,7 @@ TFuture<TUnversionedLookupRowsResult> TClientBase::LookupRows(
868850
req->set_keep_missing_rows(options.KeepMissingRows);
869851
req->set_enable_partial_result(options.EnablePartialResult);
870852
req->set_replica_consistency(static_cast<NProto::EReplicaConsistency>(options.ReplicaConsistency));
871-
if (options.UseLookupCache) {
872-
req->set_use_lookup_cache(*options.UseLookupCache);
873-
}
853+
YT_OPTIONAL_SET_PROTO(req, use_lookup_cache, options.UseLookupCache);
874854

875855
req->SetMultiplexingBand(options.MultiplexingBand);
876856
req->set_multiplexing_band(static_cast<NProto::EMultiplexingBand>(options.MultiplexingBand));
@@ -920,9 +900,7 @@ TFuture<TVersionedLookupRowsResult> TClientBase::VersionedLookupRows(
920900
req->set_keep_missing_rows(options.KeepMissingRows);
921901
req->set_enable_partial_result(options.EnablePartialResult);
922902
req->set_replica_consistency(static_cast<NProto::EReplicaConsistency>(options.ReplicaConsistency));
923-
if (options.UseLookupCache) {
924-
req->set_use_lookup_cache(*options.UseLookupCache);
925-
}
903+
YT_OPTIONAL_SET_PROTO(req, use_lookup_cache, options.UseLookupCache);
926904

927905
req->SetMultiplexingBand(options.MultiplexingBand);
928906
req->set_multiplexing_band(static_cast<NProto::EMultiplexingBand>(options.MultiplexingBand));
@@ -969,9 +947,7 @@ TFuture<std::vector<TUnversionedLookupRowsResult>> TClientBase::MultiLookupRows(
969947
}
970948
protoSubrequest->set_keep_missing_rows(subrequestOptions.KeepMissingRows);
971949
protoSubrequest->set_enable_partial_result(subrequestOptions.EnablePartialResult);
972-
if (subrequestOptions.UseLookupCache) {
973-
protoSubrequest->set_use_lookup_cache(*subrequestOptions.UseLookupCache);
974-
}
950+
YT_OPTIONAL_SET_PROTO(protoSubrequest, use_lookup_cache, subrequestOptions.UseLookupCache);
975951

976952
auto rowset = SerializeRowset(
977953
subrequest.NameTable,
@@ -1079,40 +1055,30 @@ TFuture<TSelectRowsResult> TClientBase::SelectRows(
10791055
// TODO(lukyan): Move to FillRequestBySelectRowsOptionsBase
10801056
req->SetTimeout(options.Timeout.value_or(config->DefaultSelectRowsTimeout));
10811057

1082-
if (options.InputRowLimit) {
1083-
req->set_input_row_limit(*options.InputRowLimit);
1084-
}
1085-
if (options.OutputRowLimit) {
1086-
req->set_output_row_limit(*options.OutputRowLimit);
1087-
}
1058+
YT_OPTIONAL_SET_PROTO(req, input_row_limit, options.InputRowLimit);
1059+
YT_OPTIONAL_SET_PROTO(req, output_row_limit, options.OutputRowLimit);
10881060
req->set_range_expansion_limit(options.RangeExpansionLimit);
10891061
req->set_max_subqueries(options.MaxSubqueries);
10901062
req->set_min_row_count_per_subquery(options.MinRowCountPerSubquery);
10911063
req->set_allow_full_scan(options.AllowFullScan);
10921064
req->set_allow_join_without_index(options.AllowJoinWithoutIndex);
10931065

1094-
if (options.ExecutionPool) {
1095-
req->set_execution_pool(*options.ExecutionPool);
1096-
}
1066+
YT_OPTIONAL_TO_PROTO(req, execution_pool, options.ExecutionPool);
10971067
if (options.PlaceholderValues) {
10981068
req->set_placeholder_values(options.PlaceholderValues.ToString());
10991069
}
11001070
req->set_fail_on_incomplete_result(options.FailOnIncompleteResult);
11011071
req->set_verbose_logging(options.VerboseLogging);
11021072
req->set_new_range_inference(options.NewRangeInference);
1103-
if (options.ExecutionBackend) {
1104-
req->set_execution_backend(ToProto(*options.ExecutionBackend));
1105-
}
1073+
YT_OPTIONAL_SET_PROTO(req, execution_backend, options.ExecutionBackend);
11061074
req->set_enable_code_cache(options.EnableCodeCache);
11071075
req->set_memory_limit_per_node(options.MemoryLimitPerNode);
11081076
ToProto(req->mutable_suppressable_access_tracking_options(), options);
11091077
req->set_replica_consistency(static_cast<NProto::EReplicaConsistency>(options.ReplicaConsistency));
11101078
req->set_use_canonical_null_relations(options.UseCanonicalNullRelations);
11111079
req->set_merge_versioned_rows(options.MergeVersionedRows);
11121080
ToProto(req->mutable_versioned_read_options(), options.VersionedReadOptions);
1113-
if (options.UseLookupCache) {
1114-
req->set_use_lookup_cache(*options.UseLookupCache);
1115-
}
1081+
YT_OPTIONAL_SET_PROTO(req, use_lookup_cache, options.UseLookupCache);
11161082

11171083
return req->Invoke().Apply(BIND([] (const TApiServiceProxy::TRspSelectRowsPtr& rsp) {
11181084
TSelectRowsResult result;

0 commit comments

Comments
 (0)