提交 f05eff10 编写于 作者: G Ganlin Zhao

fix(query): Disable Histogram function usage with time window query

TD-14952
TD-14955
TD-14744
Td-14953
上级 358046ca
...@@ -8528,7 +8528,8 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* ...@@ -8528,7 +8528,8 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
const char* msg4 = "retrieve tags not compatible with group by or interval query"; const char* msg4 = "retrieve tags not compatible with group by or interval query";
const char* msg5 = "functions can not be mixed up"; const char* msg5 = "functions can not be mixed up";
const char* msg6 = "TWA/Diff/Derivative/Irate/CSum/MAvg/Elapsed/stateCount/stateDuration only support group by tbname"; const char* msg6 = "TWA/Diff/Derivative/Irate/CSum/MAvg/Elapsed/stateCount/stateDuration only support group by tbname";
const char* msg7 = "unique/state function does not supportted in state window query"; const char* msg7 = "unique/state function not supported in state window query";
const char* msg8 = "histogram function not supported in time window query";
// only retrieve tags, group by is not supportted // only retrieve tags, group by is not supportted
if (tscQueryTags(pQueryInfo)) { if (tscQueryTags(pQueryInfo)) {
...@@ -8542,10 +8543,19 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* ...@@ -8542,10 +8543,19 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
if (tscIsProjectionQuery(pQueryInfo) && tscIsSessionWindowQuery(pQueryInfo)) { if (tscIsProjectionQuery(pQueryInfo) && tscIsSessionWindowQuery(pQueryInfo)) {
return invalidOperationMsg(msg, msg3); return invalidOperationMsg(msg, msg3);
} }
size_t numOfExprs = tscNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < numOfExprs; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
if ((isTimeWindowQuery(pQueryInfo) || pQueryInfo->stateWindow) && pExpr->base.functionId == TSDB_FUNC_HISTOGRAM) {
return invalidOperationMsg(msg, msg8);
}
}
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) {
// check if all the tags prj columns belongs to the group by columns // check if all the tags prj columns belongs to the group by columns
if (onlyTagPrjFunction(pQueryInfo) && allTagPrjInGroupby(pQueryInfo)) { if (onlyTagPrjFunction(pQueryInfo) && allTagPrjInGroupby(pQueryInfo)) {
...@@ -8589,7 +8599,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* ...@@ -8589,7 +8599,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
} }
} }
if (pQueryInfo->stateWindow && (f == TSDB_FUNC_UNIQUE || f == TSDB_FUNC_STATE_COUNT || f == TSDB_FUNC_STATE_DURATION)){ if (pQueryInfo->stateWindow && (f == TSDB_FUNC_UNIQUE || f == TSDB_FUNC_STATE_COUNT || f == TSDB_FUNC_STATE_DURATION)) {
return invalidOperationMsg(msg, msg7); return invalidOperationMsg(msg, msg7);
} }
......
...@@ -2535,21 +2535,21 @@ class TDTestCase: ...@@ -2535,21 +2535,21 @@ class TDTestCase:
tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}');
#select session #select session
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1w);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1w);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1d);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1d);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1h);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1h);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1m);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1m);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
#tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1s);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1s);')
#tdSql.checkRows(16) #tdSql.checkRows(16)
...@@ -2602,100 +2602,100 @@ class TDTestCase: ...@@ -2602,100 +2602,100 @@ class TDTestCase:
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_nchar);') tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_nchar);')
#select interval/sliding/fill #select interval/sliding/fill
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1y);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1y);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1n);')
tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1w);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1n);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1d);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1w);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1h);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1d);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1s);')
tdSql.checkRows(16)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1a);')
tdSql.checkRows(16)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1w) sliding(1w);')
tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1d) sliding(1d);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1h);')
tdSql.checkRows(1) #tdSql.checkRows(1)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1h) sliding(1h);') #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1s);')
tdSql.checkRows(1) #tdSql.checkRows(16)
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1s) sliding(1s);') #tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkRows(16) #tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); #tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); #tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); #tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1a);')
tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); #tdSql.checkRows(16)
tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); #tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); #tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1w and col_timestamp < now + 1w interval(1w) fill(NULL);') #tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1d and col_timestamp < now + 1d interval(1d) fill(None);') #tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1h and col_timestamp < now + 1h interval(1h) fill(Prev);') #tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1m and col_timestamp < now + 1m interval(1m) fill(Next);') #tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1s and col_timestamp < now + 1s interval(1s) fill(Linear);') #tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1a and col_timestamp < now + 1a interval(1a) fill(Value, 1);') #tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1w) sliding(1w);')
#tdSql.checkRows(1)
#tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
#tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1d) sliding(1d);')
#tdSql.checkRows(1)
#tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
#tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1h) sliding(1h);')
#tdSql.checkRows(1)
#tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}');
#tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1s) sliding(1s);')
#tdSql.checkRows(16)
#tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}');
#tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}');
#tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1w and col_timestamp < now + 1w interval(1w) fill(NULL);')
#tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1d and col_timestamp < now + 1d interval(1d) fill(None);')
#tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1h and col_timestamp < now + 1h interval(1h) fill(Prev);')
#tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1m and col_timestamp < now + 1m interval(1m) fill(Next);')
#tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1s and col_timestamp < now + 1s interval(1s) fill(Linear);')
#tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1a and col_timestamp < now + 1a interval(1a) fill(Value, 1);')
#select group by #select group by
tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_tinyint;') tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_tinyint;')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册