Skip to content

Commit b7a4f95

Browse files
authored
remove PG_TRY from TPgTypeDescriptor. Resolves #7287 (#7723)
1 parent c1875d3 commit b7a4f95

File tree

5 files changed

+93
-89
lines changed

5 files changed

+93
-89
lines changed

ydb/core/kqp/ut/pg/pg_catalog_ut.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,22 @@ Y_UNIT_TEST_SUITE(PgCatalog) {
497497
["pg_proc"]
498498
])", FormatResultSetYson(result.GetResultSet(0)));
499499
}
500+
{ //https://github.com/ydb-platform/ydb/issues/7287
501+
auto result = db.ExecuteQuery(R"(
502+
drop table table1;
503+
)", NYdb::NQuery::TTxControl::NoTx(), settings).ExtractValueSync();
504+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
505+
result = db.ExecuteQuery(R"(
506+
create table table1(id serial primary key);
507+
)", NYdb::NQuery::TTxControl::NoTx(), settings).ExtractValueSync();
508+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
509+
510+
result = db.ExecuteQuery(R"(
511+
select tablename from pg_tables where hasindexes='pg_proc';
512+
)", NYdb::NQuery::TTxControl::BeginTx().CommitTx(), settings).ExtractValueSync();
513+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::PRECONDITION_FAILED, result.GetIssues().ToString());
514+
UNIT_ASSERT(result.GetIssues().ToString().Contains("invalid input syntax for type boolean: \"pg_proc\""));
515+
}
500516
}
501517
}
502518

