summaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/common/python/bindings/py_cast.cpp
diff options
context:
space:
mode:
authorvvvv <[email protected]>2025-10-10 09:49:53 +0300
committervvvv <[email protected]>2025-10-10 10:04:09 +0300
commitc62bab8ab3141ff460f885bf2dafb922e0c19d38 (patch)
treeb37257fe1cd06a87b589992db93124d456f39152 /yql/essentials/udfs/common/python/bindings/py_cast.cpp
parent172bf557598ad5d2a67c1d18ff9d4857a6b40722 (diff)
YQL-20339 Python UDF support
init commit_hash:2a30a1b920f341e1f9250df382dd951604a0894f
Diffstat (limited to 'yql/essentials/udfs/common/python/bindings/py_cast.cpp')
-rw-r--r--yql/essentials/udfs/common/python/bindings/py_cast.cpp31
1 files changed, 31 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 42237428bb3..67524eb7890 100644
--- a/yql/essentials/udfs/common/python/bindings/py_cast.cpp
+++ b/yql/essentials/udfs/common/python/bindings/py_cast.cpp
@@ -7,6 +7,7 @@
#include "py_gil.h"
#include "py_utils.h"
#include "py_void.h"
+#include "py_linear.h"
#include "py_resource.h"
#include "py_stream.h"
#include "py_struct.h"
@@ -899,6 +900,32 @@ NUdf::TUnboxedValue FromPyNull(
throw yexception() << "Can't cast " << PyObjectRepr(value) << " to null.";
}
+TPyObjectPtr ToPyLinear(
+ const TPyCastContext::TPtr& ctx,
+ const NUdf::TType* type,
+ const NUdf::TUnboxedValuePod& value)
+{
+ const NUdf::TLinearTypeInspector inspector(*ctx->PyCtx->TypeInfoHelper, type);
+ if (inspector.IsDynamic()) {
+ return ToPyDynamicLinear(ctx, inspector.GetItemType(), value);
+ }
+
+ return ToPyObject(ctx, inspector.GetItemType(), value);
+}
+
+NUdf::TUnboxedValue FromPyLinear(
+ const TPyCastContext::TPtr& ctx,
+ const NUdf::TType* type, PyObject* value)
+{
+ const NUdf::TLinearTypeInspector inspector(*ctx->PyCtx->TypeInfoHelper, type);
+ if (inspector.IsDynamic()) {
+ TPyObjectPtr valuePtr(value, TPyObjectPtr::ADD_REF);
+ return FromPyDynamicLinear(ctx, inspector.GetItemType(), valuePtr);
+ }
+
+ return FromPyObject(ctx, inspector.GetItemType(), value);
+}
+
} // namespace
TPyObjectPtr ToPyObject(
@@ -932,6 +959,8 @@ TPyObjectPtr ToPyObject(
return ToPyVariant(ctx, type, value);
case NUdf::ETypeKind::Null:
return ToPyNull(ctx, type, value);
+ case NUdf::ETypeKind::Linear:
+ return ToPyLinear(ctx, type, value);
default: {
::TStringBuilder sb;
sb << "Failed to export: ";
@@ -972,6 +1001,8 @@ NUdf::TUnboxedValue FromPyObject(
return FromPyVariant(ctx, type, value);
case NUdf::ETypeKind::Null:
return FromPyNull(ctx, type, value);
+ case NUdf::ETypeKind::Linear:
+ return FromPyLinear(ctx, type, value);
default: {
::TStringBuilder sb;
sb << "Failed to import: ";