fix: order by same name col
This commit is contained in:
parent
81c83b67d4
commit
00fd4f21ca
|
@ -4515,6 +4515,9 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
|
||||||
FOREACH(pProject, pProjectionList) {
|
FOREACH(pProject, pProjectionList) {
|
||||||
SExprNode* pExpr = (SExprNode*)pProject;
|
SExprNode* pExpr = (SExprNode*)pProject;
|
||||||
if (0 == strcmp(((SColumnRefNode*)*pNode)->colName, pExpr->userAlias) && nodeType(*pNode) == nodeType(pProject)) {
|
if (0 == strcmp(((SColumnRefNode*)*pNode)->colName, pExpr->userAlias) && nodeType(*pNode) == nodeType(pProject)) {
|
||||||
|
if (QUERY_NODE_COLUMN == nodeType(pProject) && !nodesEqualNode(*pNode, pProject)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
SNode* pNew = nodesCloneNode(pProject);
|
SNode* pNew = nodesCloneNode(pProject);
|
||||||
if (NULL == pNew) {
|
if (NULL == pNew) {
|
||||||
pCxt->pTranslateCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
pCxt->pTranslateCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
|
@ -315,6 +315,39 @@ class TDTestCase:
|
||||||
|
|
||||||
tdSql.no_error('select c1 as name from (select c1, c2 as name from st) order by name')
|
tdSql.no_error('select c1 as name from (select c1, c2 as name from st) order by name')
|
||||||
|
|
||||||
|
def queryOrderBySameCol(self):
|
||||||
|
tdLog.info("query OrderBy same col ....")
|
||||||
|
tdSql.execute(f"create stable sta (ts timestamp, col1 int) tags(t1 int);")
|
||||||
|
tdSql.execute(f"create table tba1 using sta tags(1);")
|
||||||
|
tdSql.execute(f"create table tba2 using sta tags(2);")
|
||||||
|
|
||||||
|
pd = datetime.datetime.now()
|
||||||
|
ts = int(datetime.datetime.timestamp(pd)*1000*1000)
|
||||||
|
tdSql.execute(f"insert into tba1 values ({ts}, 1);")
|
||||||
|
tdSql.execute(f"insert into tba1 values ({ts+2}, 3);")
|
||||||
|
tdSql.execute(f"insert into tba1 values ({ts+3}, 4);")
|
||||||
|
tdSql.execute(f"insert into tba1 values ({ts+4}, 5);")
|
||||||
|
tdSql.execute(f"insert into tba2 values ({ts}, 2);")
|
||||||
|
tdSql.execute(f"insert into tba2 values ({ts+1}, 3);")
|
||||||
|
tdSql.execute(f"insert into tba2 values ({ts+3}, 5);")
|
||||||
|
tdSql.execute(f"insert into tba2 values ({ts+5}, 7);")
|
||||||
|
tdSql.query(f"select a.col1, b.col1 from sta a inner join sta b on a.ts = b.ts and a.ts < {ts+2} order by a.col1, b.col1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
tdSql.checkData(1, 0, 1)
|
||||||
|
tdSql.checkData(1, 1, 2)
|
||||||
|
tdSql.query(f"select a.col1, b.col1 from sta a inner join sta b on a.ts = b.ts and a.ts < {ts+2} order by a.col1, b.col1 desc;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.checkData(0, 1, 2)
|
||||||
|
tdSql.checkData(1, 0, 1)
|
||||||
|
tdSql.checkData(1, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query(f"select a.col1, b.col1 from sta a inner join sta b on a.ts = b.ts and a.ts < {ts+2} order by a.col1 desc, b.col1 desc;")
|
||||||
|
tdSql.checkData(1, 0, 2)
|
||||||
|
tdSql.checkData(1, 1, 2)
|
||||||
|
tdSql.checkData(2, 0, 2)
|
||||||
|
tdSql.checkData(2, 1, 1)
|
||||||
|
|
||||||
# run
|
# run
|
||||||
def run(self):
|
def run(self):
|
||||||
# prepare env
|
# prepare env
|
||||||
|
@ -332,6 +365,8 @@ class TDTestCase:
|
||||||
# td-28332
|
# td-28332
|
||||||
self.queryOrderByAmbiguousName()
|
self.queryOrderByAmbiguousName()
|
||||||
|
|
||||||
|
self.queryOrderBySameCol()
|
||||||
|
|
||||||
# stop
|
# stop
|
||||||
def stop(self):
|
def stop(self):
|
||||||
tdSql.close()
|
tdSql.close()
|
||||||
|
|
Loading…
Reference in New Issue