summaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/common/python/python_udf
diff options
context:
space:
mode:
authorvvvv <[email protected]>2025-10-06 13:26:25 +0300
committervvvv <[email protected]>2025-10-06 14:06:25 +0300
commiteca8ce9cb1613d5c983185c4e43c20651a9638aa (patch)
tree61ee5ae779948e61af9a7691d19eaa2c09869121 /yql/essentials/udfs/common/python/python_udf
parent4adf7eecae16a9b228b28cc5f64c27ef69ad5ec2 (diff)
YQL-20086 udfs
init commit_hash:f9684778bf1ea956965f2360b80b91edb7d4ffbe
Diffstat (limited to 'yql/essentials/udfs/common/python/python_udf')
-rw-r--r--yql/essentials/udfs/common/python/python_udf/python_function_factory.h23
-rw-r--r--yql/essentials/udfs/common/python/python_udf/python_udf.cpp65
-rw-r--r--yql/essentials/udfs/common/python/python_udf/python_udf.h12
-rw-r--r--yql/essentials/udfs/common/python/python_udf/ya.make2
4 files changed, 52 insertions, 50 deletions
diff --git a/yql/essentials/udfs/common/python/python_udf/python_function_factory.h b/yql/essentials/udfs/common/python/python_udf/python_function_factory.h
index 7d96f67a083..6f81817f609 100644
--- a/yql/essentials/udfs/common/python/python_udf/python_function_factory.h
+++ b/yql/essentials/udfs/common/python/python_udf/python_function_factory.h
@@ -25,15 +25,14 @@ using namespace NPython;
//////////////////////////////////////////////////////////////////////////////
// TPythonFunctionFactory
//////////////////////////////////////////////////////////////////////////////
-class TPythonFunctionFactory: public TBoxedValue
-{
+class TPythonFunctionFactory: public TBoxedValue {
public:
TPythonFunctionFactory(
- const TStringRef& name,
- const TStringRef& tag,
- const TType* functionType,
- ITypeInfoHelper::TPtr&& helper,
- const NYql::NUdf::TSourcePosition& pos)
+ const TStringRef& name,
+ const TStringRef& tag,
+ const TType* functionType,
+ ITypeInfoHelper::TPtr&& helper,
+ const NYql::NUdf::TSourcePosition& pos)
: Ctx_(new TPyContext(helper, tag, pos))
, FunctionName_(name)
, FunctionType_(functionType)
@@ -47,9 +46,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
TPyCastContext::TPtr castCtx = MakeIntrusive<TPyCastContext>(valueBuilder, Ctx_);
// for get propper c-compatible null-terminating string
@@ -74,7 +72,8 @@ private:
SetupCallableSettings(castCtx, function.Get());
} catch (const yexception& e) {
UdfTerminate((TStringBuilder() << Ctx_->Pos << "Failed to setup callable settings: "
- << e.what()).c_str());
+ << e.what())
+ .c_str());
}
return FromPyCallable(castCtx, FunctionType_, function.Release());
}
@@ -92,7 +91,7 @@ private:
cflags.cf_flags = PyCF_SOURCE_IS_UTF8;
code.ResetSteal(Py_CompileStringFlags(
- source.data(), filename.data(), Py_file_input, &cflags));
+ source.data(), filename.data(), Py_file_input, &cflags));
}
if (code) {
diff --git a/yql/essentials/udfs/common/python/python_udf/python_udf.cpp b/yql/essentials/udfs/common/python/python_udf/python_udf.cpp
index a14d9d81c32..fd0743962ba 100644
--- a/yql/essentials/udfs/common/python/python_udf/python_udf.cpp
+++ b/yql/essentials/udfs/common/python/python_udf/python_udf.cpp
@@ -10,9 +10,9 @@
namespace {
#if PY_MAJOR_VERSION >= 3
-#define PYTHON_PROGRAMM_NAME L"YQL::Python3"
+ #define PYTHON_PROGRAMM_NAME L"YQL::Python3"
#else
-#define PYTHON_PROGRAMM_NAME "YQL::Python2"
+ #define PYTHON_PROGRAMM_NAME "YQL::Python2"
#endif
int AddToPythonPath(const TVector<TStringBuf>& pathVals)
@@ -20,9 +20,11 @@ int AddToPythonPath(const TVector<TStringBuf>& pathVals)
char pathVar[] = "path"; // PySys_{Get,Set}Object take a non-const char* arg
TPyObjectPtr sysPath(PySys_GetObject(pathVar), TPyObjectPtr::ADD_REF);
- if (!sysPath) return -1;
+ if (!sysPath) {
+ return -1;
+ }
- for (const auto& val: pathVals) {
+ for (const auto& val : pathVals) {
TPyObjectPtr pyStr = PyRepr(val.data());
int rc = PyList_Append(sysPath.Get(), pyStr.Get());
if (rc != 0) {
@@ -45,11 +47,11 @@ void InitArcadiaPythonRuntime()
//////////////////////////////////////////////////////////////////////////////
// TPythonModule
//////////////////////////////////////////////////////////////////////////////
-class TPythonModule: public IUdfModule
-{
+class TPythonModule: public IUdfModule {
public:
TPythonModule(const TString& resourceName, EPythonFlavor pythonFlavor, bool standalone = true)
- : ResourceName_(resourceName), Standalone_(standalone)
+ : ResourceName_(resourceName)
+ , Standalone_(standalone)
{
if (Standalone_) {
Py_SetProgramName(PYTHON_PROGRAMM_NAME);
@@ -99,15 +101,15 @@ public:
PyCleanup();
}
- void GetAllFunctions(IFunctionsSink&) const final {}
+ void GetAllFunctions(IFunctionsSink&) const final {
+ }
void BuildFunctionTypeInfo(
- const TStringRef& name,
- TType* userType,
- const TStringRef& typeConfig,
- ui32 flags,
- IFunctionTypeInfoBuilder& builder) const final
- {
+ const TStringRef& name,
+ TType* userType,
+ const TStringRef& typeConfig,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& builder) const final {
Y_UNUSED(typeConfig);
if (flags & TFlags::TypesOnly) {
@@ -137,44 +139,43 @@ private:
// TStubModule
//////////////////////////////////////////////////////////////////////////////
class TStubModule: public IUdfModule {
- void GetAllFunctions(IFunctionsSink&) const final {}
+ void GetAllFunctions(IFunctionsSink&) const final {
+ }
void BuildFunctionTypeInfo(
- const TStringRef& /*name*/,
- TType* /*userType*/,
- const TStringRef& /*typeConfig*/,
- ui32 flags,
- IFunctionTypeInfoBuilder& /*builder*/) const final
- {
+ const TStringRef& /*name*/,
+ TType* /*userType*/,
+ const TStringRef& /*typeConfig*/,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& /*builder*/) const final {
Y_DEBUG_ABORT_UNLESS(flags & TFlags::TypesOnly,
- "in stub module this function can be called only for types loading");
+ "in stub module this function can be called only for types loading");
}
- void CleanupOnTerminate() const final {}
+ void CleanupOnTerminate() const final {
+ }
};
} // namespace
void NKikimr::NUdf::RegisterYqlPythonUdf(
- IRegistrator& registrator,
- ui32 flags,
- TStringBuf moduleName,
- TStringBuf resourceName,
- EPythonFlavor pythonFlavor)
+ IRegistrator& registrator,
+ ui32 flags,
+ TStringBuf moduleName,
+ TStringBuf resourceName,
+ EPythonFlavor pythonFlavor)
{
if (flags & IRegistrator::TFlags::TypesOnly) {
registrator.AddModule(moduleName, new TStubModule);
} else {
registrator.AddModule(
moduleName,
- NKikimr::NUdf::GetYqlPythonUdfModule(resourceName, pythonFlavor, true)
- );
+ NKikimr::NUdf::GetYqlPythonUdfModule(resourceName, pythonFlavor, true));
}
}
TUniquePtr<NKikimr::NUdf::IUdfModule> NKikimr::NUdf::GetYqlPythonUdfModule(
TStringBuf resourceName, NKikimr::NUdf::EPythonFlavor pythonFlavor,
- bool standalone
-) {
+ bool standalone) {
return new TPythonModule(TString(resourceName), pythonFlavor, standalone);
}
diff --git a/yql/essentials/udfs/common/python/python_udf/python_udf.h b/yql/essentials/udfs/common/python/python_udf/python_udf.h
index 83b3bb86e6f..ff8f6e3b07a 100644
--- a/yql/essentials/udfs/common/python/python_udf/python_udf.h
+++ b/yql/essentials/udfs/common/python/python_udf/python_udf.h
@@ -6,7 +6,7 @@ namespace NYql {
namespace NUdf {
inline constexpr char STANDART_STREAM_PROXY_INJECTION_SCRIPT[] =
-R"(
+ R"(
# numpy on import may find installed openblas library and load it,
# which in turn causes it to start CPUCOUNT threads
# with approx. 40Mb memory reserved for each thread;
@@ -66,11 +66,11 @@ enum class EPythonFlavor {
};
void RegisterYqlPythonUdf(
- IRegistrator& registrator,
- ui32 flags,
- TStringBuf moduleName,
- TStringBuf resourceName,
- EPythonFlavor pythonFlavor);
+ IRegistrator& registrator,
+ ui32 flags,
+ TStringBuf moduleName,
+ TStringBuf resourceName,
+ EPythonFlavor pythonFlavor);
TUniquePtr<IUdfModule> GetYqlPythonUdfModule(
TStringBuf resourceName,
diff --git a/yql/essentials/udfs/common/python/python_udf/ya.make b/yql/essentials/udfs/common/python/python_udf/ya.make
index 9a2090665a2..124f075c904 100644
--- a/yql/essentials/udfs/common/python/python_udf/ya.make
+++ b/yql/essentials/udfs/common/python/python_udf/ya.make
@@ -2,6 +2,8 @@ PY23_NATIVE_LIBRARY()
YQL_ABI_VERSION(2 27 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
python_udf.cpp
)