diff --git a/inc/bench.h b/inc/bench.h index 248a2e8f..85e45aea 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; + uint32_t scalingFactor; tools_cJSON * values; // fun diff --git a/src/benchData.c b/src/benchData.c index b3fd211b..df2064f6 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 162db5a2..035d7829 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; + uint32_t scalingFactor = 1; int32_t length = 4; // fun type uint8_t funType = FUNTYPE_NONE; @@ -241,17 +244,41 @@ 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; + } + + 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; + } + } + // gen tools_cJSON *dataGen = tools_cJSON_GetObjectItem(column, "gen"); if (tools_cJSON_IsString(dataGen)) { @@ -325,6 +352,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 +426,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; int32_t length = 4; tools_cJSON *tagObj = tools_cJSON_GetArrayItem(tags, k); if (!tools_cJSON_IsObject(tagObj)) { @@ -439,15 +472,39 @@ 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; + } + + double valueRange = maxInDbl - minInDbl; + tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(tagObj, "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 *dataValues = tools_cJSON_GetObjectItem(tagObj, "values"); @@ -478,6 +535,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: