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

Merge pull request #6547 from taosdata/feature/td-4735

[TD-4735]<feature>:support select last_row from subquery
......@@ -2150,7 +2150,10 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT
}
static void updateLastScanOrderIfNeeded(SQueryInfo* pQueryInfo) {
if (pQueryInfo->sessionWindow.gap > 0 || tscGroupbyColumn(pQueryInfo)) {
if (pQueryInfo->sessionWindow.gap > 0 ||
pQueryInfo->stateWindow ||
taosArrayGetSize(pQueryInfo->pUpstream) > 0 ||
tscGroupbyColumn(pQueryInfo)) {
size_t numOfExpr = tscNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < numOfExpr; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
......@@ -2410,7 +2413,9 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
// NOTE: has time range condition or normal column filter condition, the last_row query will be transferred to last query
SConvertFunc cvtFunc = {.originFuncId = functionId, .execFuncId = functionId};
if (functionId == TSDB_FUNC_LAST_ROW && ((!TSWINDOW_IS_EQUAL(pQueryInfo->window, TSWINDOW_INITIALIZER)) || (hasNormalColumnFilter(pQueryInfo)))) {
if (functionId == TSDB_FUNC_LAST_ROW && ((!TSWINDOW_IS_EQUAL(pQueryInfo->window, TSWINDOW_INITIALIZER)) ||
(hasNormalColumnFilter(pQueryInfo)) ||
taosArrayGetSize(pQueryInfo->pUpstream)>0)) {
cvtFunc.execFuncId = TSDB_FUNC_LAST;
}
......@@ -7899,6 +7904,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo, tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) {
return code;
}
updateLastScanOrderIfNeeded(pQueryInfo);
} else {
pQueryInfo->command = TSDB_SQL_SELECT;
......
......@@ -70,4 +70,17 @@ sleep 100
run general/parser/lastrow_query.sim
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
print =================== last_row + nested query
sql use $db
sql create table lr_nested(ts timestamp, f int)
sql insert into lr_nested values(now, 1)
sql insert into lr_nested values(now+1s, null)
sql select last_row(*) from (select * from lr_nested)
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册