diff options
author | vvvv <[email protected]> | 2025-06-17 23:08:38 +0300 |
---|---|---|
committer | vvvv <[email protected]> | 2025-06-18 11:14:06 +0300 |
commit | 7803a38571cb0dc674b01065f374c116de966b4b (patch) | |
tree | 1e3e98c1d5205cf9930965e6a5c6a967824165ac /yql/essentials/udfs/common/python | |
parent | 80d6f567b04024db1404525203859e917f332a26 (diff) |
YQL-20086 udfs
commit_hash:631fd9ed259a7c95a618e1265f61df28a87ce922
Diffstat (limited to 'yql/essentials/udfs/common/python')
11 files changed, 71 insertions, 71 deletions
diff --git a/yql/essentials/udfs/common/python/bindings/py_cast.cpp b/yql/essentials/udfs/common/python/bindings/py_cast.cpp index ac44ac42e5a..fe2a6eb5002 100644 --- a/yql/essentials/udfs/common/python/bindings/py_cast.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_cast.cpp @@ -27,11 +27,11 @@ #include <util/string/builder.h> #ifdef HAVE_LONG_LONG -# define YQL_PyLong_AsUnsignedMask PyLong_AsUnsignedLongLongMask +# define YQL_PyLong_AsUnsignedMask PyLong_AsUnsignedLongLongMask // NOLINT(readability-identifier-naming) # define YQL_PyLong_Asi64 PyLong_AsLongLong # define YQL_PyLong_Asui64 PyLong_AsUnsignedLongLong #else -# define YQL_PyLong_AsUnsignedMask PyLong_AsUnsignedLongMask +# define YQL_PyLong_AsUnsignedMask PyLong_AsUnsignedLongMask // NOLINT(readability-identifier-naming) # define YQL_PyLong_Asi64 PyLong_AsLong # define YQL_PyLong_Asui64 PyLong_AsUnsignedLong #endif diff --git a/yql/essentials/udfs/common/python/bindings/py_ctx.h b/yql/essentials/udfs/common/python/bindings/py_ctx.h index 9e86042908f..7958fc1f815 100644 --- a/yql/essentials/udfs/common/python/bindings/py_ctx.h +++ b/yql/essentials/udfs/common/python/bindings/py_ctx.h @@ -41,28 +41,28 @@ public: } void Cleanup() override { - Value = {}; + Value_ = {}; } template <typename TCtx> void Set(const TIntrusivePtr<TCtx>& ctx, TValueType val) { - Value = std::move(val); + Value_ = std::move(val); ctx->CleanupList.PushBack(this); } bool IsSet() const { - return !!Value; + return !!Value_; } const TValueType& Get() const { - if (!Value) { + if (!Value_) { throw yexception() << "Trying to use python wrap object with destroyed yql value"; } - return Value; + return Value_; } private: - TValueType Value; + TValueType Value_; }; struct TPyContext: public TSimpleRefCount<TPyContext> { diff --git a/yql/essentials/udfs/common/python/bindings/py_dict.cpp b/yql/essentials/udfs/common/python/bindings/py_dict.cpp index f2bd0669eda..2df6eb4e99f 100644 --- a/yql/essentials/udfs/common/python/bindings/py_dict.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_dict.cpp @@ -144,8 +144,8 @@ PyNumberMethods LazyDictNumbering = { #if PY_MAJOR_VERSION >= 3 -#define Py_TPFLAGS_HAVE_ITER 0 -#define Py_TPFLAGS_HAVE_SEQUENCE_IN 0 +#define Py_TPFLAGS_HAVE_ITER 0 // NOLINT(readability-identifier-naming) +#define Py_TPFLAGS_HAVE_SEQUENCE_IN 0 // NOLINT(readability-identifier-naming) #endif PyDoc_STRVAR(get__doc__, diff --git a/yql/essentials/udfs/common/python/bindings/py_gil.h b/yql/essentials/udfs/common/python/bindings/py_gil.h index 70e9bf3e91d..6d629e7b237 100644 --- a/yql/essentials/udfs/common/python/bindings/py_gil.h +++ b/yql/essentials/udfs/common/python/bindings/py_gil.h @@ -8,30 +8,30 @@ namespace NPython { struct TPyGilLocker { TPyGilLocker() - : Gil(PyGILState_Ensure()) + : Gil_(PyGILState_Ensure()) { } ~TPyGilLocker() { - PyGILState_Release(Gil); + PyGILState_Release(Gil_); } private: - PyGILState_STATE Gil; + PyGILState_STATE Gil_; }; struct TPyGilUnlocker { TPyGilUnlocker() - : ThreadState(PyEval_SaveThread()) + : ThreadState_(PyEval_SaveThread()) { } ~TPyGilUnlocker() { - PyEval_RestoreThread(ThreadState); + PyEval_RestoreThread(ThreadState_); } private: - PyThreadState* ThreadState; + PyThreadState* ThreadState_; }; } // namespace NPython diff --git a/yql/essentials/udfs/common/python/bindings/py_iterator.cpp b/yql/essentials/udfs/common/python/bindings/py_iterator.cpp index 090211be2c1..c6f21cecb16 100644 --- a/yql/essentials/udfs/common/python/bindings/py_iterator.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_iterator.cpp @@ -38,7 +38,7 @@ struct TPyIterator }; #if PY_MAJOR_VERSION >= 3 -#define Py_TPFLAGS_HAVE_ITER 0 +#define Py_TPFLAGS_HAVE_ITER 0 // NOLINT(readability-identifier-naming) #endif PyTypeObject PyIteratorType = { diff --git a/yql/essentials/udfs/common/python/bindings/py_lazy_mkql_dict.cpp b/yql/essentials/udfs/common/python/bindings/py_lazy_mkql_dict.cpp index ffaa2fe4ec0..b9d90e49f9f 100644 --- a/yql/essentials/udfs/common/python/bindings/py_lazy_mkql_dict.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_lazy_mkql_dict.cpp @@ -508,35 +508,35 @@ private: class TKeyIterator: public NUdf::TBoxedValue { public: TKeyIterator(Py_ssize_t size) - : Size(size), Index(0) + : Size_(size), Index_(0) {} private: bool Skip() override { - if (Index >= Size) + if (Index_ >= Size_) return false; - ++Index; + ++Index_; return true; } bool Next(NUdf::TUnboxedValue& value) override { - if (Index >= Size) + if (Index_ >= Size_) return false; - value = NUdf::TUnboxedValuePod(KeyType(Index++)); + value = NUdf::TUnboxedValuePod(KeyType(Index_++)); return true; } private: - const Py_ssize_t Size; - Py_ssize_t Index; + const Py_ssize_t Size_; + Py_ssize_t Index_; }; class TIterator: public NUdf::TBoxedValue { public: TIterator(const TPyCastContext::TPtr& ctx, const NUdf::TType* itemType, Py_ssize_t size, const TPyObjectPtr& pySeq) - : CastCtx_(ctx), ItemType_(itemType), PySeq_(pySeq), Size(size), Index(0) + : CastCtx_(ctx), ItemType_(itemType), PySeq_(pySeq), Size_(size), Index_(0) {} ~TIterator() { @@ -546,31 +546,31 @@ private: private: bool Skip() override { - if (Index >= Size) + if (Index_ >= Size_) return false; - ++Index; + ++Index_; return true; } bool Next(NUdf::TUnboxedValue& value) override try { - if (Index >= Size) + if (Index_ >= Size_) return false; const TPyGilLocker lock; - value = FromPyObject(CastCtx_, ItemType_, PySequence_Fast_GET_ITEM(PySeq_.Get(), Index++)); + value = FromPyObject(CastCtx_, ItemType_, PySequence_Fast_GET_ITEM(PySeq_.Get(), Index_++)); return true; } catch (const yexception& e) { UdfTerminate((TStringBuilder() << CastCtx_->PyCtx->Pos << e.what()).data()); } bool NextPair(NUdf::TUnboxedValue& key, NUdf::TUnboxedValue& pay) override try { - if (Index >= Size) + if (Index_ >= Size_) return false; const TPyGilLocker lock; - key = NUdf::TUnboxedValuePod(KeyType(Index)); - pay = FromPyObject(CastCtx_, ItemType_, PySequence_Fast_GET_ITEM(PySeq_.Get(), Index++)); + key = NUdf::TUnboxedValuePod(KeyType(Index_)); + pay = FromPyObject(CastCtx_, ItemType_, PySequence_Fast_GET_ITEM(PySeq_.Get(), Index_++)); return true; } catch (const yexception& e) { UdfTerminate((TStringBuilder() << CastCtx_->PyCtx->Pos << e.what()).data()); @@ -580,13 +580,13 @@ private: const TPyCastContext::TPtr CastCtx_; const NUdf::TType* ItemType_; TPyObjectPtr PySeq_; - const Py_ssize_t Size; - Py_ssize_t Index; + const Py_ssize_t Size_; + Py_ssize_t Index_; }; public: TLazySequenceAsDict(const TPyCastContext::TPtr& ctx, const NUdf::TType* itemType, TPyObjectPtr&& sequence, Py_ssize_t size) - : CastCtx_(ctx), ItemType_(itemType), Size(size), PySeq_(std::move(sequence)) + : CastCtx_(ctx), ItemType_(itemType), Size_(size), PySeq_(std::move(sequence)) {} ~TLazySequenceAsDict() @@ -599,18 +599,18 @@ private: bool IsSortedDict() const override { return true; } bool HasDictItems() const override { - return Size > 0; + return Size_ > 0; } ui64 GetDictLength() const override { - return Size; + return Size_; } NUdf::TUnboxedValue Lookup(const NUdf::TUnboxedValuePod& key) const override { const Py_ssize_t index = key.Get<KeyType>(); - if (index >= -Size && index < Size) try { + if (index >= -Size_ && index < Size_) try { const TPyGilLocker lock; - if (const auto item = PySequence_Fast_GET_ITEM(PySeq_.Get(), index >= 0 ? index : Size + index)) { + if (const auto item = PySequence_Fast_GET_ITEM(PySeq_.Get(), index >= 0 ? index : Size_ + index)) { return FromPyObject(CastCtx_, ItemType_, item).Release().MakeOptional(); } else if (PyErr_Occurred()) { UdfTerminate((TStringBuilder() << CastCtx_->PyCtx->Pos << GetLastErrorAsString()).data()); @@ -623,24 +623,24 @@ private: bool Contains(const NUdf::TUnboxedValuePod& key) const override { const Py_ssize_t index = key.Get<KeyType>(); - return index >= -Size && index < Size; + return index >= -Size_ && index < Size_; } NUdf::TUnboxedValue GetKeysIterator() const override { - return NUdf::TUnboxedValuePod(new TKeyIterator(Size)); + return NUdf::TUnboxedValuePod(new TKeyIterator(Size_)); } NUdf::TUnboxedValue GetPayloadsIterator() const override { - return NUdf::TUnboxedValuePod(new TIterator(CastCtx_, ItemType_, Size, PySeq_)); + return NUdf::TUnboxedValuePod(new TIterator(CastCtx_, ItemType_, Size_, PySeq_)); } NUdf::TUnboxedValue GetDictIterator() const override { - return NUdf::TUnboxedValuePod(new TIterator(CastCtx_, ItemType_, Size, PySeq_)); + return NUdf::TUnboxedValuePod(new TIterator(CastCtx_, ItemType_, Size_, PySeq_)); } const TPyCastContext::TPtr CastCtx_; const NUdf::TType* ItemType_; - const Py_ssize_t Size; + const Py_ssize_t Size_; TPyObjectPtr PySeq_; }; diff --git a/yql/essentials/udfs/common/python/bindings/py_list.cpp b/yql/essentials/udfs/common/python/bindings/py_list.cpp index 376a1ca124a..bbae59865f2 100644 --- a/yql/essentials/udfs/common/python/bindings/py_list.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_list.cpp @@ -165,7 +165,7 @@ static PyMethodDef TPyLazyListMethods[] = { }; #if PY_MAJOR_VERSION >= 3 -#define Py_TPFLAGS_HAVE_ITER 0 +#define Py_TPFLAGS_HAVE_ITER 0 // NOLINT(readability-identifier-naming) #endif PyTypeObject PyLazyListType = { @@ -736,7 +736,7 @@ static PyMethodDef TPyThinListMethods[] = { }; #if PY_MAJOR_VERSION >= 3 -#define Py_TPFLAGS_HAVE_ITER 0 +#define Py_TPFLAGS_HAVE_ITER 0 // NOLINT(readability-identifier-naming) #endif PyTypeObject PyThinListType = { diff --git a/yql/essentials/udfs/common/python/bindings/py_stream.cpp b/yql/essentials/udfs/common/python/bindings/py_stream.cpp index 3d9aecdc00b..5be78e442aa 100644 --- a/yql/essentials/udfs/common/python/bindings/py_stream.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_stream.cpp @@ -49,7 +49,7 @@ struct TPyStream { }; #if PY_MAJOR_VERSION >= 3 -#define Py_TPFLAGS_HAVE_ITER 0 +#define Py_TPFLAGS_HAVE_ITER 0 // NOLINT(readability-identifier-naming) #endif PyTypeObject PyStreamType = { diff --git a/yql/essentials/udfs/common/python/bindings/py_yql_module.cpp b/yql/essentials/udfs/common/python/bindings/py_yql_module.cpp index 5d1497f7c76..11ba4262173 100644 --- a/yql/essentials/udfs/common/python/bindings/py_yql_module.cpp +++ b/yql/essentials/udfs/common/python/bindings/py_yql_module.cpp @@ -94,21 +94,21 @@ static PyModuleDef ModuleDefinitionTyping = { INIT_MEMBER(m_free, nullptr), }; -PyMODINIT_FUNC PyInit_YQL(void) +PyMODINIT_FUNC PyInit_YQL(void) // NOLINT(readability-identifier-naming) { auto mod = PyModule_Create(&ModuleDefinition); PyModule_AddObject(mod, "__path__", Py_BuildValue("()")); return mod; } -void go_throw(); +void GoThrow(); -PyMODINIT_FUNC PyInit_YQLTyping(void) +PyMODINIT_FUNC PyInit_YQLTyping(void) // NOLINT(readability-identifier-naming) { return PyModule_Create(&ModuleDefinitionTyping); } #else -PyMODINIT_FUNC PyInit_YQL(void) +PyMODINIT_FUNC PyInit_YQL(void) // NOLINT(readability-identifier-naming) { Py_InitModule3(MODULE_NAME, ModuleMethods, ModuleDoc); } 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 a4e393b4868..657fb1f442b 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 @@ -34,14 +34,14 @@ public: const TType* functionType, ITypeInfoHelper::TPtr&& helper, const NYql::NUdf::TSourcePosition& pos) - : Ctx(new TPyContext(helper, tag, pos)) - , FunctionName(name) + : Ctx_(new TPyContext(helper, tag, pos)) + , FunctionName_(name) , FunctionType_(functionType) { } ~TPythonFunctionFactory() { - Ctx->Cleanup(); + Ctx_->Cleanup(); PyCleanup(); } @@ -50,30 +50,30 @@ private: const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const override { - TPyCastContext::TPtr castCtx = MakeIntrusive<TPyCastContext>(valueBuilder, Ctx); + TPyCastContext::TPtr castCtx = MakeIntrusive<TPyCastContext>(valueBuilder, Ctx_); // for get propper c-compatible null-terminating string TString source(args[0].AsStringRef()); TPyGilLocker lock; - TPyObjectPtr module = CompileModule(FunctionName, source); + TPyObjectPtr module = CompileModule(FunctionName_, source); if (!module) { - UdfTerminate((TStringBuilder() << Ctx->Pos << "Failed to compile module: " << GetLastErrorAsString()).data()); + UdfTerminate((TStringBuilder() << Ctx_->Pos << "Failed to compile module: " << GetLastErrorAsString()).data()); } - TPyObjectPtr function(PyObject_GetAttrString(module.Get(), FunctionName.data())); + TPyObjectPtr function(PyObject_GetAttrString(module.Get(), FunctionName_.data())); if (!function) { - UdfTerminate((TStringBuilder() << Ctx->Pos << "Failed to find entry point: " << GetLastErrorAsString()).data()); + UdfTerminate((TStringBuilder() << Ctx_->Pos << "Failed to find entry point: " << GetLastErrorAsString()).data()); } if (!PyCallable_Check(function.Get())) { - UdfTerminate((TStringBuilder() << Ctx->Pos << "Entry point is not a callable").data()); + UdfTerminate((TStringBuilder() << Ctx_->Pos << "Entry point is not a callable").data()); } try { SetupCallableSettings(castCtx, function.Get()); } catch (const yexception& e) { - UdfTerminate((TStringBuilder() << Ctx->Pos << "Failed to setup callable settings: " + UdfTerminate((TStringBuilder() << Ctx_->Pos << "Failed to setup callable settings: " << e.what()).data()); } return FromPyCallable(castCtx, FunctionType_, function.Release()); @@ -104,8 +104,8 @@ private: return module; } - const TPyContext::TPtr Ctx; - const TString FunctionName; + const TPyContext::TPtr Ctx_; + const TString FunctionName_; const TType* FunctionType_; inline static std::atomic_uint AtomicCounter = 0; }; 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 1007c75edc3..a14d9d81c32 100644 --- a/yql/essentials/udfs/common/python/python_udf/python_udf.cpp +++ b/yql/essentials/udfs/common/python/python_udf/python_udf.cpp @@ -49,9 +49,9 @@ class TPythonModule: public IUdfModule { public: TPythonModule(const TString& resourceName, EPythonFlavor pythonFlavor, bool standalone = true) - : ResourceName(resourceName), Standalone(standalone) + : ResourceName_(resourceName), Standalone_(standalone) { - if (Standalone) { + if (Standalone_) { Py_SetProgramName(PYTHON_PROGRAMM_NAME); PrepareYqlModule(); Py_Initialize(); @@ -67,7 +67,7 @@ public: } #ifndef _win_ - if (Standalone) { + if (Standalone_) { TVector<TStringBuf> paths; if (pythonFlavor == EPythonFlavor::System) { paths.push_back(TStringBuf("/usr/lib/python2.7/dist-packages")); @@ -82,14 +82,14 @@ public: TPyObjectPtr pyExecutableStr = PyRepr(GetExecPath().data()); Y_ABORT_UNLESS(PySys_SetObject(executableVar, pyExecutableStr.Get()) >= 0, "Can't set sys.executable"); - if (Standalone) { + if (Standalone_) { PyEval_InitThreads(); MainThreadState_ = PyEval_SaveThread(); } } ~TPythonModule() { - if (Standalone) { + if (Standalone_) { PyEval_RestoreThread(MainThreadState_); Py_Finalize(); } @@ -121,15 +121,15 @@ public: } const auto pos = builder.GetSourcePosition(); - builder.Implementation(new TPythonFunctionFactory(name, ResourceName, userType, std::move(typeHelper), pos)); + builder.Implementation(new TPythonFunctionFactory(name, ResourceName_, userType, std::move(typeHelper), pos)); } catch (const yexception& e) { builder.SetError(TStringBuf(e.what())); } } private: - TString ResourceName; - bool Standalone; + TString ResourceName_; + bool Standalone_; PyThreadState* MainThreadState_; }; |