MCPcopy Create free account
hub / github.com/bytedance/bolt / asPyArgs

Function asPyArgs

bolt/python/Utils.cpp:144–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144pybind11::list asPyArgs(
145 const size_t numExpectedArgs,
146 const std::vector<VectorPtr>& args,
147 const std::vector<pybind11::object>& defaultArgs) {
148 BOLT_CHECK_LE(args.size(), numExpectedArgs);
149 BOLT_CHECK_GE(args.size() + defaultArgs.size(), numExpectedArgs);
150
151 pybind11::list pyArgs;
152 auto arg = args.cbegin();
153
154 // Append arguments without existing default value as is.
155 for (; arg != args.cbegin() + (numExpectedArgs - defaultArgs.size()); ++arg) {
156 (*arg)->loadedVector();
157 appendGenericArg(pyArgs, *arg);
158 }
159
160 // Arguments with a default value that is a constant type are expected to
161 // be a python scalar by the user python function. However, when providing
162 // a scalar value as part of a UDF expression, the value is converted into
163 // a constant vector. Therefore, we need to recast the constant vector value
164 // into a python scalar value
165 //
166 // This loop will iterate through arguments provided by the user which also
167 // have a default value.
168 for (; arg != args.cend(); ++arg) {
169 (*arg)->loadedVector();
170 if ((*arg)->encoding() == VectorEncoding::Simple::CONSTANT) {
171 BOLT_DYNAMIC_SCALAR_TYPE_DISPATCH(
172 appendConstantValue, (*arg)->type()->kind(), pyArgs, **arg);
173 } else {
174 appendGenericArg(pyArgs, *arg);
175 }
176 }
177
178 // Iterate through remaining arguments that use the default value.
179 for (auto defaultArg = defaultArgs.cend() - (numExpectedArgs - args.size());
180 defaultArg != defaultArgs.cend();
181 ++defaultArg) {
182 pyArgs.append(*defaultArg);
183 }
184
185 return pyArgs;
186}
187
188std::shared_ptr<RowVector> combineInputColumns(
189 const std::vector<VectorPtr>& args,

Callers 1

applyMethod · 0.85

Calls 9

appendGenericArgFunction · 0.85
cbeginMethod · 0.80
cendMethod · 0.80
sizeMethod · 0.45
loadedVectorMethod · 0.45
encodingMethod · 0.45
kindMethod · 0.45
typeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected