From 7f9335d9a5ad73001969841eae0a7fbbbb3964c7 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 21 Jan 2022 10:27:54 +0800 Subject: [PATCH] [TD-11222]: Histogram function --- src/client/src/tscSQLParser.c | 3 +++ .../2-query/function_histogram.py | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 365e6426f9..e41141c286 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3463,6 +3463,9 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col int i = 0; while (bin) { intervals[i] = bin->valuedouble; + if (!cJSON_IsNumber(bin)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg22); + } if (i != 0 && intervals[i] <= intervals[i - 1]) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg22); } diff --git a/tests/develop-test/2-query/function_histogram.py b/tests/develop-test/2-query/function_histogram.py index 72c8ed7cb6..abdba47171 100644 --- a/tests/develop-test/2-query/function_histogram.py +++ b/tests/develop-test/2-query/function_histogram.py @@ -193,7 +193,7 @@ class TDTestCase: print("============== STEP 2: bin types ================== ") - #user_input + ## user_input ## #TINYINT tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5]", 0) from stb;') tdSql.checkRows(2); @@ -760,6 +760,30 @@ class TDTestCase: tdSql.checkData(1, 0, "(9.9-19.9]:2"); tdSql.checkData(2, 0, "(19.9-1e+14]:2"); + #ERROR CASE + tdSql.error('select histogram(col_double, "user_input", "[1,5,3,7]", 0) from stb;') + tdSql.error('select histogram(col_double, "user_input", "[1,-1,3,-3]", 0) from stb;') + tdSql.error('select histogram(col_double, "user_input", "[1.0,5.5,3.3,7.7]", 0) from stb;') + tdSql.error('select histogram(col_double, "user_input", "[1,1,1]", 0) from stb;') + tdSql.error('select histogram(col_double, "user_input", "[false,3,5]", 0) from stb;') + tdSql.error('select histogram(col_double, "user_input", "[true,3,5]", 0) from stb;') + + + ## user_input ## + #TINYINT + tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5]", 0) from stb;') + tdSql.checkRows(2); + tdSql.checkData(0, 0, "(1-3]:2"); + tdSql.checkData(1, 0, "(3-5]:2"); + tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5]", 0) from ctb;') + tdSql.checkRows(2); + tdSql.checkData(0, 0, "(1-3]:2"); + tdSql.checkData(1, 0, "(3-5]:2"); + tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5]", 0) from tb;') + tdSql.checkRows(2); + tdSql.checkData(0, 0, "(1-3]:2"); + tdSql.checkData(1, 0, "(3-5]:2"); + return tdSql.execute('drop database db') def stop(self): -- GitLab