This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 1c433436 Add a simple pass manager for KQIR (#2226)
1c433436 is described below

commit 1c4334367f52ee2be0d62fbe3cf3f0f03f0e4294
Author: Twice <[email protected]>
AuthorDate: Sat Apr 6 18:38:34 2024 +0900

    Add a simple pass manager for KQIR (#2226)
---
 src/search/passes/manager.h   | 51 +++++++++++++++++++++++++++++++++++++++++++
 tests/cppunit/ir_pass_test.cc |  7 ++++++
 2 files changed, 58 insertions(+)

diff --git a/src/search/passes/manager.h b/src/search/passes/manager.h
new file mode 100644
index 00000000..5d11e670
--- /dev/null
+++ b/src/search/passes/manager.h
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#pragma once
+
+#include <memory>
+#include <utility>
+
+#include "search/ir.h"
+#include "search/ir_pass.h"
+#include "search/passes/push_down_not_expr.h"
+#include "search/passes/simplify_and_or_expr.h"
+#include "search/passes/simplify_boolean.h"
+
+namespace kqir {
+
+struct PassManager {
+  template <typename... PN>
+  static std::unique_ptr<Node> Execute(std::unique_ptr<Node> node) {
+    return executeImpl<PN...>(std::move(node), 
std::make_index_sequence<sizeof...(PN)>{});
+  }
+
+  static constexpr auto Default = Execute<SimplifyAndOrExpr, PushDownNotExpr, 
SimplifyBoolean>;
+
+ private:
+  template <typename... PN, size_t... I>
+  static std::unique_ptr<Node> executeImpl(std::unique_ptr<Node> node, 
std::index_sequence<I...>) {
+    std::tuple<PN...> passes;
+
+    return std::move(((node = std::get<I>(passes).Transform(std::move(node))), 
...));
+  }
+};
+
+}  // namespace kqir
diff --git a/tests/cppunit/ir_pass_test.cc b/tests/cppunit/ir_pass_test.cc
index 7ac7dfd0..70d39f96 100644
--- a/tests/cppunit/ir_pass_test.cc
+++ b/tests/cppunit/ir_pass_test.cc
@@ -21,6 +21,7 @@
 #include "search/ir_pass.h"
 
 #include "gtest/gtest.h"
+#include "search/passes/manager.h"
 #include "search/passes/push_down_not_expr.h"
 #include "search/passes/simplify_and_or_expr.h"
 #include "search/passes/simplify_boolean.h"
@@ -96,3 +97,9 @@ TEST(IRPassTest, PushDownNotExpr) {
   ASSERT_EQ(pdne.Transform(*Parse("select * from a where not (not a > 1 or (b 
< 3 and c hastag \"\"))"))->Dump(),
             "select * from a where (and a > 1, (or b >= 3, not c hastag 
\"\"))");
 }
+
+TEST(IRPassTest, Manager) {
+  ASSERT_EQ(
+      PassManager::Default(*Parse("select * from a where not (x > 1 or (y < 2 
or z = 3)) and (true or x = 1)"))->Dump(),
+      "select * from a where (and x <= 1, y >= 2, z != 3)");
+}

Reply via email to