Skip to content

Commit 3ab4d61

Browse files
The --supported-codecs option for the topic create and topic consumer add commands (#9419)
1 parent e64385b commit 3ab4d61

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

ydb/apps/ydb/ut/supported_codecs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Y_UNIT_TEST_SUITE(YdbTopic) {
55

66
Y_UNIT_TEST_F(SupportedCodecs_TopicCreate_DefaultValue, TSupportedCodecsFixture)
77
{
8-
TestTopicCreate(GetTopicName(), {}, {"RAW"});
8+
TestTopicCreate(GetTopicName(), {}, {});
99
}
1010

1111
Y_UNIT_TEST_F(SupportedCodecs_TopicCreate_UserValue, TSupportedCodecsFixture)
@@ -19,7 +19,7 @@ Y_UNIT_TEST_F(SupportedCodecs_TopicAlter, TSupportedCodecsFixture)
1919

2020
YdbTopicCreate(topicName);
2121

22-
TestTopicAlter(topicName, {}, {"RAW"});
22+
TestTopicAlter(topicName, {}, {});
2323
TestTopicAlter(topicName, {"GZIP", "ZSTD"}, {"GZIP", "ZSTD"});
2424
TestTopicAlter(topicName, {}, {"GZIP", "ZSTD"});
2525
}
@@ -31,7 +31,7 @@ Y_UNIT_TEST_F(SupportedCodecs_TopicConsumerAdd_DefaultValue, TSupportedCodecsFix
3131

3232
YdbTopicCreate(topicName);
3333

34-
TestTopicConsumerAdd(topicName, consumerName, {}, {"RAW"});
34+
TestTopicConsumerAdd(topicName, consumerName, {}, {});
3535
}
3636

3737
Y_UNIT_TEST_F(SupportedCodecs_TopicConsumerAdd_UserValue, TSupportedCodecsFixture)

ydb/apps/ydb/ut/supported_codecs_fixture.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ auto TSupportedCodecsFixture::GetTopicConsumerSupportedCodecs(const TString& des
209209
TVector<TString> codecs;
210210
Split(fields[1], ",", codecs);
211211
for (auto& codec : codecs) {
212-
result.insert(Strip(codec));
212+
if (auto c = Strip(codec); !c.empty()) {
213+
result.insert(c);
214+
}
213215
}
214216

215217
return result;

ydb/public/lib/ydb_cli/commands/ydb_service_topic.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,9 @@ namespace {
337337
settings.PartitionWriteSpeedBytesPerSecond(PartitionWriteSpeedKbps_ * 1_KB);
338338

339339
auto codecs = GetCodecs();
340-
if (codecs.empty()) {
341-
codecs.push_back(NTopic::ECodec::RAW);
340+
if (!codecs.empty()) {
341+
settings.SetSupportedCodecs(codecs);
342342
}
343-
settings.SetSupportedCodecs(codecs);
344343

345344
if (GetMeteringMode() != NTopic::EMeteringMode::Unspecified) {
346345
settings.MeteringMode(GetMeteringMode());
@@ -546,11 +545,10 @@ namespace {
546545
consumerSettings.ReadFrom(TInstant::Seconds(*StartingMessageTimestamp_));
547546
}
548547

549-
TVector<NTopic::ECodec> codecs = GetCodecs();
550-
if (codecs.empty()) {
551-
codecs.push_back(NTopic::ECodec::RAW);
548+
auto codecs = GetCodecs();
549+
if (!codecs.empty()) {
550+
consumerSettings.SetSupportedCodecs(codecs);
552551
}
553-
consumerSettings.SetSupportedCodecs(codecs);
554552
consumerSettings.SetImportant(IsImportant_);
555553

556554
readRuleSettings.AppendAddConsumers(consumerSettings);
@@ -897,7 +895,6 @@ namespace {
897895
TString description = PrepareAllowedCodecsDescription("Client-side compression algorithm. When read, data will be uncompressed transparently with a codec used on write", allowedCodecs);
898896
config.Opts->AddLongOption("codec", description)
899897
.Optional()
900-
.DefaultValue((TStringBuilder() << NTopic::ECodec::RAW))
901898
.StoreResult(&CodecStr_);
902899
AllowedCodecs_ = allowedCodecs;
903900
}
@@ -910,7 +907,7 @@ namespace {
910907
Codec_ = ::NYdb::NConsoleClient::ParseCodec(CodecStr_, AllowedCodecs_);
911908
}
912909

913-
NTopic::ECodec TCommandWithCodec::GetCodec() const {
910+
TMaybe<NTopic::ECodec> TCommandWithCodec::GetCodec() const {
914911
return Codec_;
915912
}
916913

@@ -960,7 +957,9 @@ namespace {
960957

961958
NTopic::TWriteSessionSettings TCommandTopicWrite::PrepareWriteSessionSettings() {
962959
NTopic::TWriteSessionSettings settings;
963-
settings.Codec(GetCodec());
960+
if (auto codec = GetCodec(); codec.Defined()) {
961+
settings.Codec(*codec);
962+
}
964963
settings.Path(TopicName);
965964

966965
if (!MessageGroupId_.Defined()) {

ydb/public/lib/ydb_cli/commands/ydb_service_topic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ namespace NYdb::NConsoleClient {
225225
protected:
226226
void AddAllowedCodecs(TClientCommand::TConfig& config, const TVector<NTopic::ECodec>& allowedCodecs);
227227
void ParseCodec();
228-
NTopic::ECodec GetCodec() const;
228+
TMaybe<NTopic::ECodec> GetCodec() const;
229229

230230
private:
231231
TVector<NTopic::ECodec> AllowedCodecs_;
232232
TString CodecStr_;
233-
NTopic::ECodec Codec_ = NTopic::ECodec::RAW;
233+
TMaybe<NTopic::ECodec> Codec_;
234234
};
235235

236236
class TCommandTopicWrite: public TYdbCommand,

0 commit comments

Comments
 (0)