From b86f416645733dc8f8c9c8924ddb0395d019a64d Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 28 Aug 2024 18:00:40 +0800 Subject: [PATCH] feat:[TD-31242]add new interface taos_get_column_data_null to get if raw data is null --- include/client/taos.h | 2 +- source/client/src/clientMain.c | 11 +++++++---- utils/test/c/tmq_multi_thread_test.c | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/client/taos.h b/include/client/taos.h index a3d35104e1..55b24c8721 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -210,12 +210,12 @@ DLL_EXPORT int taos_select_db(TAOS *taos, const char *db); DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields); DLL_EXPORT void taos_stop_query(TAOS_RES *res); DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col); +DLL_EXPORT int taos_is_null_by_column(TAOS_RES *res, int columnIndex, bool result[], int *rows); DLL_EXPORT bool taos_is_update_query(TAOS_RES *res); DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); DLL_EXPORT int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows); DLL_EXPORT int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData); DLL_EXPORT int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex); -DLL_EXPORT int taos_get_column_data_null(TAOS_RES *res, int columnIndex, bool result[], int rows); DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql); DLL_EXPORT void taos_reset_current_db(TAOS *taos); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index ab4d1837ea..9b336d27f2 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -859,8 +859,8 @@ int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { return pResInfo->pCol[columnIndex].offset; } -int taos_get_column_data_null(TAOS_RES *res, int columnIndex, bool result[], int rows){ - if (res == NULL || result == NULL || rows <= 0 || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) { +int taos_is_null_by_column(TAOS_RES *res, int columnIndex, bool result[], int *rows){ + if (res == NULL || result == NULL || *rows <= 0 || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) { return TSDB_CODE_INVALID_PARA; } @@ -873,8 +873,11 @@ int taos_get_column_data_null(TAOS_RES *res, int columnIndex, bool result[], int TAOS_FIELD *pField = &pResInfo->userFields[columnIndex]; SResultColumn *pCol = &pResInfo->pCol[columnIndex]; + if (*rows > pResInfo->numOfRows){ + *rows = pResInfo->numOfRows; + } if (IS_VAR_DATA_TYPE(pField->type)) { - for(int i = 0; i < rows && i < pResInfo->numOfRows; i++){ + for(int i = 0; i < *rows; i++){ if(pCol->offset[i] == -1){ result[i] = true; }else{ @@ -882,7 +885,7 @@ int taos_get_column_data_null(TAOS_RES *res, int columnIndex, bool result[], int } } }else{ - for(int i = 0; i < rows && i < pResInfo->numOfRows; i++){ + for(int i = 0; i < *rows; i++){ if (colDataIsNull_f(pCol->nullbitmap, i)){ result[i] = true; }else{ diff --git a/utils/test/c/tmq_multi_thread_test.c b/utils/test/c/tmq_multi_thread_test.c index c34cd43716..0b6117c89b 100644 --- a/utils/test/c/tmq_multi_thread_test.c +++ b/utils/test/c/tmq_multi_thread_test.c @@ -69,7 +69,7 @@ void* consumeThreadFunc(void* param) { } int64_t end = taosGetTimestampUs(); bool* isNULL = taosMemoryCalloc(rows, sizeof(bool)); - int code = taos_get_column_data_null(pRes, i, isNULL, rows); + int code = taos_is_null_by_column(pRes, i, isNULL, &rows); printf("taos_fetch_raw_block gourp:%s total rows:%d cost %"PRId64" us, code:%d\n", groupId, totalRows, end - start, code); }