From cdc8b757ad6a58b9cfd1d9d509c8f2de9019abc3 Mon Sep 17 00:00:00 2001 From: slzhou Date: Wed, 18 Oct 2023 10:11:43 +0800 Subject: [PATCH 1/5] fix: remove subquery user alias name distinct check --- source/libs/parser/src/parTranslater.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 42ab2f7a2f..85d154b94c 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3318,9 +3318,6 @@ static int32_t checkProjectAlias(STranslateContext* pCxt, SNodeList* pProjection } static int32_t translateProjectionList(STranslateContext* pCxt, SSelectStmt* pSelect) { - if (pSelect->isSubquery) { - return checkProjectAlias(pCxt, pSelect->pProjectionList, NULL); - } return rewriteProjectAlias(pSelect->pProjectionList); } From 98d782cfa5d63479c8253c16388f7dde0beb3f41 Mon Sep 17 00:00:00 2001 From: slzhou Date: Wed, 18 Oct 2023 11:04:34 +0800 Subject: [PATCH 2/5] fix: if not subquery, rewrite project alias --- source/libs/parser/src/parTranslater.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 85d154b94c..05c5b427fe 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3318,7 +3318,9 @@ static int32_t checkProjectAlias(STranslateContext* pCxt, SNodeList* pProjection } static int32_t translateProjectionList(STranslateContext* pCxt, SSelectStmt* pSelect) { - return rewriteProjectAlias(pSelect->pProjectionList); + if (!pSelect->isSubquery) { + return rewriteProjectAlias(pSelect->pProjectionList); + } } static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect) { From 9c1697bfd11cb701e2bd82b97a78e1c5b6cfd879 Mon Sep 17 00:00:00 2001 From: slzhou Date: Wed, 18 Oct 2023 13:19:44 +0800 Subject: [PATCH 3/5] fix: fix minior error --- source/libs/parser/src/parTranslater.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 05c5b427fe..4d212a1c3d 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3320,6 +3320,8 @@ static int32_t checkProjectAlias(STranslateContext* pCxt, SNodeList* pProjection static int32_t translateProjectionList(STranslateContext* pCxt, SSelectStmt* pSelect) { if (!pSelect->isSubquery) { return rewriteProjectAlias(pSelect->pProjectionList); + } else { + return TSDB_CODE_SUCCESS; } } From 02658a4b3ca9febde23ec4daeeec5d5c4d5f62ab Mon Sep 17 00:00:00 2001 From: slzhou Date: Wed, 18 Oct 2023 15:30:18 +0800 Subject: [PATCH 4/5] fix: add test case --- tests/script/tsim/query/unionall_as_table.sim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/script/tsim/query/unionall_as_table.sim b/tests/script/tsim/query/unionall_as_table.sim index f8145d4e97..11fdf17978 100644 --- a/tests/script/tsim/query/unionall_as_table.sim +++ b/tests/script/tsim/query/unionall_as_table.sim @@ -1,5 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c keepColumnName -v 1 system sh/exec.sh -n dnode1 -s start sql connect @@ -50,4 +51,14 @@ print $data00 if $data00 != 2 then return -1 endi +sql select count(*) from (select f, f from ctcount) +print $data00 +if $data00 != 2 then + return -1 +endi +sql select count(*) from (select last(ts), first(ts) from ctcount); +print $data00 +if $data00 != 1 then + return -1 +endi system sh/exec.sh -n dnode1 -s stop -x SIGINT From 81b7093a42a14ef1f9188e8810c3f141eabac08a Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 19 Oct 2023 11:17:00 +0800 Subject: [PATCH 5/5] enhance: enhance test --- tests/script/tsim/query/unionall_as_table.sim | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/tsim/query/unionall_as_table.sim b/tests/script/tsim/query/unionall_as_table.sim index 11fdf17978..a03ecac34a 100644 --- a/tests/script/tsim/query/unionall_as_table.sim +++ b/tests/script/tsim/query/unionall_as_table.sim @@ -61,4 +61,5 @@ print $data00 if $data00 != 1 then return -1 endi +sql_error select f from (select f, f from ctcount); system sh/exec.sh -n dnode1 -s stop -x SIGINT