feat:support decimal in raw block

This commit is contained in:
wangmm0220 2025-02-27 14:32:05 +08:00 committed by wangjiaming0909
parent e42d0e118c
commit afa6301e32
3 changed files with 29 additions and 13 deletions

View File

@ -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;

View File

@ -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; \
} \
@ -1022,6 +1041,7 @@ int rawBlockBindData(SQuery* query, STableMeta* pTableMeta, void* data, SVCreate
char* pStart = p;
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;

View File

@ -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))");