Skip to content

YQL-17678 throw exception instead of abort #1348

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

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ydb/library/yql/minikql/mkql_terminator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "defs.h"
#include "mkql_terminator.h"

#include <util/string/builder.h>

namespace NKikimr {

namespace NMiniKQL {
Expand All @@ -18,6 +20,18 @@ TBindTerminator::~TBindTerminator()
Terminator = PreviousTerminator;
}

TThrowingBindTerminator::TThrowingBindTerminator()
: TBindTerminator(this)
{
}

void TThrowingBindTerminator::Terminate(const char* message) const {
TStringBuf reason = (message ? TStringBuf(message) : TStringBuf("(unknown)"));
TString fullMessage = TStringBuilder() <<
"Terminate was called, reason(" << reason.size() << "): " << reason << Endl;
ythrow yexception() << fullMessage;
}

[[noreturn]] void MKQLTerminate(const char* message) {
if (const auto t = TBindTerminator::Terminator)
t->Terminate(message);
Expand Down
5 changes: 5 additions & 0 deletions ydb/library/yql/minikql/mkql_terminator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ struct TBindTerminator : private TNonCopyable {
ITerminator* PreviousTerminator;
};

struct TThrowingBindTerminator : public TBindTerminator, public ITerminator {
TThrowingBindTerminator();
void Terminate(const char* message) const final;
};

[[noreturn]] void MKQLTerminate(const char* message);

}
Expand Down
4 changes: 4 additions & 0 deletions ydb/library/yql/providers/dq/actors/proto_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool TProtoBuilder::CanBuildResultSet() const {
}

TString TProtoBuilder::BuildYson(TVector<NYql::NDq::TDqSerializedBatch>&& rows, ui64 maxBytesLimit) {
TThrowingBindTerminator t;
ui64 size = 0;
TStringStream out;
NYson::TYsonWriter writer((IOutputStream*)&out);
Expand All @@ -82,13 +83,15 @@ TString TProtoBuilder::BuildYson(TVector<NYql::NDq::TDqSerializedBatch>&& rows,
}

bool TProtoBuilder::WriteYsonData(NYql::NDq::TDqSerializedBatch&& data, const std::function<bool(const TString& rawYson)>& func) {
TThrowingBindTerminator t;
return WriteData(std::move(data), [&](const NYql::NUdf::TUnboxedValuePod& value) {
auto rowYson = NCommon::WriteYsonValue(value, ResultType, ColumnOrder.empty() ? nullptr : &ColumnOrder);
return func(rowYson);
});
}

bool TProtoBuilder::WriteData(NYql::NDq::TDqSerializedBatch&& data, const std::function<bool(const NYql::NUdf::TUnboxedValuePod& value)>& func) {
TThrowingBindTerminator t;
TGuard<TScopedAlloc> allocGuard(Alloc);

TMemoryUsageInfo memInfo("ProtoBuilder");
Expand All @@ -106,6 +109,7 @@ bool TProtoBuilder::WriteData(NYql::NDq::TDqSerializedBatch&& data, const std::f
}

bool TProtoBuilder::WriteData(TVector<NYql::NDq::TDqSerializedBatch>&& rows, const std::function<bool(const NYql::NUdf::TUnboxedValuePod& value)>& func) {
TThrowingBindTerminator t;
TGuard<TScopedAlloc> allocGuard(Alloc);

TMemoryUsageInfo memInfo("ProtoBuilder");
Expand Down