From 8e977ea9909141018b4ac36374225db3ff456892 Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Tue, 2 Jul 2024 20:59:33 +0800 Subject: [PATCH 1/7] Fixed float number truncation in cjson library reading configuration item min --- inc/bench.h | 3 +++ src/benchData.c | 22 ++++++++++++++++++++++ src/benchJsonOpt.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/benchUtil.c | 2 +- 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/inc/bench.h b/inc/bench.h index 248a2e8f..2e5381aa 100644 --- a/inc/bench.h +++ b/inc/bench.h @@ -599,6 +599,9 @@ typedef struct SField { StmtData stmtData; int64_t max; int64_t min; + double maxInDbl; + double minInDbl; + uint8_t scalingFactor; tools_cJSON * values; // fun diff --git a/src/benchData.c b/src/benchData.c index 4da0f0ad..69a95f72 100644 --- a/src/benchData.c +++ b/src/benchData.c @@ -658,6 +658,17 @@ float tmpFloatImpl(Field *field, int i, int32_t angle, int32_t k) { + floatTmp / 1000000000) / 360); } } + + if (field->scalingFactor > 0) { + if (field->scalingFactor > 1) + floatTmp = floatTmp / field->scalingFactor; + + if (floatTmp > field->maxInDbl) + floatTmp = field->maxInDbl; + else if (floatTmp < field->minInDbl) + floatTmp = field->minInDbl; + } + return floatTmp; } @@ -674,6 +685,17 @@ double tmpDoubleImpl(Field *field, int32_t angle, int32_t k) { taosRandom() % 1000000 / 1000000.0); } } + + if (field->scalingFactor > 0) { + if (field->scalingFactor > 1) + doubleTmp = doubleTmp / field->scalingFactor; + + if (doubleTmp > field->maxInDbl) + doubleTmp = field->maxInDbl; + else if (doubleTmp < field->minInDbl) + doubleTmp = field->minInDbl; + } + return doubleTmp; } diff --git a/src/benchJsonOpt.c b/src/benchJsonOpt.c index 573c86b4..b4491460 100644 --- a/src/benchJsonOpt.c +++ b/src/benchJsonOpt.c @@ -198,6 +198,9 @@ static int getColumnAndTagTypeFromInsertJsonFile( int count = 1; int64_t max = RAND_MAX >> 1; int64_t min = 0; + double maxInDbl = max; + double minInDbl = min; + uint8_t scalingFactor = 1; int32_t length = 4; // fun type uint8_t funType = FUNTYPE_NONE; @@ -241,15 +244,32 @@ static int getColumnAndTagTypeFromInsertJsonFile( tools_cJSON *dataMax = tools_cJSON_GetObjectItem(column, "max"); if (tools_cJSON_IsNumber(dataMax)) { max = dataMax->valueint; + maxInDbl = dataMax->valuedouble; } else { max = convertDatatypeToDefaultMax(type); + maxInDbl = max; } tools_cJSON *dataMin = tools_cJSON_GetObjectItem(column, "min"); if (tools_cJSON_IsNumber(dataMin)) { min = dataMin->valueint; + minInDbl = dataMin->valuedouble; } else { min = convertDatatypeToDefaultMin(type); + minInDbl = min; + } + + tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(column, "scalingFactor"); + if (tools_cJSON_IsNumber(dataScalingFactor)) { + scalingFactor = dataScalingFactor->valueint; + if (scalingFactor > 1) { + max = maxInDbl * scalingFactor; + min = minInDbl * scalingFactor; + } else { + scalingFactor = 1; + } + } else { + scalingFactor = 1; } // gen @@ -325,6 +345,9 @@ static int getColumnAndTagTypeFromInsertJsonFile( col->sma = sma; col->max = max; col->min = min; + col->maxInDbl = maxInDbl; + col->minInDbl = minInDbl; + col->scalingFactor = scalingFactor; col->gen = gen; col->fillNull = fillNull; col->values = dataValues; @@ -396,6 +419,9 @@ static int getColumnAndTagTypeFromInsertJsonFile( int count = 1; int64_t max = RAND_MAX >> 1; int64_t min = 0; + double maxInDbl = max; + double minInDbl = min; + uint8_t scalingFactor = 1; int32_t length = 4; tools_cJSON *tagObj = tools_cJSON_GetArrayItem(tags, k); if (!tools_cJSON_IsObject(tagObj)) { @@ -439,15 +465,32 @@ static int getColumnAndTagTypeFromInsertJsonFile( tools_cJSON *dataMax = tools_cJSON_GetObjectItem(tagObj, "max"); if (tools_cJSON_IsNumber(dataMax)) { max = dataMax->valueint; + maxInDbl = dataMax->valuedouble; } else { max = convertDatatypeToDefaultMax(type); + maxInDbl = max; } tools_cJSON *dataMin = tools_cJSON_GetObjectItem(tagObj, "min"); if (tools_cJSON_IsNumber(dataMin)) { min = dataMin->valueint; + minInDbl = dataMin->valuedouble; } else { min = convertDatatypeToDefaultMin(type); + minInDbl = min; + } + + tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(tagObj, "scalingFactor"); + if (tools_cJSON_IsNumber(dataScalingFactor)) { + scalingFactor = dataScalingFactor->valueint; + if (scalingFactor > 1) { + max *= scalingFactor; + min *= scalingFactor; + } else { + scalingFactor = 1; + } + } else { + scalingFactor = 1; } tools_cJSON *dataValues = tools_cJSON_GetObjectItem(tagObj, "values"); @@ -478,6 +521,9 @@ static int getColumnAndTagTypeFromInsertJsonFile( } tag->max = max; tag->min = min; + tag->maxInDbl = maxInDbl; + tag->minInDbl = minInDbl; + tag->scalingFactor = scalingFactor; tag->values = dataValues; if (customName) { if (n >= 1) { diff --git a/src/benchUtil.c b/src/benchUtil.c index e860ef55..f7fb55dd 100644 --- a/src/benchUtil.c +++ b/src/benchUtil.c @@ -954,9 +954,9 @@ int64_t convertDatatypeToDefaultMax(uint8_t type) { ret = 65534; break; case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_DOUBLE: ret = RAND_MAX >> 1; break; case TSDB_DATA_TYPE_UINT: From e62bd406f6fc10384f97198c67d8dffcdd5585ba Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Tue, 2 Jul 2024 21:18:59 +0800 Subject: [PATCH 2/7] Fixed float number truncation in cjson library reading configuration item min --- inc/bench.h | 2 +- src/benchJsonOpt.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/bench.h b/inc/bench.h index 2e5381aa..85e45aea 100644 --- a/inc/bench.h +++ b/inc/bench.h @@ -601,7 +601,7 @@ typedef struct SField { int64_t min; double maxInDbl; double minInDbl; - uint8_t scalingFactor; + uint32_t scalingFactor; tools_cJSON * values; // fun diff --git a/src/benchJsonOpt.c b/src/benchJsonOpt.c index b4491460..68464138 100644 --- a/src/benchJsonOpt.c +++ b/src/benchJsonOpt.c @@ -200,7 +200,7 @@ static int getColumnAndTagTypeFromInsertJsonFile( int64_t min = 0; double maxInDbl = max; double minInDbl = min; - uint8_t scalingFactor = 1; + uint32_t scalingFactor = 1; int32_t length = 4; // fun type uint8_t funType = FUNTYPE_NONE; @@ -421,7 +421,7 @@ static int getColumnAndTagTypeFromInsertJsonFile( int64_t min = 0; double maxInDbl = max; double minInDbl = min; - uint8_t scalingFactor = 1; + uint32_t scalingFactor = 1; int32_t length = 4; tools_cJSON *tagObj = tools_cJSON_GetArrayItem(tags, k); if (!tools_cJSON_IsObject(tagObj)) { From a17814d4a9957676c82493425d3d3958998c122a Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Wed, 3 Jul 2024 09:29:30 +0800 Subject: [PATCH 3/7] Fixed float number truncation in cjson library reading configuration item min --- src/benchJsonOpt.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/benchJsonOpt.c b/src/benchJsonOpt.c index 68464138..f31d27ac 100644 --- a/src/benchJsonOpt.c +++ b/src/benchJsonOpt.c @@ -269,7 +269,14 @@ static int getColumnAndTagTypeFromInsertJsonFile( scalingFactor = 1; } } else { - scalingFactor = 1; + if (0 < (max - min) && (max - min) <= 1) { + scalingFactor = 1000; + max = maxInDbl * scalingFactor; + min = minInDbl * scalingFactor; + } else { + scalingFactor = 1; + } + } // gen @@ -490,7 +497,13 @@ static int getColumnAndTagTypeFromInsertJsonFile( scalingFactor = 1; } } else { - scalingFactor = 1; + if (0 < (max - min) && (max - min) <= 1) { + scalingFactor = 1000; + max = maxInDbl * scalingFactor; + min = minInDbl * scalingFactor; + } else { + scalingFactor = 1; + } } tools_cJSON *dataValues = tools_cJSON_GetObjectItem(tagObj, "values"); From a5ad6927a433be883e041d47041980ff33defdf4 Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Wed, 3 Jul 2024 14:24:22 +0800 Subject: [PATCH 4/7] For the float value in json file, the random number granularity is further refined --- src/benchJsonOpt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/benchJsonOpt.c b/src/benchJsonOpt.c index f31d27ac..9558fb0e 100644 --- a/src/benchJsonOpt.c +++ b/src/benchJsonOpt.c @@ -259,6 +259,7 @@ static int getColumnAndTagTypeFromInsertJsonFile( minInDbl = min; } + double valueRange = maxInDbl - minInDbl; tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(column, "scalingFactor"); if (tools_cJSON_IsNumber(dataScalingFactor)) { scalingFactor = dataScalingFactor->valueint; @@ -269,14 +270,13 @@ static int getColumnAndTagTypeFromInsertJsonFile( scalingFactor = 1; } } else { - if (0 < (max - min) && (max - min) <= 1) { + if (0 < valueRange && valueRange <= 1) { scalingFactor = 1000; max = maxInDbl * scalingFactor; min = minInDbl * scalingFactor; } else { scalingFactor = 1; } - } // gen @@ -487,17 +487,18 @@ static int getColumnAndTagTypeFromInsertJsonFile( minInDbl = min; } + double valueRange = maxInDbl - minInDbl; tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(tagObj, "scalingFactor"); if (tools_cJSON_IsNumber(dataScalingFactor)) { scalingFactor = dataScalingFactor->valueint; if (scalingFactor > 1) { - max *= scalingFactor; - min *= scalingFactor; + max = maxInDbl * scalingFactor; + min = minInDbl * scalingFactor; } else { scalingFactor = 1; } } else { - if (0 < (max - min) && (max - min) <= 1) { + if (0 < valueRange && valueRange <= 1) { scalingFactor = 1000; max = maxInDbl * scalingFactor; min = minInDbl * scalingFactor; From dc7f675767e4be925431c2830f2e87f0d7e6f4a0 Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Wed, 3 Jul 2024 15:58:05 +0800 Subject: [PATCH 5/7] Fixed float number truncation in cjson library reading configuration item min --- src/benchJsonOpt.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/benchJsonOpt.c b/src/benchJsonOpt.c index 9558fb0e..345ec0e3 100644 --- a/src/benchJsonOpt.c +++ b/src/benchJsonOpt.c @@ -260,25 +260,25 @@ static int getColumnAndTagTypeFromInsertJsonFile( } double valueRange = maxInDbl - minInDbl; - tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(column, "scalingFactor"); - if (tools_cJSON_IsNumber(dataScalingFactor)) { - scalingFactor = dataScalingFactor->valueint; - if (scalingFactor > 1) { - max = maxInDbl * scalingFactor; - min = minInDbl * scalingFactor; - } else { - scalingFactor = 1; - } - } else { - if (0 < valueRange && valueRange <= 1) { - scalingFactor = 1000; - max = maxInDbl * scalingFactor; - min = minInDbl * scalingFactor; - } else { - scalingFactor = 1; - } - } - + tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(column, "scalingFactor"); + if (tools_cJSON_IsNumber(dataScalingFactor)) { + scalingFactor = dataScalingFactor->valueint; + if (scalingFactor > 1) { + max = maxInDbl * scalingFactor; + min = minInDbl * scalingFactor; + } else { + scalingFactor = 1; + } + } else { + if (0 < valueRange && valueRange <= 1) { + scalingFactor = 1000; + max = maxInDbl * scalingFactor; + min = minInDbl * scalingFactor; + } else { + scalingFactor = 1; + } + } + // gen tools_cJSON *dataGen = tools_cJSON_GetObjectItem(column, "gen"); if (tools_cJSON_IsString(dataGen)) { From 5864be625f734aa2dc9d01e4e3e65eb81b8a0948 Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Wed, 3 Jul 2024 17:44:45 +0800 Subject: [PATCH 6/7] Remove the ^M character at the end of line of code to trigger CI execution --- src/benchJsonOpt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/benchJsonOpt.c b/src/benchJsonOpt.c index 345ec0e3..bac2c788 100644 --- a/src/benchJsonOpt.c +++ b/src/benchJsonOpt.c @@ -198,9 +198,9 @@ static int getColumnAndTagTypeFromInsertJsonFile( int count = 1; int64_t max = RAND_MAX >> 1; int64_t min = 0; - double maxInDbl = max; - double minInDbl = min; - uint32_t scalingFactor = 1; + double maxInDbl = max; + double minInDbl = min; + uint32_t scalingFactor = 1; int32_t length = 4; // fun type uint8_t funType = FUNTYPE_NONE; From 58b66c852f810963160b37b2150c767ec157d401 Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Wed, 3 Jul 2024 19:08:44 +0800 Subject: [PATCH 7/7] Remove the ^M character at the end of line of code to trigger CI execution --- src/benchJsonOpt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/benchJsonOpt.c b/src/benchJsonOpt.c index bac2c788..5125bf60 100644 --- a/src/benchJsonOpt.c +++ b/src/benchJsonOpt.c @@ -352,9 +352,9 @@ static int getColumnAndTagTypeFromInsertJsonFile( col->sma = sma; col->max = max; col->min = min; - col->maxInDbl = maxInDbl; - col->minInDbl = minInDbl; - col->scalingFactor = scalingFactor; + col->maxInDbl = maxInDbl; + col->minInDbl = minInDbl; + col->scalingFactor = scalingFactor; col->gen = gen; col->fillNull = fillNull; col->values = dataValues;