fix(query)[TS-5878]: correct column name for SELECT * FROM subquery
Fix issue where column names were not correctly copied when using SELECT * FROM subqueries.
This commit is contained in:
parent
981960e8a2
commit
57ea2dcbad
|
@ -1364,7 +1364,7 @@ static int32_t setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SCo
|
||||||
tstrncpy(pCol->node.aliasName, pExpr->aliasName, TSDB_COL_NAME_LEN);
|
tstrncpy(pCol->node.aliasName, pExpr->aliasName, TSDB_COL_NAME_LEN);
|
||||||
}
|
}
|
||||||
if ('\0' == pCol->node.userAlias[0]) {
|
if ('\0' == pCol->node.userAlias[0]) {
|
||||||
tstrncpy(pCol->node.userAlias, pExpr->aliasName, TSDB_COL_NAME_LEN);
|
tstrncpy(pCol->node.userAlias, pExpr->userAlias, TSDB_COL_NAME_LEN);
|
||||||
}
|
}
|
||||||
pCol->node.resType = pExpr->resType;
|
pCol->node.resType = pExpr->resType;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -22,6 +22,8 @@ from frame.autogen import *
|
||||||
|
|
||||||
|
|
||||||
class TDTestCase(TBase):
|
class TDTestCase(TBase):
|
||||||
|
clientCfgDict = { "keepColumnName": 1 }
|
||||||
|
updatecfgDict = { "clientCfg": clientCfgDict }
|
||||||
|
|
||||||
def ts_30189(self):
|
def ts_30189(self):
|
||||||
tdLog.info("create database ts_30189")
|
tdLog.info("create database ts_30189")
|
||||||
|
@ -144,6 +146,40 @@ class TDTestCase(TBase):
|
||||||
tdSql.checkRows(1)
|
tdSql.checkRows(1)
|
||||||
tdSql.checkData(0, 0, 2)
|
tdSql.checkData(0, 0, 2)
|
||||||
|
|
||||||
|
def ts_5878(self):
|
||||||
|
# prepare data
|
||||||
|
tdLog.info("create database ts_5878")
|
||||||
|
tdSql.execute("create database ts_5878")
|
||||||
|
tdSql.execute("use ts_5878")
|
||||||
|
sqls = [
|
||||||
|
"CREATE STABLE meters (ts timestamp, c1 int) TAGS (gid int)",
|
||||||
|
"CREATE TABLE d0 USING meters (gid) TAGS (0)",
|
||||||
|
"CREATE TABLE d1 USING meters (gid) TAGS (1)",
|
||||||
|
"CREATE TABLE d2 USING meters (gid) TAGS (2)",
|
||||||
|
"INSERT INTO d0 VALUES ('2025-01-01 00:00:00', 0)",
|
||||||
|
"INSERT INTO d1 VALUES ('2025-01-01 00:01:00', 1)",
|
||||||
|
"INSERT INTO d2 VALUES ('2025-01-01 00:02:00', 2)"
|
||||||
|
]
|
||||||
|
tdSql.executes(sqls)
|
||||||
|
# check column name in query result
|
||||||
|
sql1 = "SELECT * FROM (SELECT LAST_ROW(ts) FROM d1)"
|
||||||
|
cols = ["ts"]
|
||||||
|
rows = [["2025-01-01 00:01:00"]]
|
||||||
|
colNames = tdSql.getColNameList(sql1)
|
||||||
|
tdSql.checkColNameList(colNames, cols)
|
||||||
|
tdSql.checkDataMem(sql1, rows)
|
||||||
|
|
||||||
|
sql2 = "SELECT * FROM (SELECT LAST(ts) FROM meters PARTITION BY tbname) ORDER BY 1"
|
||||||
|
cols = ["ts"]
|
||||||
|
rows = [
|
||||||
|
["2025-01-01 00:00:00"],
|
||||||
|
["2025-01-01 00:01:00"],
|
||||||
|
["2025-01-01 00:02:00"],
|
||||||
|
]
|
||||||
|
colNames = tdSql.getColNameList(sql2)
|
||||||
|
tdSql.checkColNameList(colNames, cols)
|
||||||
|
tdSql.checkDataMem(sql2, rows)
|
||||||
|
|
||||||
# run
|
# run
|
||||||
def run(self):
|
def run(self):
|
||||||
tdLog.debug(f"start to excute {__file__}")
|
tdLog.debug(f"start to excute {__file__}")
|
||||||
|
@ -154,6 +190,9 @@ class TDTestCase(TBase):
|
||||||
# TS-5443
|
# TS-5443
|
||||||
self.ts_5443()
|
self.ts_5443()
|
||||||
|
|
||||||
|
# TS-5878
|
||||||
|
self.ts_5878()
|
||||||
|
|
||||||
tdLog.success(f"{__file__} successfully executed")
|
tdLog.success(f"{__file__} successfully executed")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue