未验证 提交 be1eef79 编写于 作者: H Haojun Liao 提交者: GitHub

Merge pull request #9617 from taosdata/fix/TD-12614-2.4

[TD-12614]<fix>(query): Functions related to timeline should not support inner query group by tbname
...@@ -2673,6 +2673,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2673,6 +2673,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const char* msg14 = "third parameter algorithm must be 'default' or 't-digest'"; const char* msg14 = "third parameter algorithm must be 'default' or 't-digest'";
const char* msg15 = "parameter is out of range [1, 1000]"; const char* msg15 = "parameter is out of range [1, 1000]";
const char* msg16 = "elapsed duration should be greater than or equal to database precision"; const char* msg16 = "elapsed duration should be greater than or equal to database precision";
const char* msg17 = "elapsed/twa should not be used in nested query if inner query has group by clause";
switch (functionId) { switch (functionId) {
case TSDB_FUNC_COUNT: { case TSDB_FUNC_COUNT: {
...@@ -2797,6 +2798,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2797,6 +2798,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
} }
} }
//for timeline related aggregation function like elapsed and twa, groupby in subquery is not allowed
//as calculation result is meaningless by mixing different childtables(timelines) results.
if ((functionId == TSDB_FUNC_ELAPSED || functionId == TSDB_FUNC_TWA) && pQueryInfo->pUpstream != NULL) {
size_t numOfUpstreams = taosArrayGetSize(pQueryInfo->pUpstream);
for (int32_t i = 0; i < numOfUpstreams; ++i) {
SQueryInfo* pSub = taosArrayGetP(pQueryInfo->pUpstream, i);
if (pSub->groupbyExpr.numOfGroupCols > 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg17);
}
}
}
STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta); STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
from posixpath import split from posixpath import split
import sys import sys
import os import os
from util.log import * from util.log import *
from util.cases import * from util.cases import *
...@@ -24,7 +24,7 @@ class TDTestCase: ...@@ -24,7 +24,7 @@ class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__) tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql) tdSql.init(conn.cursor(), logSql)
self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record
self.num = 10 self.num = 10
...@@ -49,8 +49,8 @@ class TDTestCase: ...@@ -49,8 +49,8 @@ class TDTestCase:
''' '''
case1 <shenglian zhou>: [TD-12344] : fix session window for super table two stage query case1 <shenglian zhou>: [TD-12344] : fix session window for super table two stage query
''' '''
return return
def getBuildPath(self): def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__)) selfPath = os.path.dirname(os.path.realpath(__file__))
...@@ -75,13 +75,13 @@ class TDTestCase: ...@@ -75,13 +75,13 @@ class TDTestCase:
projPath = selfPath[:selfPath.find("community")] projPath = selfPath[:selfPath.find("community")]
else: else:
projPath = selfPath[:selfPath.find("tests")] projPath = selfPath[:selfPath.find("tests")]
cfgPath = projPath + "/sim/dnode1/cfg " cfgPath = projPath + "/sim/dnode1/cfg "
return cfgPath return cfgPath
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
tdSql.execute("create database if not exists testdb keep 36500;") tdSql.execute("create database if not exists testdb keep 36500;")
...@@ -95,9 +95,9 @@ class TDTestCase: ...@@ -95,9 +95,9 @@ class TDTestCase:
cfg_path = self.getcfgPath() cfg_path = self.getcfgPath()
print(cfg_path) print(cfg_path)
tdSql.query('select elapsed(ts,10s) from st where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1d) group by tbname;') # session not support super table tdSql.query('select elapsed(ts,10s) from st where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1d) group by tbname;') # session not support super table
tdSql.checkRows(10) tdSql.checkRows(10)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
###################################################################
# Copyright (c) 2021 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def caseDescription(self):
'''
case1<Ganlin Zhao>: [TD-12614] : Functions related to timeline should not support inner query group by tbname
'''
return
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record
self.num = 10
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def run(self):
print("running {}".format(__file__))
tdSql.execute("drop database if exists db")
tdSql.execute("create database if not exists db")
tdSql.execute('use db')
#Prepare data
tdSql.execute("create stable st (ts timestamp , id int , value double) tags(hostname binary(10) ,ind int);")
for i in range(self.num):
tdSql.execute("insert into tb%s using st tags('host_%s' , %d) values (%d , %d , %f );"%(str(i),str(i),i*10,self.ts+100*i,i*2,i+10.00))
tdSql.execute("insert into tb%s using st tags('host_%s' , %d) values (%d , %d , %f );"%(str(i),str(i),i*10,self.ts+200*i,i*2,i+10.00))
tdSql.execute("insert into tb%s using st tags('host_%s' , %d) values (%d , %d , %f );"%(str(i),str(i),i*10,self.ts+300*i,i*2,i+10.00))
tdSql.execute("insert into tb%s using st tags('host_%s' , %d) values (%d , %d , %f );"%(str(i),str(i),i*10,self.ts+10000*i,i*2,i+10.00))
#execute query
tdSql.error(' select elapsed(ts) from (select csum(value) from st group by tbname );')
tdSql.error(' select elapsed(ts) from (select diff(value) from st group by tbname );')
tdSql.error(' select twa(value) from (select csum(value) value from st group by tbname );')
tdSql.error(' select twa(value) from (select diff(value) value from st group by tbname );')
tdSql.execute('drop database db')
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
python3 ./test.py -f 2-query/ts_hidden_column.py python3 ./test.py -f 2-query/ts_hidden_column.py
python3 ./test.py -f 2-query/union-order.py python3 ./test.py -f 2-query/union-order.py
python3 ./test.py -f 2-query/session_two_stage.py python3 ./test.py -f 2-query/session_two_stage.py
python3 ./test.py -f 2-query/timeline_agg_func_groupby.py
python3 ./test.py -f 2-query/ts_2016.py python3 ./test.py -f 2-query/ts_2016.py
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册