Skip to content

Commit 851759e

Browse files
MBkktazevaykin
andauthored
Improve error messages for Knn module (#5282)
Co-authored-by: azevaykin <145343289+azevaykin@users.noreply.github.com>
1 parent 5b5e3d5 commit 851759e

File tree

2 files changed

+19
-4
lines changed
  • ydb/library/yql/udfs/common/knn

2 files changed

+19
-4
lines changed

ydb/library/yql/udfs/common/knn/knn.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "knn-distance.h"
44

55
#include <ydb/library/yql/public/udf/udf_helpers.h>
6+
#include <ydb/library/yql/public/udf/udf_type_printer.h>
67

78
#include <util/generic/buffer.h>
89
#include <util/generic/queue.h>
@@ -164,7 +165,11 @@ class TToBinaryStringBit: public TMultiSignatureBase<TToBinaryStringBit> {
164165
}
165166
}
166167
if (type == EType::None) {
167-
builder.SetError("'List<Double|Float|Uint8|Int8>' is expected");
168+
TStringBuilder sb;
169+
sb << "'List<Double|Float|Uint8|Int8>' is expected but got '";
170+
TTypePrinter(*typeInfoHelper, argsTuple.GetElementType(0)).Out(sb.Out);
171+
sb << "'";
172+
builder.SetError(std::move(sb));
168173
return true;
169174
}
170175

@@ -229,7 +234,11 @@ class TFloatFromBinaryString: public TMultiSignatureBase<TFloatFromBinaryString>
229234
auto argType = argsTuple.GetElementType(0);
230235
auto argTag = GetArg(*typeInfoHelper, argType, builder);
231236
if (!ValidTag(argTag, {TagStoredVector, TagFloatVector, TagInt8Vector, TagUint8Vector})) {
232-
builder.SetError("A result from 'ToBinaryString[Float|Int8|Uint8]' is expected as an argument");
237+
TStringBuilder sb;
238+
sb << "A result from 'ToBinaryString[Float|Int8|Uint8]' is expected as an argument but got '";
239+
TTypePrinter(*typeInfoHelper, argsTuple.GetElementType(0)).Out(sb.Out);
240+
sb << "'";
241+
builder.SetError(std::move(sb));
233242
return true;
234243
}
235244

@@ -279,7 +288,13 @@ class TDistanceBase: public TMultiSignatureBase<Derived> {
279288

280289
if (!Base::ValidTag(arg0Tag, {TagStoredVector, TagFloatVector, TagInt8Vector, TagUint8Vector, TagBitVector}) ||
281290
!Base::ValidTag(arg1Tag, {TagStoredVector, TagFloatVector, TagInt8Vector, TagUint8Vector, TagBitVector})) {
282-
builder.SetError("A result from 'ToBinaryString[Float|Int8|Uint8]' is expected as an argument");
291+
TStringBuilder sb;
292+
sb << "Both arguments are expected to be results from 'ToBinaryString[Float|Int8|Uint8]' but got '";
293+
TTypePrinter(*typeInfoHelper, argsTuple.GetElementType(0)).Out(sb.Out);
294+
sb << "' and '";
295+
TTypePrinter(*typeInfoHelper, argsTuple.GetElementType(1)).Out(sb.Out);
296+
sb << "'";
297+
builder.SetError(std::move(sb));
283298
return true;
284299
}
285300

ydb/library/yql/udfs/common/knn/test/canondata/test.test_ErrorFloatFromBinaryStringBitVector_/extracted

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<tmp_path>/program.sql:<main>:4:13: Error: At function: Apply, At function: Udf, At Knn.FloatFromBinaryString
77
select Knn::FloatFromBinaryString($bitvector);
88
^
9-
<tmp_path>/program.sql:<main>:4:13: Error: Failed to find UDF function: Knn.FloatFromBinaryString, reason: Error: Module: Knn, function: FloatFromBinaryString, error: A result from 'ToBinaryString[Float|Int8|Uint8]' is expected as an argument
9+
<tmp_path>/program.sql:<main>:4:13: Error: Failed to find UDF function: Knn.FloatFromBinaryString, reason: Error: Module: Knn, function: FloatFromBinaryString, error: A result from 'ToBinaryString[Float|Int8|Uint8]' is expected as an argument but got 'Tagged<String,'BitVector'>'
1010
select Knn::FloatFromBinaryString($bitvector);
1111
^

0 commit comments

Comments
 (0)