Skip to content

Commit 744a463

Browse files
authored
Some fixes in erase_rows_condition.cpp (#10361)
1 parent 40f8edb commit 744a463

File tree

1 file changed

+57
-49
lines changed

1 file changed

+57
-49
lines changed

ydb/core/tx/datashard/erase_rows_condition.cpp

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ class TExpirationCondition: public IEraseRowsCondition {
3333
}
3434
}
3535

36+
TMaybe<TString> GetWallClockDyNumber() const {
37+
const auto instantValue = InstantValue(WallClockInstant, Unit);
38+
if (!instantValue) {
39+
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
40+
"Unsupported unit: " << static_cast<ui32>(Unit));
41+
CannotSerialize = true;
42+
return Nothing();
43+
}
44+
45+
const auto strInstant = ToString(*instantValue);
46+
WallClockSerialized = NDyNumber::ParseDyNumberString(strInstant);
47+
if (!WallClockSerialized) {
48+
CannotSerialize = true;
49+
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
50+
"Cannot parse DyNumber from: " << strInstant.Quote());
51+
}
52+
53+
return WallClockSerialized;
54+
}
55+
3656
void ParsePgFromText(const TString& value) const {
3757
const auto& result = NPg::PgNativeBinaryFromNativeText(value, Type.GetPgTypeDesc());
3858
if (result.Error) {
@@ -44,6 +64,34 @@ class TExpirationCondition: public IEraseRowsCondition {
4464
}
4565
}
4666

67+
TMaybe<TString> GetWallClockPg() const {
68+
switch (NPg::PgTypeIdFromTypeDesc(Type.GetPgTypeDesc())) {
69+
case DATEOID:
70+
case TIMESTAMPOID: {
71+
const auto& wallClockIsoString = WallClockInstant.ToString();
72+
ParsePgFromText(wallClockIsoString);
73+
break;
74+
}
75+
case INT4OID:
76+
case INT8OID: {
77+
const auto instantValue = InstantValue(WallClockInstant, Unit);
78+
if (!instantValue) {
79+
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
80+
"Unsupported unit: " << static_cast<ui32>(Unit));
81+
CannotSerialize = true;
82+
return Nothing();
83+
}
84+
const auto strInstant = ToString(*instantValue);
85+
ParsePgFromText(strInstant);
86+
break;
87+
}
88+
default:
89+
CannotSerialize = true;
90+
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD, "Unsupported PG type");
91+
}
92+
return WallClockSerialized;
93+
}
94+
4795
TMaybe<TString> GetWallClockSerialized() const {
4896
if (WallClockSerialized) {
4997
return WallClockSerialized;
@@ -54,53 +102,13 @@ class TExpirationCondition: public IEraseRowsCondition {
54102
}
55103

56104
switch (Type.GetTypeId()) {
57-
case NScheme::NTypeIds::DyNumber: {
58-
const auto instantValue = InstantValue(WallClockInstant, Unit);
59-
if (!instantValue) {
60-
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
61-
"Unsupported unit: " << static_cast<ui32>(Unit));
62-
return Nothing();
63-
}
64-
65-
const auto strInstant = ToString(*instantValue);
66-
const auto wallClockDyNumber = NDyNumber::ParseDyNumberString(strInstant);
67-
if (!wallClockDyNumber) {
68-
CannotSerialize = true;
69-
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
70-
"Cannot parse DyNumber from: " << strInstant.Quote());
71-
} else {
72-
WallClockSerialized = *wallClockDyNumber;
73-
}
74-
break;
75-
}
76-
case NScheme::NTypeIds::Pg: {
77-
switch (NPg::PgTypeIdFromTypeDesc(Type.GetPgTypeDesc())) {
78-
case DATEOID:
79-
case TIMESTAMPOID: {
80-
const auto& wallClockIsoString = WallClockInstant.ToString();
81-
ParsePgFromText(wallClockIsoString);
82-
break;
83-
}
84-
case INT4OID:
85-
case INT8OID: {
86-
const auto instantValue = InstantValue(WallClockInstant, Unit);
87-
if (!instantValue) {
88-
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
89-
"Unsupported unit: " << static_cast<ui32>(Unit));
90-
return Nothing();
91-
}
92-
const auto strInstant = ToString(*instantValue);
93-
ParsePgFromText(strInstant);
94-
break;
95-
}
96-
default:
97-
CannotSerialize = true;
98-
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD, "Unsupported PG type");
99-
}
100-
break;
101-
}
105+
case NScheme::NTypeIds::DyNumber:
106+
return GetWallClockDyNumber();
107+
case NScheme::NTypeIds::Pg:
108+
return GetWallClockPg();
109+
default:
110+
Y_ABORT("Unreachable");
102111
}
103-
return WallClockSerialized;
104112
}
105113

106114
bool CheckUi64(ui64 value) const {
@@ -154,15 +162,15 @@ class TExpirationCondition: public IEraseRowsCondition {
154162
}
155163

156164
bool CheckSerialized(TStringBuf value) const {
157-
if (const auto& wallClockDSerialized = GetWallClockSerialized()) {
165+
if (const auto& wallClockSerialized = GetWallClockSerialized()) {
158166
switch (Type.GetTypeId()) {
159167
// 'value since epoch' mode
160168
case NScheme::NTypeIds::DyNumber:
161-
return value <= *wallClockDSerialized;
169+
return value <= *wallClockSerialized;
162170
case NScheme::NTypeIds::Pg: {
163171
int result = NPg::PgNativeBinaryCompare(
164172
value.Data(), value.Size(),
165-
wallClockDSerialized->Data(), wallClockDSerialized->Size(),
173+
wallClockSerialized->Data(), wallClockSerialized->Size(),
166174
Type.GetPgTypeDesc());
167175
return result <= 0;
168176
}

0 commit comments

Comments
 (0)