From afa6301e32e631fc7f2f2f91f07e17000135f33d Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 27 Feb 2025 14:32:05 +0800 Subject: [PATCH] feat:support decimal in raw block --- source/client/src/clientImpl.c | 10 ++------- source/libs/parser/src/parInsertUtil.c | 28 +++++++++++++++++++++++--- utils/test/c/write_raw_block_test.c | 4 ++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 22b5d2f705..abf6d28959 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -2452,14 +2452,8 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, bool convertUcs4) { uint64_t groupId = *(uint64_t*)p; p += sizeof(uint64_t); - // check fields - for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { - int8_t type = *(int8_t*)p; - p += sizeof(int8_t); - - int32_t bytes = *(int32_t*)p; - p += sizeof(int32_t); - } + // type+bytes + p += (sizeof(int32_t) + sizeof(int8_t)) * pResultInfo->numOfCols; int32_t* colLength = (int32_t*)p; p += sizeof(int32_t) * pResultInfo->numOfCols; diff --git a/source/libs/parser/src/parInsertUtil.c b/source/libs/parser/src/parInsertUtil.c index 97b6c10eb4..5a6463b04e 100644 --- a/source/libs/parser/src/parInsertUtil.c +++ b/source/libs/parser/src/parInsertUtil.c @@ -894,13 +894,32 @@ static bool findFileds(SSchema* pSchema, TAOS_FIELD* fields, int numFields) { return false; } -int32_t checkSchema(SSchema* pColSchema, int8_t* fields, char* errstr, int32_t errstrLen) { +int32_t checkSchema(SSchema* pColSchema, SSchemaExt* pColExtSchema, int8_t* fields, char* errstr, int32_t errstrLen) { if (*fields != pColSchema->type) { if (errstr != NULL) snprintf(errstr, errstrLen, "column type not equal, name:%s, schema type:%s, data type:%s", pColSchema->name, tDataTypes[pColSchema->type].name, tDataTypes[*fields].name); return TSDB_CODE_INVALID_PARA; } + + if (IS_DECIMAL_TYPE(pColSchema->type)) { + uint8_t precision = 0, scale = 0; + decimalFromTypeMod(pColExtSchema->typeMod, &precision, &scale); + uint8_t precisionData = 0, scaleData = 0; + int32_t bytes = *(int32_t*)(fields + sizeof(int8_t)); + extractDecimalTypeInfoFromBytes(&bytes, &precisionData, &scaleData); + if (precision != precisionData || scale != scaleData) { + if (errstr != NULL) + snprintf(errstr, errstrLen, + "column decimal type not equal, name:%s, schema type:%s, precision:%d, scale:%d, data type:%s, " + "precision:%d, scale:%d", + pColSchema->name, tDataTypes[pColSchema->type].name, precision, scale, tDataTypes[*fields].name, + precisionData, scaleData); + return TSDB_CODE_INVALID_PARA; + } + return 0; + } + if (IS_VAR_DATA_TYPE(pColSchema->type) && *(int32_t*)(fields + sizeof(int8_t)) > pColSchema->bytes) { if (errstr != NULL) snprintf(errstr, errstrLen, @@ -922,7 +941,7 @@ int32_t checkSchema(SSchema* pColSchema, int8_t* fields, char* errstr, int32_t e } #define PRCESS_DATA(i, j) \ - ret = checkSchema(pColSchema, fields, errstr, errstrLen); \ + ret = checkSchema(pColSchema, pColExtSchema, fields, errstr, errstrLen); \ if (ret != 0) { \ goto end; \ } \ @@ -1021,7 +1040,8 @@ int rawBlockBindData(SQuery* query, STableMeta* pTableMeta, void* data, SVCreate char* pStart = p; - SSchema* pSchema = getTableColumnSchema(pTableCxt->pMeta); + SSchema* pSchema = getTableColumnSchema(pTableCxt->pMeta); + SSchemaExt* pExtSchemas = getTableColumnExtSchema(pTableCxt->pMeta); SBoundColInfo* boundInfo = &pTableCxt->boundColsInfo; if (tFields != NULL && numFields != numOfCols) { @@ -1035,12 +1055,14 @@ int rawBlockBindData(SQuery* query, STableMeta* pTableMeta, void* data, SVCreate int32_t len = TMIN(numOfCols, boundInfo->numOfBound); for (int j = 0; j < len; j++) { SSchema* pColSchema = &pSchema[j]; + SSchemaExt* pColExtSchema = &pExtSchemas[j]; PRCESS_DATA(j, j) } } else { for (int i = 0; i < numFields; i++) { for (int j = 0; j < boundInfo->numOfBound; j++) { SSchema* pColSchema = &pSchema[j]; + SSchemaExt* pColExtSchema = &pExtSchemas[j]; char* fieldName = NULL; if (raw) { fieldName = ((SSchemaWrapper*)tFields)->pSchema[i].name; diff --git a/utils/test/c/write_raw_block_test.c b/utils/test/c/write_raw_block_test.c index ae4a606e6e..590e9143fc 100644 --- a/utils/test/c/write_raw_block_test.c +++ b/utils/test/c/write_raw_block_test.c @@ -62,12 +62,12 @@ void init_env() { action("use db_raw"); action( - "CREATE STABLE `meters` (`ts` TIMESTAMP, `current` INT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, " + "CREATE STABLE `meters` (`ts` TIMESTAMP, `current` INT, `voltage` INT, `phase` FLOAT, data decimal(4,2)) TAGS (`groupid` INT, " "`location` VARCHAR(16))"); action("create table d0 using meters tags(1, 'San Francisco')"); action("create table d1 using meters tags(2, 'San Francisco')"); action("create table d2 using meters tags(3, 'San Francisco')"); - action("insert into d0 (ts, current) values (now, 120)"); + action("insert into d0 (ts, current, data) values (now, 120, 2.32)"); action("create table ntba(ts timestamp, addr binary(32))"); action("create table ntbb(ts timestamp, addr binary(8))");