C++自定义插件如何调用DolphinDB函数

背景

比如想调用这个函数,如何去构建C++代码
attachments-2023-03-FrM3Fcsa6400175ab0e09.png

请先 登录 后评论

1 个回答

Jax Wu

自定义插件调用DolphinDB函数可以参考如下文档的1.4节

https://gitee.com/dolphindb/Tutorials_CN/blob/master/plugin_development_tutorial.md#14-%E8%B0%83%E7%94%A8-dolphindb-%E5%86%85%E7%BD%AE%E5%87%BD%E6%95%B0


attachments-2023-03-vq63PBHe64001d72c5da0.png

内置函数分为运算符函数以及系统函数

step1

目前有两个函数可以区分系统函数还是运算符函数函数

inline bool isSystemFunction() const {return defType_ == SYSFUNC;}
inline FUNCTIONDEF_TYPE getFunctionDefType() const {return defType_;}

step2 系统函数与运算符函数

createPartitionedTable 是系统函数

vector<ConstantSP> args{dbHandle, load(MySQLTableName_or_query, schema, 0, 1), new String(tableName), partitionColumns};
 ret = heap->currentSession()->getFunctionDef("createPartitionedTable")->call(heap, args);

cumsum是运算符函数

ConstantSP v = Util::createIndexVector(1, 100);
v->setTemporary(false);                                   //v 的值可能在内置函数调用时被修改。如果不希望它被修改,应先调用 setTemporary(false)
FunctionDefSP cumsum = heap->currentSession()->getFunctionDef("cumsum");
ConstantSP result = cumsum->call(heap, v, new Void());
// 相当于 cumsum(v),这里的 new Void() 是一个占位符,没有实际用途
请先 登录 后评论