From dd26795cf86cc9ae87371e9b354b4eed5ab14a51 Mon Sep 17 00:00:00 2001
From: leijsen <20215135@stud.tjut.edu.cn>
Date: Sun, 7 Jul 2024 14:07:08 +0800
Subject: [PATCH] =?UTF-8?q?having=E5=90=8E=E4=B8=8D=E8=83=BD=E8=B7=9F?=
 =?UTF-8?q?=E6=99=AE=E9=80=9A=E6=9D=A1=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/analyze/analyze.cpp | 7 +++++++
 src/errors.h            | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/src/analyze/analyze.cpp b/src/analyze/analyze.cpp
index cfc5fb8..ea0b9c0 100644
--- a/src/analyze/analyze.cpp
+++ b/src/analyze/analyze.cpp
@@ -107,6 +107,13 @@ std::shared_ptr<Query> Analyze::do_analyze(std::shared_ptr<ast::TreeNode> parse)
 
         // 处理having条件
         if (x->group_by && !x->group_by->having_conds.empty()) {
+            // having中出现普通条件对比返回异常
+            for (auto &cond : x->group_by->having_conds) {
+                if (cond->lhs->ag_type == ast::SV_AGGRE_NONE) {
+                    throw AggreInHavingError();
+                }
+            }
+
             get_clause(x->group_by->having_conds, query->having_conds);
             check_clause(query->tables, query->having_conds);
         }
diff --git a/src/errors.h b/src/errors.h
index 48cd9e5..815f642 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -201,4 +201,10 @@ class AggreInWhereError : public RMDBError {
 public:
     AggreInWhereError()
             : RMDBError("Aggre in where error") {}
+};
+
+class AggreInHavingError : public RMDBError {
+public:
+    AggreInHavingError()
+            : RMDBError("Aggre in having error") {}
 };
\ No newline at end of file
-- 
GitLab