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

Method apply

bolt/python/PythonScalarFunction.cpp:90–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88 returnType_(returnType) {}
89
90 void apply(
91 const SelectivityVector& rows,
92 std::vector<VectorPtr>& args,
93 const TypePtr& outputType,
94 exec::EvalCtx& context,
95 VectorPtr& result) const override {
96 BOLT_CHECK(numArgs_ >= args.size());
97 for (auto& arg : args) {
98 // The argument may be flat or constant.
99 BOLT_CHECK(arg->isFlatEncoding() || arg->isConstantEncoding());
100 }
101
102 BaseVector::ensureWritable(rows, returnType_, context.pool(), result);
103 result->clearNulls(rows);
104
105 rows.applyToSelected([&](auto row) {
106 py::list pyArgs;
107 for (int i = 0; i < args.size(); ++i) {
108 auto& arg = args[i];
109 py::object val = py::none();
110 if (arg->isConstantEncoding()) {
111 val = BOLT_DYNAMIC_SCALAR_TYPE_DISPATCH(
112 getPyObjectFromVector, arg->typeKind(), arg, 0);
113 } else {
114 val = BOLT_DYNAMIC_SCALAR_TYPE_DISPATCH(
115 getPyObjectFromVector, arg->typeKind(), arg, row);
116 }
117 pyArgs.append(val);
118 }
119
120 py::object res =
121 bolt::python::pyTry<py::object>([&]() { return function_(*pyArgs); });
122
123 BOLT_DYNAMIC_SCALAR_TYPE_DISPATCH(
124 setPyObjectInFlatVector, result->typeKind(), result, row, res);
125 });
126 }
127
128 private:
129 int numArgs_;

Callers

nothing calls this directly

Calls 7

ensureWritableFunction · 0.85
applyToSelectedMethod · 0.80
sizeMethod · 0.45
poolMethod · 0.45
clearNullsMethod · 0.45
typeKindMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected