【发布时间】:2014-05-22 05:40:08
【问题描述】:
我正在尝试通过 Rserve 实现使用 R language 的 Netezza UDX(因此我使用 C++ 的 Rconnection 库)。目前,我只编写了 UDX 运行所需的最低要求。
如下所示:
#define MAIN
// Netezza UDX libraries
#include "udxinc.h"
#include "udxhelpers.h"
// C++ libraries
#include <cstdlib>
#include <cstring>
// external Rserve and R headers
#include "Rconnection.h"
#include "sisocks.h"
using namespace nz::udx::dthelpers;
using namespace nz::udx_ver2;
// extends UDF base class
class My_UDX : public Udf {
public:
Rconnection * rc;
My_UDX(UdxInit *pInit) : Udf(pInit) {
initsocks();
// IP address in place of ...
rc = new Rconnection("...", 6311);
};
~My_UDX() {
delete rc;
}
static Udf* instantiate(UdxInit *pInit);
virtual ReturnValue evaluate();
};
Udf* My_UDX::instantiate(UdxInit *pInit) {
return new My_UDX(pInit);
}
// called once for each row of data during execution
ReturnValue My_UDX::evaluate() {
int32 retval = 15;
NZ_UDX_RETURN_INT32(retval);
}
当我尝试使用 SQL 查询测试 UDX 时出现问题。我的查询如下所示:
SELECT * FROM table_name WHERE My_UDX(table_field) = 1;
这是我收到的错误消息:
Testing...
nzsql -d database_name -u my_username -pw my_password -f sql/test.sql
nzsql:sql/test.sql:1: ERROR: /dev/shm/spuplans/63_1_3.o: undefined symbol: _ZN11RconnectionC1EPKci : loading executable code
make: *** [update] Error 2
如果我删除 Rconnection 对象,UDX 就可以正常工作。
我查看了有关 Netezza UDX、Rserve 和 Rconnection 的不同手册,但没有任何结果。找不到对此错误的任何解释以及可以采取的解决方法。
然后我认为编译过程可能有问题,包含所需的库和标志。我对makefile不太熟悉,所以这是很有可能的。我的 makefile 看起来像这样:
# list of files
function_name = My_UDX
object_files = $(function_name).o_x86
spu_files = $(function_name).o_spu10
# database connection
db_call = nzsql -d database_name -u my_username -pw my_password -f
# path to directories
lib_dir = /home/nz/libs
r_connection_dir = /home/nz/Rconnection
all: update
update: compile
$(db_call) sql/unload.sql
cp $(object_files) $(lib_dir)
cp $(spu_files) $(lib_dir)
rm -f *.o_spu10 *.o_x86
$(db_call) sql/create.sql
$(db_call) sql/test.sql
compile:
nzudxcompile $(function_name).cpp --args -I$(r_connection_dir)
unload.sql 只是删除之前加载的函数,而 create.sql 只是创建它。只有在执行带有前面显示的 SQL 查询的 test.sql 时才会出现问题。
已经尝试解决这个问题很长一段时间,所以任何帮助都将不胜感激!
【问题讨论】:
-
您是否有理由使用 Rserve 而不是按照 IBM 的建议在 Netezza 上安装 R?对于您的问题,如果您使用的是共享库,则必须使用 CREATE OR REPLACE LIBRARY 安装它,否则您的 UDX 将看不到它。
-
因为我们在不同的服务器上安装了 Rserve,而这正是我被分配尝试的。您对共享库的看法是正确的。