ydb/core/sys_view/pg_tables/pg_tables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace NSysView {
1919
using namespace NActors;
2020

2121
TStringBuf TPgTablesScanBase::GetColumnName(NTable::TTag tag) const {
22+
Y_ENSURE(tag > 0 && tag <= SchemaColumns_.size());
2223
return SchemaColumns_.at(tag - 1)._ColumnName;
2324
}
2425

ydb/library/yql/minikql/mkql_terminator.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ void TThrowingBindTerminator::Terminate(const char* message) const {
3232
ythrow yexception() << fullMessage;
3333
}
3434

35+
TOnlyThrowingBindTerminator::TOnlyThrowingBindTerminator()
36+
: TBindTerminator(this)
37+
{
38+
}
39+
40+
void TOnlyThrowingBindTerminator::Terminate(const char* message) const {
41+
ythrow yexception() << message;
42+
}
43+
44+
3545
[[noreturn]] void MKQLTerminate(const char* message) {
3646
if (const auto t = TBindTerminator::Terminator)
3747
t->Terminate(message);

ydb/library/yql/minikql/mkql_terminator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ struct TThrowingBindTerminator : public TBindTerminator, public ITerminator {
3131
void Terminate(const char* message) const final;
3232
};
3333

34+
struct TOnlyThrowingBindTerminator : public TBindTerminator, public ITerminator {
35+
TOnlyThrowingBindTerminator();
36+
void Terminate(const char* message) const final;
37+
};
38+
39+
40+
3441
[[noreturn]] void MKQLTerminate(const char* message);
3542

3643
}

ydb/library/yql/parser/pg_wrapper/comp_factory.cpp

Lines changed: 59 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ NUdf::TUnboxedValuePod ConvertToPgValue(NUdf::TUnboxedValuePod value, TMaybe<NUd
21162116
}
21172117
case NUdf::EDataSlot::TzDate:
21182118
case NUdf::EDataSlot::TzDatetime:
2119-
case NUdf::EDataSlot::TzTimestamp:
2119+
case NUdf::EDataSlot::TzTimestamp:
21202120
case NUdf::EDataSlot::TzDate32:
21212121
case NUdf::EDataSlot::TzDatetime64:
21222122
case NUdf::EDataSlot::TzTimestamp64: {
@@ -3755,7 +3755,7 @@ NUdf::TUnboxedValue PgValueFromNativeBinary(const TStringBuf binary, ui32 pgType
37553755
if (!NPg::HasType(pgTypeId)) {
37563756
return MakeString(binary);
37573757
}
3758-
3758+
37593759
TPAllocScope call;
37603760
StringInfoData stringInfo;
37613761
stringInfo.data = (char*)binary.Data();
@@ -5275,6 +5275,7 @@ class TPgTypeDescriptor
52755275
}
52765276

52775277
TConvertResult NativeBinaryFromNativeText(const TString& str) const {
5278+
NMiniKQL::TOnlyThrowingBindTerminator bind;
52785279
NMiniKQL::TScopedAlloc alloc(__LOCATION__);
52795280
NMiniKQL::TPAllocScope scope;
52805281
Datum datum = 0;
@@ -5287,51 +5288,45 @@ class TPgTypeDescriptor
52875288
pfree(serialized);
52885289
}
52895290
};
5290-
PG_TRY();
5291-
{
5292-
{
5291+
try {
5292+
{
5293+
FmgrInfo finfo;
5294+
InitFunc(InFuncId, &finfo, 1, 3);
5295+
LOCAL_FCINFO(callInfo, 3);
5296+
Zero(*callInfo);
5297+
callInfo->flinfo = &finfo;
5298+
callInfo->nargs = 3;
5299+
callInfo->fncollation = DEFAULT_COLLATION_OID;
5300+
callInfo->isnull = false;
5301+
callInfo->args[0] = { (Datum)str.Data(), false };
5302+
callInfo->args[1] = { ObjectIdGetDatum(NMiniKQL::MakeTypeIOParam(*this)), false };
5303+
callInfo->args[2] = { Int32GetDatum(-1), false };
5304+
5305+
datum = finfo.fn_addr(callInfo);
5306+
Y_ENSURE(!callInfo->isnull);
5307+
}
52935308
FmgrInfo finfo;
5294-
InitFunc(InFuncId, &finfo, 1, 3);
5295-
LOCAL_FCINFO(callInfo, 3);
5309+
InitFunc(SendFuncId, &finfo, 1, 1);
5310+
LOCAL_FCINFO(callInfo, 1);
52965311
Zero(*callInfo);
52975312
callInfo->flinfo = &finfo;
5298-
callInfo->nargs = 3;
5313+
callInfo->nargs = 1;
52995314
callInfo->fncollation = DEFAULT_COLLATION_OID;
53005315
callInfo->isnull = false;
5301-
callInfo->args[0] = { (Datum)str.Data(), false };
5302-
callInfo->args[1] = { ObjectIdGetDatum(NMiniKQL::MakeTypeIOParam(*this)), false };
5303-
callInfo->args[2] = { Int32GetDatum(-1), false };
5316+
callInfo->args[0] = { datum, false };
53045317

5305-
datum = finfo.fn_addr(callInfo);
5318+
serialized = (text*)finfo.fn_addr(callInfo);
53065319
Y_ENSURE(!callInfo->isnull);
5307-
}
5308-
FmgrInfo finfo;
5309-
InitFunc(SendFuncId, &finfo, 1, 1);
5310-
LOCAL_FCINFO(callInfo, 1);
5311-
Zero(*callInfo);
5312-
callInfo->flinfo = &finfo;
5313-
callInfo->nargs = 1;
5314-
callInfo->fncollation = DEFAULT_COLLATION_OID;
5315-
callInfo->isnull = false;
5316-
callInfo->args[0] = { datum, false };
5317-
5318-
serialized = (text*)finfo.fn_addr(callInfo);
5319-
Y_ENSURE(!callInfo->isnull);
5320-
return {TString(NMiniKQL::GetVarBuf(serialized)), {}};
5321-
}
5322-
PG_CATCH();
5323-
{
5324-
auto error_data = CopyErrorData();
5320+
return {TString(NMiniKQL::GetVarBuf(serialized)), {}};
5321+
} catch (const yexception& e) {
53255322
TStringBuilder errMsg;
5326-
errMsg << "Error while converting text to binary: " << error_data->message;
5327-
FreeErrorData(error_data);
5328-
FlushErrorState();
5323+
errMsg << "Error while converting text to binary: " << e.what();
53295324
return {"", errMsg};
53305325
}
5331-
PG_END_TRY();
53325326
}
53335327

53345328
TConvertResult NativeTextFromNativeBinary(const TStringBuf binary) const {
5329+
NMiniKQL::TOnlyThrowingBindTerminator bind;
53355330
NMiniKQL::TScopedAlloc alloc(__LOCATION__);
53365331
NMiniKQL::TPAllocScope scope;
53375332
Datum datum = 0;
@@ -5344,33 +5339,26 @@ class TPgTypeDescriptor
53445339
pfree(str);
53455340
}
53465341
};
5347-
PG_TRY();
5348-
{
5349-
datum = Receive(binary.Data(), binary.Size());
5350-
FmgrInfo finfo;
5351-
InitFunc(OutFuncId, &finfo, 1, 1);
5352-
LOCAL_FCINFO(callInfo, 1);
5353-
Zero(*callInfo);
5354-
callInfo->flinfo = &finfo;
5355-
callInfo->nargs = 1;
5356-
callInfo->fncollation = DEFAULT_COLLATION_OID;
5357-
callInfo->isnull = false;
5358-
callInfo->args[0] = { datum, false };
5342+
try {
5343+
datum = Receive(binary.Data(), binary.Size());
5344+
FmgrInfo finfo;
5345+
InitFunc(OutFuncId, &finfo, 1, 1);
5346+
LOCAL_FCINFO(callInfo, 1);
5347+
Zero(*callInfo);
5348+
callInfo->flinfo = &finfo;
5349+
callInfo->nargs = 1;
5350+
callInfo->fncollation = DEFAULT_COLLATION_OID;
5351+
callInfo->isnull = false;
5352+
callInfo->args[0] = { datum, false };
53595353

5360-
str = (char*)finfo.fn_addr(callInfo);
5361-
Y_ENSURE(!callInfo->isnull);
5362-
return {TString(str), {}};
5363-
}
5364-
PG_CATCH();
5365-
{
5366-
auto error_data = CopyErrorData();
5354+
str = (char*)finfo.fn_addr(callInfo);
5355+
Y_ENSURE(!callInfo->isnull);
5356+
return {TString(str), {}};
5357+
} catch (const yexception& e) {
53675358
TStringBuilder errMsg;
5368-
errMsg << "Error while converting binary to text: " << error_data->message;
5369-
FreeErrorData(error_data);
5370-
FlushErrorState();
5359+
errMsg << "Error while converting binary to text: " << e.what();
53715360
return {"", errMsg};
53725361
}
5373-
PG_END_TRY();
53745362
}
53755363

