提交 b62d3759 编写于 作者: wmmhello's avatar wmmhello

fix error in subquery order by ts

上级 a7920d00
......@@ -2696,6 +2696,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const char* msg28 = "the second paramter of diff should be 0 or 1";
const char* msg29 = "key timestamp column cannot be used to unique/mode/tail function";
const char* msg30 = "offset is out of range [0, 100]";
const char* msg31 = "state function can not be used in subquery";
switch (functionId) {
case TSDB_FUNC_COUNT: {
......@@ -2848,6 +2849,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
}
if ((functionId == TSDB_FUNC_STATE_COUNT || functionId == TSDB_FUNC_STATE_DURATION) &&
pQueryInfo->pUpstream != NULL && taosArrayGetSize(pQueryInfo->pUpstream) > 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg31);
}
STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta);
// functions can not be applied to tags
......
......@@ -2631,7 +2631,7 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) {
tValuePair **tvp = pRes->res;
// user specify the order of output by sort the result according to timestamp
if (pCtx->param[2].i64 == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
if (pCtx->param[2].i64 == PRIMARYKEY_TIMESTAMP_COL_INDEX || pCtx->param[2].i64 == TSDB_RES_COL_ID) {
__compar_fn_t comparator = (pCtx->param[3].i64 == TSDB_ORDER_ASC) ? resAscComparFn : resDescComparFn;
qsort(tvp, (size_t)pResInfo->numOfRes, POINTER_BYTES, comparator);
} else /*if (pCtx->param[2].i64 > PRIMARYKEY_TIMESTAMP_COL_INDEX)*/ {
......@@ -5402,7 +5402,7 @@ static void unique_func_finalizer(SQLFunctionCtx *pCtx) {
}
SortSupporter support = {0};
// user specify the order of output by sort the result according to timestamp
if (pCtx->param[2].i64 == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
if (pCtx->param[2].i64 == PRIMARYKEY_TIMESTAMP_COL_INDEX || pCtx->param[2].i64 == TSDB_RES_COL_ID) {
support.dataOffset = 0;
support.comparFn = compareInt64Val;
} else{
......@@ -5701,7 +5701,7 @@ static void tail_func_finalizer(SQLFunctionCtx *pCtx) {
SortSupporter support = {0};
// user specify the order of output by sort the result according to timestamp
if (pCtx->param[2].i64 != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
if (pCtx->param[2].i64 != PRIMARYKEY_TIMESTAMP_COL_INDEX && pCtx->param[2].i64 != TSDB_RES_COL_ID) {
support.dataOffset = sizeof(int64_t);
support.comparFn = getComparFunc(type, 0);
taosqsort(data, (size_t)GET_RES_INFO(pCtx)->numOfRes, size, &support, sortCompareFn);
......
......@@ -32,7 +32,7 @@ class TDTestCase:
def run(self):
print("running {}".format(__file__))
tdSql.execute("drop database if exists statef")
tdSql.execute("create database if not exists statef")
tdSql.execute("create database if not exists statef PRECISION 'ns'")
tdSql.execute('use statef')
tdSql.execute('create table sstatef (ts timestamp, dbig bigint, dsmall smallint, dbool bool, dtiny tinyint unsigned, dfloat float, ddouble double, dnchar nchar(4093), dbinary binary(64), dtime timestamp) tags (tbinary nchar(4093), tint int)')
......@@ -221,12 +221,7 @@ class TDTestCase:
tdSql.query('select stateDuration(dtiny,ne,9.0,1s) from sstatef group by tbname having stateDuration(dtiny,ne,9.0,1s) > 0')
#subquery
tdSql.query('select stateDuration(dfloat,Ge,3.32323) from (select ts,dfloat from statef2)')
tdSql.checkRows(6)
tdSql.checkData(0, 2, 0)
tdSql.checkData(1, 2, 172798)
tdSql.checkData(2, 2, None)
tdSql.checkData(3, 2, -1)
tdSql.error('select stateDuration(dfloat,Ge,3.32323) from (select ts,dfloat from statef2)')
#union
tdSql.query('select stateCount(dfloat,Ge,3.32323) from statef1 union all select stateCount(dfloat,Ge,3.32323) from statef2')
......
......@@ -321,6 +321,20 @@ class TDTestCase:
tdSql.checkData(1, 0, "2022-01-01 08:00:07")
tdSql.checkData(1, 1, "试试")
tdSql.query('select tail(dbig, 3) from (select * from stail) order by ts')
tdSql.checkRows(3)
tdSql.checkData(0, 0, "2022-01-01 08:00:06")
tdSql.checkData(0, 1, None)
tdSql.checkData(1, 0, "2022-01-01 08:00:07")
tdSql.checkData(1, 1, 9)
tdSql.query('select tail(dbig, 3) from (select * from stail) order by ts desc')
tdSql.checkRows(3)
tdSql.checkData(0, 0, "2022-01-24 00:31:32")
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 0, "2022-01-01 08:00:07")
tdSql.checkData(1, 1, 9)
#union
tdSql.query('select tail(dtiny,2) from tail1 union all select tail(dtiny,2) from tail2')
tdSql.checkRows(4)
......
......@@ -256,6 +256,20 @@ class TDTestCase:
tdSql.query('select unique(num) from (select * from unique where voltage > 1)')
tdSql.checkRows(2)
tdSql.query('select unique(num) from (select * from unique) order by ts')
tdSql.checkRows(2)
tdSql.checkData(0, 0, "2021-10-15 00:00:01")
tdSql.checkData(0, 1, 2)
tdSql.checkData(1, 0, "2021-12-25 01:31:31")
tdSql.checkData(1, 1, 4)
tdSql.query('select unique(num) from (select * from unique) order by ts desc')
tdSql.checkRows(2)
tdSql.checkData(0, 0, "2021-12-25 01:31:31")
tdSql.checkData(0, 1, 4)
tdSql.checkData(1, 0, "2021-10-15 00:00:01")
tdSql.checkData(1, 1, 2)
#union
tdSql.query('select unique(voltage) from d002 union all select unique(voltage) from d003')
tdSql.checkRows(5)
......
......@@ -790,4 +790,5 @@
3,,script,./test.sh -f general/compute/scalar_str_concat_len.sim
3,,develop-test,python3 ./test.py -f 2-query/function_tail.py
2,,develop-test,python3 ./test.py -f 2-query/function_unique.py
1,,develop-test,python3 ./test.py -f 2-query/function_state.py
1,,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/demo.py
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册