Merge pull request #27083 from taosdata/docs/udf
enh: enable log in udf
This commit is contained in:
commit
0d1d462e08
|
@ -320,6 +320,30 @@ typedef int32_t (*TScriptUdfDestoryFunc)(void *udfCtx);
|
||||||
typedef int32_t (*TScriptOpenFunc)(SScriptUdfEnvItem *items, int numItems);
|
typedef int32_t (*TScriptOpenFunc)(SScriptUdfEnvItem *items, int numItems);
|
||||||
typedef int32_t (*TScriptCloseFunc)();
|
typedef int32_t (*TScriptCloseFunc)();
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
#ifdef WINDOWS
|
||||||
|
#define fnFatal(...) {}
|
||||||
|
#define fnError(...) {}
|
||||||
|
#define fnWarn(...) {}
|
||||||
|
#define fnInfo(...) {}
|
||||||
|
#define fnDebug(...) {}
|
||||||
|
#define fnTrace(...) {}
|
||||||
|
#else
|
||||||
|
DLL_EXPORT void taosPrintLog(const char *flags, int32_t level, int32_t dflag, const char *format, ...)
|
||||||
|
#ifdef __GNUC__
|
||||||
|
__attribute__((format(printf, 4, 5)))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
extern int32_t udfDebugFlag;
|
||||||
|
#define udfFatal(...) { if (udfDebugFlag & 1) { taosPrintLog("UDF FATAL ", 1, 255, __VA_ARGS__); }}
|
||||||
|
#define udfError(...) { if (udfDebugFlag & 1) { taosPrintLog("UDF ERROR ", 1, 255, __VA_ARGS__); }}
|
||||||
|
#define udfWarn(...) { if (udfDebugFlag & 2) { taosPrintLog("UDF WARN ", 2, 255, __VA_ARGS__); }}
|
||||||
|
#define udfInfo(...) { if (udfDebugFlag & 2) { taosPrintLog("UDF ", 2, 255, __VA_ARGS__); }}
|
||||||
|
#define udfDebug(...) { if (udfDebugFlag & 4) { taosPrintLog("UDF ", 4, udfDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define udfTrace(...) { if (udfDebugFlag & 8) { taosPrintLog("UDF ", 8, udfDebugFlag, __VA_ARGS__); }}
|
||||||
|
#endif
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -74,13 +74,13 @@ void taosCloseLog();
|
||||||
void taosResetLog();
|
void taosResetLog();
|
||||||
void taosDumpData(uint8_t *msg, int32_t len);
|
void taosDumpData(uint8_t *msg, int32_t len);
|
||||||
|
|
||||||
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
|
void taosPrintLog(const char *flags, int32_t level, int32_t dflag, const char *format, ...)
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__attribute__((format(printf, 4, 5)))
|
__attribute__((format(printf, 4, 5)))
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
|
void taosPrintLongString(const char *flags, int32_t level, int32_t dflag, const char *format, ...)
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__attribute__((format(printf, 4, 5)))
|
__attribute__((format(printf, 4, 5)))
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -567,7 +567,7 @@ static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
|
void taosPrintLog(const char *flags, int32_t level, int32_t dflag, const char *format, ...) {
|
||||||
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
|
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
|
||||||
|
|
||||||
char buffer[LOG_MAX_LINE_BUFFER_SIZE];
|
char buffer[LOG_MAX_LINE_BUFFER_SIZE];
|
||||||
|
@ -590,7 +590,7 @@ void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
|
void taosPrintLongString(const char *flags, int32_t level, int32_t dflag, const char *format, ...) {
|
||||||
if (!osLogSpaceAvailable()) return;
|
if (!osLogSpaceAvailable()) return;
|
||||||
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
|
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,17 @@ DLL_EXPORT int32_t bit_and_init() { return 0; }
|
||||||
DLL_EXPORT int32_t bit_and_destroy() { return 0; }
|
DLL_EXPORT int32_t bit_and_destroy() { return 0; }
|
||||||
|
|
||||||
DLL_EXPORT int32_t bit_and(SUdfDataBlock* block, SUdfColumn* resultCol) {
|
DLL_EXPORT int32_t bit_and(SUdfDataBlock* block, SUdfColumn* resultCol) {
|
||||||
|
udfTrace("block:%p, processing begins, rows:%d cols:%d", block, block->numOfRows, block->numOfCols);
|
||||||
|
|
||||||
if (block->numOfCols < 2) {
|
if (block->numOfCols < 2) {
|
||||||
|
udfError("block:%p, cols:%d needs to be greater than 2", block, block->numOfCols);
|
||||||
return TSDB_CODE_UDF_INVALID_INPUT;
|
return TSDB_CODE_UDF_INVALID_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < block->numOfCols; ++i) {
|
for (int32_t i = 0; i < block->numOfCols; ++i) {
|
||||||
SUdfColumn* col = block->udfCols[i];
|
SUdfColumn* col = block->udfCols[i];
|
||||||
if (!(col->colMeta.type == TSDB_DATA_TYPE_INT)) {
|
if (col->colMeta.type != TSDB_DATA_TYPE_INT) {
|
||||||
|
udfError("block:%p, col:%d type:%d should be int(%d)", block, i, col->colMeta.type, TSDB_DATA_TYPE_INT);
|
||||||
return TSDB_CODE_UDF_INVALID_INPUT;
|
return TSDB_CODE_UDF_INVALID_INPUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,25 +27,35 @@ DLL_EXPORT int32_t bit_and(SUdfDataBlock* block, SUdfColumn* resultCol) {
|
||||||
|
|
||||||
for (int32_t i = 0; i < block->numOfRows; ++i) {
|
for (int32_t i = 0; i < block->numOfRows; ++i) {
|
||||||
if (udfColDataIsNull(block->udfCols[0], i)) {
|
if (udfColDataIsNull(block->udfCols[0], i)) {
|
||||||
|
udfTrace("block:%p, row:%d result is null since col:0 is null", block, i);
|
||||||
udfColDataSetNull(resultCol, i);
|
udfColDataSetNull(resultCol, i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t result = *(int32_t*)udfColDataGetData(block->udfCols[0], i);
|
int32_t result = *(int32_t*)udfColDataGetData(block->udfCols[0], i);
|
||||||
int j = 1;
|
udfTrace("block:%p, row:%d col:0 data:%d", block, i, result);
|
||||||
|
|
||||||
|
int32_t j = 1;
|
||||||
for (; j < block->numOfCols; ++j) {
|
for (; j < block->numOfCols; ++j) {
|
||||||
if (udfColDataIsNull(block->udfCols[j], i)) {
|
if (udfColDataIsNull(block->udfCols[j], i)) {
|
||||||
|
udfTrace("block:%p, row:%d result is null since col:%d is null", block, i, j);
|
||||||
udfColDataSetNull(resultCol, i);
|
udfColDataSetNull(resultCol, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* colData = udfColDataGetData(block->udfCols[j], i);
|
char* colData = udfColDataGetData(block->udfCols[j], i);
|
||||||
result &= *(int32_t*)colData;
|
result &= *(int32_t*)colData;
|
||||||
|
udfTrace("block:%p, row:%d col:%d data:%d", block, i, j, *(int32_t*)colData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j == block->numOfCols) {
|
if (j == block->numOfCols) {
|
||||||
udfColDataSet(resultCol, i, (char*)&result, false);
|
udfColDataSet(resultCol, i, (char*)&result, false);
|
||||||
|
udfTrace("block:%p, row:%d result is %d", block, i, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resultData->numOfRows = block->numOfRows;
|
resultData->numOfRows = block->numOfRows;
|
||||||
|
udfTrace("block:%p, processing completed, rows:%d, cols:%d,", block, block->numOfRows, block->numOfCols);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue