Merge pull request #6547 from taosdata/feature/td-4735
[TD-4735]<feature>:support select last_row from subquery
This commit is contained in:
commit
9dd96c1060
|
@ -2150,7 +2150,10 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateLastScanOrderIfNeeded(SQueryInfo* pQueryInfo) {
|
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);
|
size_t numOfExpr = tscNumOfExprs(pQueryInfo);
|
||||||
for (int32_t i = 0; i < numOfExpr; ++i) {
|
for (int32_t i = 0; i < numOfExpr; ++i) {
|
||||||
SExprInfo* pExpr = tscExprGet(pQueryInfo, 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
|
// 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};
|
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;
|
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) {
|
if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo, tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateLastScanOrderIfNeeded(pQueryInfo);
|
||||||
} else {
|
} else {
|
||||||
pQueryInfo->command = TSDB_SQL_SELECT;
|
pQueryInfo->command = TSDB_SQL_SELECT;
|
||||||
|
|
||||||
|
|
|
@ -70,4 +70,17 @@ sleep 100
|
||||||
|
|
||||||
run general/parser/lastrow_query.sim
|
run general/parser/lastrow_query.sim
|
||||||
|
|
||||||
|
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
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
Loading…
Reference in New Issue