aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkniv <kniv@yandex-team.ru>2022-03-14 14:51:13 +0300
committerkniv <kniv@yandex-team.ru>2022-03-14 14:51:13 +0300
commit03eec4e7e455d44d111cdffcaa3ee791074e2f86 (patch)
tree18f4f486d2497b9b1e5161038b0f5df2bc618048
parente55fb55efda71cea0cd9c5fdafa41af406aef5bf (diff)
downloadydb-03eec4e7e455d44d111cdffcaa3ee791074e2f86.tar.gz
YQL-7418: Add ToUint64() UDF
YQL-7418: Add ToUint64() UDF ref:9b4ad719c1595ed2553128cad1aec17027ea2847
-rw-r--r--ydb/library/yql/udfs/common/unicode_base/lib/unicode_base_udf.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/ydb/library/yql/udfs/common/unicode_base/lib/unicode_base_udf.h b/ydb/library/yql/udfs/common/unicode_base/lib/unicode_base_udf.h
index 1f8b0d3a95..85867d84ec 100644
--- a/ydb/library/yql/udfs/common/unicode_base/lib/unicode_base_udf.h
+++ b/ydb/library/yql/udfs/common/unicode_base/lib/unicode_base_udf.h
@@ -53,6 +53,23 @@ namespace {
return TUnboxedValuePod(static_cast<ui64>(result));
}
+ SIMPLE_UDF(TToUint64, ui64(TAutoMap<TUtf8>, ui16)) {
+ Y_UNUSED(valueBuilder);
+ const TString inputStr(args[0].AsStringRef());
+ const char* input = inputStr.Data();
+ const int base = static_cast<int>(args[1].Get<ui16>());
+ char *pos = nullptr;
+ unsigned long long res = std::strtoull(input, &pos, base);
+ if (!res && pos == input) {
+ UdfTerminate("Input string is not a number");
+ } else if (res == ULLONG_MAX && errno == ERANGE) {
+ UdfTerminate("Converted value falls out of Uint64 range");
+ } else if (*pos) {
+ UdfTerminate("Input string contains junk after the number");
+ }
+ return TUnboxedValuePod(static_cast<ui64>(res));
+ }
+
SIMPLE_UDF_OPTIONS(TSubstring, TUtf8(TAutoMap<TUtf8>, TOptional<ui64>, TOptional<ui64>),
builder.OptionalArgs(1)) {
const TStringBuf input(args[0].AsStringRef());
@@ -434,5 +451,6 @@ namespace {
TReverse, \
TToLower, \
TToUpper, \
- TToTitle
+ TToTitle, \
+ TToUint64
}