53765364
TTypeModResult ReadTypeMod(const TString& str) const {
@@ -5413,6 +5401,7 @@ class TPgTypeDescriptor
54135401
}
54145402
}
54155403

5404+
NMiniKQL::TOnlyThrowingBindTerminator bind;
54165405
NMiniKQL::TScopedAlloc alloc(__LOCATION__);
54175406
NMiniKQL::TPAllocScope scope;
54185407
ArrayType* paramsArray = nullptr;
@@ -5421,8 +5410,7 @@ class TPgTypeDescriptor
54215410
pfree(paramsArray);
54225411
}
54235412
};
5424-
PG_TRY();
5425-
{
5413+
try {
54265414
int ndims = 0;
54275415
int dims[MAXDIM];
54285416
int lbs[MAXDIM];
@@ -5451,22 +5439,17 @@ class TPgTypeDescriptor
54515439
auto result = finfo.fn_addr(callInfo);
54525440
Y_ENSURE(!callInfo->isnull);
54535441
return {DatumGetInt32(result), {}};
5454-
}
5455-
PG_CATCH();
5456-
{
5457-
auto error_data = CopyErrorData();
5442+
} catch (const yexception& e) {
54585443
TStringBuilder errMsg;
54595444
errMsg << "Error in 'typemodin' function: "
54605445
<< NYql::NPg::LookupProc(TypeModInFuncId).Name
5461-
<< ", reason: " << error_data->message;
5462-
FreeErrorData(error_data);
5463-
FlushErrorState();
5446+
<< ", reason: " << e.what();
54645447
return {-1, errMsg};
54655448
}
5466-
PG_END_TRY();
54675449
}
54685450

54695451
TMaybe<TString> Validate(const TStringBuf binary) {
5452+
NMiniKQL::TOnlyThrowingBindTerminator bind;
54705453
NMiniKQL::TScopedAlloc alloc(__LOCATION__);
54715454
NMiniKQL::TPAllocScope scope;
54725455
Datum datum = 0;
@@ -5475,23 +5458,16 @@ class TPgTypeDescriptor
54755458
pfree((void*)datum);
54765459
}
54775460
};
5478-
PG_TRY();
5479-
{
5480-
datum = Receive(binary.Data(), binary.Size());
5481-
return {};
5482-
}
5483-
PG_CATCH();
5484-
{
5485-
auto error_data = CopyErrorData();
5461+
try {
5462+
datum = Receive(binary.Data(), binary.Size());
5463+
return {};
5464+
} catch (const yexception& e) {
54865465
TStringBuilder errMsg;
54875466
errMsg << "Error in 'recv' function: "
54885467
<< NYql::NPg::LookupProc(ReceiveFuncId).Name
5489-
<< ", reason: " << error_data->message;
5490-
FreeErrorData(error_data);
5491-
FlushErrorState();
5468+
<< ", reason: " << e.what();
54925469
return errMsg;
54935470
}
5494-
PG_END_TRY();
54955471
}
54965472

54975473
TCoerceResult Coerce(const TStringBuf binary, i32 typmod) {
@@ -5508,6 +5484,7 @@ class TPgTypeDescriptor
55085484

55095485
private:
55105486
TCoerceResult Coerce(bool isSourceBinary, const TStringBuf binary, Datum datum, i32 typmod) {
5487+
NMiniKQL::TOnlyThrowingBindTerminator bind;
55115488
NMiniKQL::TScopedAlloc alloc(__LOCATION__);
55125489
NMiniKQL::TPAllocScope scope;
55135490

@@ -5535,8 +5512,7 @@ class TPgTypeDescriptor
55355512
pfree(serialized);
55365513
}
55375514
};
5538-
PG_TRY();
5539-
{
5515+
try {
55405516
if (isSourceBinary) {
55415517
datum = Receive(binary.Data(), binary.Size());
55425518
}
@@ -5602,17 +5578,11 @@ class TPgTypeDescriptor
56025578
Y_ENSURE(!callInfo->isnull);
56035579
return {TString(NMiniKQL::GetVarBuf(serialized)), {}};
56045580
}
5605-
}
5606-
PG_CATCH();
5607-
{
5608-
auto error_data = CopyErrorData();
5581+
} catch (const yexception& e) {
56095582
TStringBuilder errMsg;
5610-
errMsg << "Error while coercing value, reason: " << error_data->message;
5611-
FreeErrorData(error_data);
5612-
FlushErrorState();
5583+
errMsg << "Error while coercing value, reason: " << e.what();
56135584
return {{}, errMsg};
56145585
}
5615-
PG_END_TRY();
56165586
}
56175587

56185588
Datum CoerceOne(ui32 typeId, Datum datum, i32 typmod) const {

0 commit comments

Comments
 (0)