fix: expand scalar param column data to fill the udf datablock
This commit is contained in:
parent
bd99fc5ceb
commit
3108e658e6
|
@ -853,8 +853,15 @@ int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SS
|
||||||
if (isNull) {
|
if (isNull) {
|
||||||
colDataAppendNNULL(pColInfoData, startRow, expandRows);
|
colDataAppendNNULL(pColInfoData, startRow, expandRows);
|
||||||
} else {
|
} else {
|
||||||
char* data = colDataGetData(pColInfoData, (input + i)->numOfRows - 1);
|
char* src = colDataGetData(pColInfoData, (input + i)->numOfRows - 1);
|
||||||
colDataAppendNItems(pColInfoData, startRow, data, expandRows);
|
int32_t bytes = pColInfoData->info.bytes;
|
||||||
|
char* data = taosMemoryMalloc(bytes);
|
||||||
|
memcpy(data, src, bytes);
|
||||||
|
for (int j = 0; j < expandRows; ++j) {
|
||||||
|
colDataAppend(pColInfoData, startRow+j, data, false);
|
||||||
|
}
|
||||||
|
//colDataAppendNItems(pColInfoData, startRow, data, expandRows);
|
||||||
|
taosMemoryFree(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
rm -rf /tmp/udf/libbitand.so /tmp/udf/libsqrsum.so
|
rm -rf /tmp/udf/libbitand.so /tmp/udf/libsqrsum.so /tmp/udf/libgpd.so
|
||||||
mkdir -p /tmp/udf
|
mkdir -p /tmp/udf
|
||||||
echo "compile udf bit_and and sqr_sum"
|
echo "compile udf bit_and and sqr_sum"
|
||||||
gcc -fPIC -shared sh/bit_and.c -I../../include/libs/function/ -I../../include/client -I../../include/util -o /tmp/udf/libbitand.so
|
gcc -fPIC -shared sh/bit_and.c -I../../include/libs/function/ -I../../include/client -I../../include/util -o /tmp/udf/libbitand.so
|
||||||
gcc -fPIC -shared sh/l2norm.c -I../../include/libs/function/ -I../../include/client -I../../include/util -o /tmp/udf/libl2norm.so
|
gcc -fPIC -shared sh/l2norm.c -I../../include/libs/function/ -I../../include/client -I../../include/util -o /tmp/udf/libl2norm.so
|
||||||
|
gcc -fPIC -shared sh/gpd.c -I../../include/libs/function/ -I../../include/client -I../../include/util -o /tmp/udf/libgpd.so
|
||||||
echo "debug show /tmp/udf/*.so"
|
echo "debug show /tmp/udf/*.so"
|
||||||
ls /tmp/udf/*.so
|
ls /tmp/udf/*.so
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,10 @@
|
||||||
TAOS* taos = NULL;
|
TAOS* taos = NULL;
|
||||||
|
|
||||||
DLL_EXPORT int32_t gpd_init() {
|
DLL_EXPORT int32_t gpd_init() {
|
||||||
taos = taos_connect("localhost", "root", "taosdata", "", 7100);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_EXPORT int32_t gpd_destroy() {
|
DLL_EXPORT int32_t gpd_destroy() {
|
||||||
taos_close(taos);
|
|
||||||
taos_cleanup();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,43 +29,18 @@ DLL_EXPORT int32_t gpd(SUdfDataBlock* block, SUdfColumn *resultCol) {
|
||||||
SUdfColumnData *resultData = &resultCol->colData;
|
SUdfColumnData *resultData = &resultCol->colData;
|
||||||
resultData->numOfRows = block->numOfRows;
|
resultData->numOfRows = block->numOfRows;
|
||||||
for (int32_t i = 0; i < resultData->numOfRows; ++i) {
|
for (int32_t i = 0; i < resultData->numOfRows; ++i) {
|
||||||
int j = 0;
|
int64_t* calc_ts = (int64_t*)udfColDataGetData(block->udfCols[0], i);
|
||||||
for (; j < block->numOfCols; ++j) {
|
char* varTbname = udfColDataGetData(block->udfCols[1], i);
|
||||||
if (udfColDataIsNull(block->udfCols[j], i)) {
|
char* varDbname = udfColDataGetData(block->udfCols[2], i);
|
||||||
udfColDataSetNull(resultCol, i);
|
|
||||||
break;
|
char dbName[256] = {0};
|
||||||
}
|
char tblName[256] = {0};
|
||||||
}
|
memcpy(dbName, varDataVal(varDbname), varDataLen(varDbname));
|
||||||
if ( j == block->numOfCols) {
|
memcpy(tblName, varDataVal(varTbname), varDataLen(varTbname));
|
||||||
int32_t luckyNum = 88;
|
printf("%s, %s\n", dbName, tblName);
|
||||||
udfColDataSet(resultCol, i, (char *)&luckyNum, false);
|
int32_t result = 0;
|
||||||
}
|
udfColDataSet(resultCol, i, (char*)&result, false);
|
||||||
}
|
|
||||||
TAOS_RES* res = taos_query(taos, "create database if not exists gpd");
|
|
||||||
if (taos_errno(res) != 0) {
|
|
||||||
char* errstr = taos_errstr(res);
|
|
||||||
}
|
|
||||||
res = taos_query(taos, "create table gpd.st (ts timestamp, f int) tags(t int)");
|
|
||||||
if (taos_errno(res) != 0) {
|
|
||||||
char* errstr = taos_errstr(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taos_query(taos, "insert into gpd.t using gpd.st tags(1) values(now, 1) ");
|
|
||||||
if (taos_errno(res) != 0) {
|
|
||||||
char* errstr = taos_errstr(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_query(taos, "select * from gpd.t");
|
|
||||||
if (taos_errno(res) != 0) {
|
|
||||||
char* errstr = taos_errstr(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
//to simulate actual processing delay by udf
|
|
||||||
#ifdef LINUX
|
|
||||||
usleep(1 * 1000); // usleep takes sleep time in us (1 millionth of a second)
|
|
||||||
#endif
|
|
||||||
#ifdef WINDOWS
|
|
||||||
Sleep(1);
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
system_content printf %OS%
|
||||||
|
if $system_content == Windows_NT then
|
||||||
|
return 0;
|
||||||
|
endi
|
||||||
|
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/cfg.sh -n dnode1 -c udf -v 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print ======== step1 udf
|
||||||
|
system sh/compile_udf.sh
|
||||||
|
sql create database udf vgroups 3;
|
||||||
|
sql use udf;
|
||||||
|
|
||||||
|
sql create table t (ts timestamp, f int);
|
||||||
|
sql insert into t values(now, 1)(now+1s, 2)(now+2s,3)(now+3s,4)(now+4s,5)(now+5s,6)(now+6s,7);
|
||||||
|
|
||||||
|
system_content printf %OS%
|
||||||
|
if $system_content == Windows_NT then
|
||||||
|
return 0;
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $system_content == Windows_NT then
|
||||||
|
sql create function gpd as 'C:\\Windows\\Temp\\gpd.dll' outputtype int bufSize 8;
|
||||||
|
else
|
||||||
|
sql create function gpd as '/tmp/udf/libgpd.so' outputtype int bufSize 8;
|
||||||
|
endi
|
||||||
|
sql show functions;
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select gpd(ts, tbname, 'detail') from t;
|
||||||
|
if $rows != 7 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
print $data00 $data10
|
||||||
|
if $data00 != @0@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql drop function gpd;
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
Loading…
Reference in New Issue