diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-11-21 18:15:58 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-11-21 18:52:11 +0300 |
commit | bb335634021286c083baadac9715a40e8ecd0595 (patch) | |
tree | 2842811b4fe1a1c19bd20faf6e791e09f7bb3158 | |
parent | c8482a7c9c43883e325c2ab31b58cb62abde7eba (diff) | |
download | ydb-bb335634021286c083baadac9715a40e8ecd0595.tar.gz |
Intermediate changes
commit_hash:50996f174ea1b659bc41e9f4e9f27328060af2ca
-rw-r--r-- | yql/essentials/udfs/common/python/bindings/py_cast.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/yql/essentials/udfs/common/python/bindings/py_cast.cpp b/yql/essentials/udfs/common/python/bindings/py_cast.cpp index 3aa5537b21..078239962e 100644 --- a/yql/essentials/udfs/common/python/bindings/py_cast.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_cast.cpp @@ -814,6 +814,27 @@ NUdf::TUnboxedValue FromPyDict( throw yexception() << "Can't cast "<< PyObjectRepr(value) << " to dict."; } +TPyObjectPtr ToPyNull( + const TPyCastContext::TPtr& ctx, + const NUdf::TType* type, + const NUdf::TUnboxedValuePod& value) +{ + if (!value.HasValue()) { + return TPyObjectPtr(Py_None, TPyObjectPtr::ADD_REF); + } + throw yexception() << "Value is not null"; +} + +NUdf::TUnboxedValue FromPyNull( + const TPyCastContext::TPtr& ctx, + const NUdf::TType* type, PyObject* value) +{ + if (value == Py_None) { + return NYql::NUdf::TUnboxedValuePod(); + } + throw yexception() << "Can't cast " << PyObjectRepr(value) << " to null."; +} + } // namespace TPyObjectPtr ToPyObject( @@ -832,6 +853,7 @@ TPyObjectPtr ToPyObject( case NUdf::ETypeKind::Void: return ToPyVoid(ctx, type, value); case NUdf::ETypeKind::Stream: return ToPyStream(ctx, type, value); case NUdf::ETypeKind::Variant: return ToPyVariant(ctx, type, value); + case NUdf::ETypeKind::Null: return ToPyNull(ctx, type, value); default: { ::TStringBuilder sb; sb << "Failed to export: "; @@ -857,6 +879,7 @@ NUdf::TUnboxedValue FromPyObject( case NUdf::ETypeKind::Void: return FromPyVoid(ctx, type, value); case NUdf::ETypeKind::Stream: return FromPyStream(ctx, type, TPyObjectPtr(value, TPyObjectPtr::ADD_REF), nullptr, nullptr, nullptr); case NUdf::ETypeKind::Variant: return FromPyVariant(ctx, type, value); + case NUdf::ETypeKind::Null: return FromPyNull(ctx, type, value); default: { ::TStringBuilder sb; sb << "Failed to import: "; |