Skip to content

Commit bb33563

Browse files
committed
Intermediate changes
commit_hash:50996f174ea1b659bc41e9f4e9f27328060af2ca
1 parent c8482a7 commit bb33563

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

yql/essentials/udfs/common/python/bindings/py_cast.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,27 @@ NUdf::TUnboxedValue FromPyDict(
814814
throw yexception() << "Can't cast "<< PyObjectRepr(value) << " to dict.";
815815
}
816816

817+
TPyObjectPtr ToPyNull(
818+
const TPyCastContext::TPtr& ctx,
819+
const NUdf::TType* type,
820+
const NUdf::TUnboxedValuePod& value)
821+
{
822+
if (!value.HasValue()) {
823+
return TPyObjectPtr(Py_None, TPyObjectPtr::ADD_REF);
824+
}
825+
throw yexception() << "Value is not null";
826+
}
827+
828+
NUdf::TUnboxedValue FromPyNull(
829+
const TPyCastContext::TPtr& ctx,
830+
const NUdf::TType* type, PyObject* value)
831+
{
832+
if (value == Py_None) {
833+
return NYql::NUdf::TUnboxedValuePod();
834+
}
835+
throw yexception() << "Can't cast " << PyObjectRepr(value) << " to null.";
836+
}
837+
817838
} // namespace
818839

819840
TPyObjectPtr ToPyObject(
@@ -832,6 +853,7 @@ TPyObjectPtr ToPyObject(
832853
case NUdf::ETypeKind::Void: return ToPyVoid(ctx, type, value);
833854
case NUdf::ETypeKind::Stream: return ToPyStream(ctx, type, value);
834855
case NUdf::ETypeKind::Variant: return ToPyVariant(ctx, type, value);
856+
case NUdf::ETypeKind::Null: return ToPyNull(ctx, type, value);
835857
default: {
836858
::TStringBuilder sb;
837859
sb << "Failed to export: ";
@@ -857,6 +879,7 @@ NUdf::TUnboxedValue FromPyObject(
857879
case NUdf::ETypeKind::Void: return FromPyVoid(ctx, type, value);
858880
case NUdf::ETypeKind::Stream: return FromPyStream(ctx, type, TPyObjectPtr(value, TPyObjectPtr::ADD_REF), nullptr, nullptr, nullptr);
859881
case NUdf::ETypeKind::Variant: return FromPyVariant(ctx, type, value);
882+
case NUdf::ETypeKind::Null: return FromPyNull(ctx, type, value);
860883
default: {
861884
::TStringBuilder sb;
862885
sb << "Failed to import: ";

0 commit comments

Comments
 (0)