Merge pull request #20669 from taosdata/szhou/python-udf-improvement
enhance: add language and body to ins_functions
This commit is contained in:
commit
333bbe73d5
|
@ -114,6 +114,8 @@ static const SSysDbTableSchema userFuncSchema[] = {
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
||||||
{.name = "code_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
{.name = "code_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
||||||
{.name = "bufsize", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
{.name = "bufsize", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
||||||
|
{.name = "func_language", .bytes = TSDB_TYPE_STR_MAX_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||||
|
{.name = "func_body", .bytes = TSDB_MAX_BINARY_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SSysDbTableSchema userIdxSchema[] = {
|
static const SSysDbTableSchema userIdxSchema[] = {
|
||||||
|
|
|
@ -519,6 +519,7 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataSetVal(pColInfo, numOfRows, (const char *)b2, false);
|
colDataSetVal(pColInfo, numOfRows, (const char *)b2, false);
|
||||||
|
taosMemoryFree(b2);
|
||||||
} else {
|
} else {
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataSetVal(pColInfo, numOfRows, NULL, true);
|
colDataSetVal(pColInfo, numOfRows, NULL, true);
|
||||||
|
@ -545,6 +546,26 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->bufSize, false);
|
colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->bufSize, false);
|
||||||
|
|
||||||
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
char* language = "";
|
||||||
|
if (pFunc->scriptType == TSDB_FUNC_SCRIPT_BIN_LIB) {
|
||||||
|
language = "C";
|
||||||
|
} else if (pFunc->scriptType == TSDB_FUNC_SCRIPT_PYTHON) {
|
||||||
|
language = "Python";
|
||||||
|
}
|
||||||
|
char varLang[TSDB_TYPE_STR_MAX_LEN + 1] = {0};
|
||||||
|
varDataSetLen(varLang, strlen(language));
|
||||||
|
strcpy(varDataVal(varLang), language);
|
||||||
|
colDataSetVal(pColInfo, numOfRows, (const char *)varLang, false);
|
||||||
|
|
||||||
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
int32_t varCodeLen = (pFunc->codeSize + VARSTR_HEADER_SIZE) > TSDB_MAX_BINARY_LEN ? TSDB_MAX_BINARY_LEN : pFunc->codeSize + VARSTR_HEADER_SIZE;
|
||||||
|
char *b4 = taosMemoryMalloc(varCodeLen);
|
||||||
|
memcpy(varDataVal(b4), pFunc->pCode, varCodeLen - VARSTR_HEADER_SIZE);
|
||||||
|
varDataSetLen(b4, varCodeLen - VARSTR_HEADER_SIZE);
|
||||||
|
colDataSetVal(pColInfo, numOfRows, (const char*)b4, false);
|
||||||
|
taosMemoryFree(b4);
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
sdbRelease(pSdb, pFunc);
|
sdbRelease(pSdb, pFunc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1070,8 +1070,15 @@ int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols,
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SUdfcUvSession *session = handle;
|
SUdfcUvSession *session = handle;
|
||||||
code = doCallUdfScalarFunc(handle, input, numOfCols, output);
|
code = doCallUdfScalarFunc(handle, input, numOfCols, output);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
fnError("udfc scalar function execution failure");
|
||||||
|
releaseUdfFuncHandle(udfName);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
if (output->columnData == NULL) {
|
if (output->columnData == NULL) {
|
||||||
fnError("udfc scalar function calculate error. no column data");
|
fnError("udfc scalar function calculate error. no column data");
|
||||||
code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
||||||
|
|
|
@ -42,6 +42,25 @@ sql show functions;
|
||||||
if $rows != 4 then
|
if $rows != 4 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
sql select func_language, func_body,name from information_schema.ins_functions order by name
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 != @C@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data10 != @C@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data20 != @Python@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data30 != @Python@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
sql select bit_and(f, f) from t;
|
sql select bit_and(f, f) from t;
|
||||||
if $rows != 2 then
|
if $rows != 2 then
|
||||||
return -1
|
return -1
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TDTestCase:
|
||||||
tdSql.execute("insert into db.ctb using db.stb tags(1) (ts, c1) values (now, 1)")
|
tdSql.execute("insert into db.ctb using db.stb tags(1) (ts, c1) values (now, 1)")
|
||||||
|
|
||||||
tdSql.query("select count(*) from information_schema.ins_columns")
|
tdSql.query("select count(*) from information_schema.ins_columns")
|
||||||
tdSql.checkData(0, 0, 272)
|
tdSql.checkData(0, 0, 274)
|
||||||
|
|
||||||
tdSql.query("select * from information_schema.ins_columns where table_name = 'ntb'")
|
tdSql.query("select * from information_schema.ins_columns where table_name = 'ntb'")
|
||||||
tdSql.checkRows(14)
|
tdSql.checkRows(14)
|
||||||
|
|
Loading…
Reference in New Issue