Skip to content

Commit

Permalink
Merge pull request #841 from taosdata/fix/TS-5944
Browse files Browse the repository at this point in the history
fix/TS-5944 Avoid entering the higher precision processing logic of floating-point types in the range of int type [0,1)
  • Loading branch information
zitsen authored Jan 23, 2025
2 parents cde537a + 5a2fd5b commit 84c50c5
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 62 deletions.
69 changes: 37 additions & 32 deletions src/benchJsonOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,25 @@ 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;
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;
if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE) {
double valueRange = maxInDbl - minInDbl;
tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(column, "scalingFactor");
if (tools_cJSON_IsNumber(dataScalingFactor)) {
scalingFactor = dataScalingFactor->valueint;
if (1< scalingFactor && scalingFactor <= 1000000) {
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
} else {
scalingFactor = 1;
if (0 < valueRange && valueRange <= 1) {
scalingFactor = 1000;
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
}
}

Expand Down Expand Up @@ -495,23 +497,26 @@ 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 = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
} else {
if (0 < valueRange && valueRange <= 1) {
scalingFactor = 1000;
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;

if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE) {
double valueRange = maxInDbl - minInDbl;
tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(tagObj, "scalingFactor");
if (tools_cJSON_IsNumber(dataScalingFactor)) {
scalingFactor = dataScalingFactor->valueint;
if (1< scalingFactor && scalingFactor <= 1000000) {
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
} else {
scalingFactor = 1;
if (0 < valueRange && valueRange <= 1) {
scalingFactor = 1000;
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
}
}

Expand Down
42 changes: 32 additions & 10 deletions tests/taosbenchmark/json/taosc_insert_alltypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,38 @@
"use_sample_ts": "no",
"tags_file": "",
"partial_col_num": 999,
"columns": [{"type": "TIMESTAMP","max": 10, "min": 0},{"type": "INT","max": 10, "min": 0}, {"type": "BIGINT","max": 10, "min": 0}, {"type": "FLOAT","max": 10, "min": 0}, {"type": "DOUBLE","max": 10, "min": 0}, {"type": "SMALLINT","max": 10, "min": 0}, {"type": "TINYINT","max": 10, "min": 0}, {"type": "BOOL","max": 10, "min": 0}, {"type": "NCHAR","len": 29, "count":1,
"values": ["d1", "d2"]
}, {"type": "UINT","max": 10, "min": 0}, {"type": "UBIGINT","max": 10, "min": 0}, {"type": "UTINYINT","max": 10, "min": 0}, {"type": "USMALLINT","max": 10, "min": 0}, {"type": "BINARY", "len": 23, "count":1,
"values": ["b1","b2"]
}],
"tags": [{"type": "TIMESTAMP","max": 10, "min": 0},{"type": "INT","max": 10, "min": 0}, {"type": "BIGINT","max": 10, "min": 0}, {"type": "FLOAT","max": 10, "min": 0}, {"type": "DOUBLE","max": 10, "min": 0}, {"type": "SMALLINT","max": 10, "min": 0}, {"type": "TINYINT","max": 10, "min": 0}, {"type": "BOOL","max": 10, "min": 0}, {"type": "NCHAR","len": 17, "count":1,
"values": ["d1", "d2"]
}, {"type": "UINT","max": 10, "min": 0}, {"type": "UBIGINT","max": 10, "min": 0}, {"type": "UTINYINT","max": 10, "min": 0}, {"type": "USMALLINT","max": 10, "min": 0}, {"type": "BINARY", "len": 19, "count":1,
"values": ["b1","b2"]
}]
"columns": [
{"type": "TIMESTAMP","max": 10, "min": 0},
{"type": "INT","max": 1, "min": 0},
{"type": "BIGINT","max": 10, "min": 0},
{"type": "FLOAT","max": 10, "min": 0},
{"type": "DOUBLE","max": 10, "min": 0},
{"type": "SMALLINT","max": 10, "min": 0},
{"type": "TINYINT","max": 10, "min": 0},
{"type": "BOOL","max": 10, "min": 0},
{"type": "NCHAR","len": 29, "count":1, "values": ["d1", "d2"]},
{"type": "UINT","max": 10, "min": 0},
{"type": "UBIGINT","max": 10, "min": 0},
{"type": "UTINYINT","max": 10, "min": 0},
{"type": "USMALLINT","max": 10, "min": 0},
{"type": "BINARY", "len": 23, "count":1, "values": ["b1","b2"]}
],
"tags": [
{"type": "TIMESTAMP","max": 10, "min": 0},
{"type": "INT","max": 10, "min": 0},
{"type": "BIGINT","max": 10, "min": 0},
{"type": "FLOAT","max": 10, "min": 0},
{"type": "DOUBLE","max": 10, "min": 0},
{"type": "SMALLINT","max": 10, "min": 0},
{"type": "TINYINT","max": 10, "min": 0},
{"type": "BOOL","max": 10, "min": 0},
{"type": "NCHAR","len": 17, "count":1, "values": ["d1", "d2"]},
{"type": "UINT","max": 10, "min": 0},
{"type": "UBIGINT","max": 10, "min": 0},
{"type": "UTINYINT","max": 10, "min": 0},
{"type": "USMALLINT","max": 10, "min": 0},
{"type": "BINARY", "len": 19, "count":1, "values": ["b1","b2"]}
]
}]
}]
}
40 changes: 20 additions & 20 deletions tests/taosbenchmark/taosc_insert_alltypes_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,51 +106,51 @@ def run(self):
# binary/varchar diff in 2.x/3.x
# tdSql.checkData(28, 1, "BINARY")
tdSql.checkData(28, 2, 19)
tdSql.query("select count(*) from db.stb where c1 >= 0 and c1 <= 10")
tdSql.query("select count(*) from db.stb where c1 >= 0 and c1 < 1")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c2 >= 0 and c2 <= 10")
tdSql.query("select count(*) from db.stb where c2 >= 0 and c2 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c3 >= 0 and c3 <= 10")
tdSql.query("select count(*) from db.stb where c3 >= 0 and c3 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c4 >= 0 and c4 <= 10")
tdSql.query("select count(*) from db.stb where c4 >= 0 and c4 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c5 >= 0 and c5 <= 10")
tdSql.query("select count(*) from db.stb where c5 >= 0 and c5 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c6 >= 0 and c6 <= 10")
tdSql.query("select count(*) from db.stb where c6 >= 0 and c6 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c8 = 'd1' or c8 = 'd2'")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c9 >= 0 and c9 <= 10")
tdSql.query("select count(*) from db.stb where c9 >= 0 and c9 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c10 >= 0 and c10 <= 10")
tdSql.query("select count(*) from db.stb where c10 >= 0 and c10 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c11 >= 0 and c11 <= 10")
tdSql.query("select count(*) from db.stb where c11 >= 0 and c11 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c12 >= 0 and c12 <= 10")
tdSql.query("select count(*) from db.stb where c12 >= 0 and c12 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where c13 = 'b1' or c13 = 'b2'")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t1 >= 0 and t1 <= 10")
tdSql.query("select count(*) from db.stb where t1 >= 0 and t1 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t2 >= 0 and t2 <= 10")
tdSql.query("select count(*) from db.stb where t2 >= 0 and t2 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t3 >= 0 and t3 <= 10")
tdSql.query("select count(*) from db.stb where t3 >= 0 and t3 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t4 >= 0 and t4 <= 10")
tdSql.query("select count(*) from db.stb where t4 >= 0 and t4 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t5 >= 0 and t5 <= 10")
tdSql.query("select count(*) from db.stb where t5 >= 0 and t5 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t6 >= 0 and t6 <= 10")
tdSql.query("select count(*) from db.stb where t6 >= 0 and t6 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t8 = 'd1' or t8 = 'd2'")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t9 >= 0 and t9 <= 10")
tdSql.query("select count(*) from db.stb where t9 >= 0 and t9 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t10 >= 0 and t10 <= 10")
tdSql.query("select count(*) from db.stb where t10 >= 0 and t10 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t11 >= 0 and t11 <= 10")
tdSql.query("select count(*) from db.stb where t11 >= 0 and t11 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t12 >= 0 and t12 <= 10")
tdSql.query("select count(*) from db.stb where t12 >= 0 and t12 < 10")
tdSql.checkData(0, 0, 160)
tdSql.query("select count(*) from db.stb where t13 = 'b1' or t13 = 'b2'")
tdSql.checkData(0, 0, 160)
Expand Down

0 comments on commit 84c50c5

Please sign in to comment.