C++;未注册Netezza UDF的正则表达式标头 我根据C++文档,使用C++编写IBM的NETEZA上的一个UDF。我的代码编译没有问题 #include <stdarg.h> #include <string.h> #include <regex.h> #include "udxinc.h" #include "udxhelpers.h" using namespace nz::udx_ver2; class Dateconvert: public Udf { public: Dateconvert(UdxInit *pInit) : Udf(pInit){} ~Dateconvert(){} static Udf* instantiate(UdxInit *pInit); virtual ReturnValue evaluate() { StringReturn* ret = stringReturnInfo(); StringArg *str; str = stringArg(0); int lengths = str->length; char *datas = str->data; char retval[100]; strcpy(retval,"99991231"); ret->size = sizeof(retval); memcpy(ret->data, retval, sizeof(retval)); NZ_UDX_RETURN_STRING(ret); } }; Udf* Dateconvert::instantiate(UdxInit *pInit) { return new Dateconvert(pInit); }

C++;未注册Netezza UDF的正则表达式标头 我根据C++文档,使用C++编写IBM的NETEZA上的一个UDF。我的代码编译没有问题 #include <stdarg.h> #include <string.h> #include <regex.h> #include "udxinc.h" #include "udxhelpers.h" using namespace nz::udx_ver2; class Dateconvert: public Udf { public: Dateconvert(UdxInit *pInit) : Udf(pInit){} ~Dateconvert(){} static Udf* instantiate(UdxInit *pInit); virtual ReturnValue evaluate() { StringReturn* ret = stringReturnInfo(); StringArg *str; str = stringArg(0); int lengths = str->length; char *datas = str->data; char retval[100]; strcpy(retval,"99991231"); ret->size = sizeof(retval); memcpy(ret->data, retval, sizeof(retval)); NZ_UDX_RETURN_STRING(ret); } }; Udf* Dateconvert::instantiate(UdxInit *pInit) { return new Dateconvert(pInit); },c++,regex,compiler-errors,include,netezza,C++,Regex,Compiler Errors,Include,Netezza,我得到以下错误: /nz/kit.7.2.0.7-P1/sys/cc/bin/i686-rhel5-linux-gnu-g++ -o /export/home/nz/DateConvert.o_x86 -fPIC -shared -Wa,--32 -march=prescott -mfpmath=sse -D__STDC_CONSTANT_MACROS -DGENCODE -DNZDEBUG=0 -DNZ_UDX_COMPILE -I/nz/kit.7.2.0.7-P1/sys/inclu

我得到以下错误:

/nz/kit.7.2.0.7-P1/sys/cc/bin/i686-rhel5-linux-gnu-g++ -o 
/export/home/nz/DateConvert.o_x86  -fPIC -shared -Wa,--32 -march=prescott
-mfpmath=sse -D__STDC_CONSTANT_MACROS -DGENCODE -DNZDEBUG=0 -DNZ_UDX_COMPILE 
-I/nz/kit.7.2.0.7-P1/sys/include -I/nz/kit.7.2.0.7-P1/sys/include/pg/include
-DLINUX   /export/home/nz/DateConvert.cpp
/export/home/nz/DateConvert.cpp:3:17: error: regex: No such file or directory
/export/home/nz/DateConvert.cpp: In member function 'virtual nz::udx::ReturnValue Dateconvert::evaluate()':
/export/home/nz/DateConvert.cpp:27: error: 'regex' was not declared in this scope
/export/home/nz/DateConvert.cpp:27: error: expected `;' before 'pattern'
/export/home/nz/DateConvert.cpp:45: error: 'pattern' was not declared in this scope
/export/home/nz/DateConvert.cpp:45: error: 'regex_match' was not declared in this scope

每个在线示例都使用C++中的两个标题来表示正则表达式。为什么我编译时它没有注册

顺便说一下,这是编译命令:

nzudxcompile /export/home/nz/dateconvert.cpp -o dateconvert.o 
--sig "Dateconvert(VARCHAR(200))" --version 2 --return "VARCHAR(200)" 
--class Dateconvert --user user1 --pw pw1  --db db1

这不是我的专业领域,但在我看来,Netezza UDX开发所包含的regex.h似乎来自GNU C库,它将使用regcomp和regexec,而不是regex_match

收割台具有用于cpp支持的ifdef块


有几个Netezza UDF示例使用这些函数。

使用std::regex。这是指将“std::regex”附加到任何与regex相关的代码中,还是在代码顶部添加“usingnamespace std::regex”@AlanStokes您可以添加我在代码顶部给出的行(
regex
是一个名称,而不是名称空间)。或者显式地将
std::
放在
regex
前面。在“使用名称空间nz::udx\u ver2”下添加“使用std::regex;”会产生错误“错误:'std::regex'尚未声明”@AlanStokesYou need
#在使用之前也包括
。没有“.h”。
string int_num= "some pattern"
string test= "test"
regex pattern(int_num);
if(regex_match(test, pattern) { do something}; 
/nz/kit.7.2.0.7-P1/sys/cc/bin/i686-rhel5-linux-gnu-g++ -o 
/export/home/nz/DateConvert.o_x86  -fPIC -shared -Wa,--32 -march=prescott
-mfpmath=sse -D__STDC_CONSTANT_MACROS -DGENCODE -DNZDEBUG=0 -DNZ_UDX_COMPILE 
-I/nz/kit.7.2.0.7-P1/sys/include -I/nz/kit.7.2.0.7-P1/sys/include/pg/include
-DLINUX   /export/home/nz/DateConvert.cpp
/export/home/nz/DateConvert.cpp:3:17: error: regex: No such file or directory
/export/home/nz/DateConvert.cpp: In member function 'virtual nz::udx::ReturnValue Dateconvert::evaluate()':
/export/home/nz/DateConvert.cpp:27: error: 'regex' was not declared in this scope
/export/home/nz/DateConvert.cpp:27: error: expected `;' before 'pattern'
/export/home/nz/DateConvert.cpp:45: error: 'pattern' was not declared in this scope
/export/home/nz/DateConvert.cpp:45: error: 'regex_match' was not declared in this scope
nzudxcompile /export/home/nz/dateconvert.cpp -o dateconvert.o 
--sig "Dateconvert(VARCHAR(200))" --version 2 --return "VARCHAR(200)" 
--class Dateconvert --user user1 --pw pw1  --db db1