You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "PragmaTwice (via GitHub)" <gi...@apache.org> on 2024/04/08 15:50:01 UTC

[PR] Initialize the query plan part of KQIR [kvrocks]

PragmaTwice opened a new pull request, #2232:
URL: https://github.com/apache/kvrocks/pull/2232

   In this PR, we added new nodes to KQIR to construct the query plan.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1557794368


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }
+};
+
+struct Filter : PlanOperator {
+  std::unique_ptr<PlanOperator> source;
+  std::unique_ptr<QueryExpr> filter_expr;
+
+  std::string_view Name() const override { return "Filter"; };
+  std::string Dump() const override { return fmt::format("(filter {}, {})", source->Dump(), Content()); }
+
+  NodeIterator ChildBegin() override { return {source.get(), filter_expr.get()}; }
+  NodeIterator ChildEnd() override { return {}; }
+};
+
+struct Merge : PlanOperator {
+  std::vector<std::unique_ptr<PlanOperator>> ops;
+
+  std::string_view Name() const override { return "Merge"; };
+  std::string Dump() const override {
+    return fmt::format("(merge {})", util::StringJoin(ops, [](const auto &v) { return v->Dump(); }));
+  }
+
+  NodeIterator ChildBegin() override { return NodeIterator(ops.begin()); }
+  NodeIterator ChildEnd() override { return NodeIterator(ops.end()); }
+};
+
+struct Limit : PlanOperator {
+  std::unique_ptr<PlanOperator> op;
+  size_t offset = 0, count = std::numeric_limits<size_t>::max();
+
+  std::string_view Name() const override { return "Limit"; };
+  std::string Dump() const override { return fmt::format("(limit {}, {}: {})", offset, count, op->Dump()); }
+
+  NodeIterator ChildBegin() override { return NodeIterator{op.get()}; }
+  NodeIterator ChildEnd() override { return {}; }
+};
+
+struct Projection : PlanOperator {
+  std::unique_ptr<PlanOperator> source;
+  std::unique_ptr<SelectExpr> select;

Review Comment:
   It currently just doesn't support such form.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1556826743


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+namespace plan {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }

Review Comment:
   Ahh I think I've got you now. Yeah I prefer S-expr and omit the parentheses as much as possible, rather than `f(..)`.
   And `Dump` is only used for equality checking in unit test. For debugging, we can use the dot graph dumper.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1557759414


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }
+};
+
+struct Filter : PlanOperator {
+  std::unique_ptr<PlanOperator> source;
+  std::unique_ptr<QueryExpr> filter_expr;
+
+  std::string_view Name() const override { return "Filter"; };
+  std::string Dump() const override { return fmt::format("(filter {}, {})", source->Dump(), Content()); }
+
+  NodeIterator ChildBegin() override { return {source.get(), filter_expr.get()}; }
+  NodeIterator ChildEnd() override { return {}; }
+};
+
+struct Merge : PlanOperator {

Review Comment:
   You can add description on Merge, since it's far from "SQL MERGE", which means doing complex if-else on selected data



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice merged PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1556826743


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+namespace plan {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }

Review Comment:
   Ahh I think I've got you now. Yeah I prefer S-expr and omit the parentheses as much as possible, rather than `f(..)`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#issuecomment-2043237913

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2232) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=2232&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2232&metric=new_accepted_issues&view=list)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=2232&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [61.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2232&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2232&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2232)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1557795106


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }
+};
+
+struct Filter : PlanOperator {
+  std::unique_ptr<PlanOperator> source;
+  std::unique_ptr<QueryExpr> filter_expr;
+
+  std::string_view Name() const override { return "Filter"; };
+  std::string Dump() const override { return fmt::format("(filter {}, {})", source->Dump(), Content()); }
+
+  NodeIterator ChildBegin() override { return {source.get(), filter_expr.get()}; }
+  NodeIterator ChildEnd() override { return {}; }
+};
+
+struct Merge : PlanOperator {

Review Comment:
   I see. Good suggestion.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#issuecomment-2044733972

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2232) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=2232&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2232&metric=new_accepted_issues&view=list)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=2232&resolved=false&inNewCodePeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [61.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2232&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2232&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2232)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1556080997


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+namespace plan {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }

Review Comment:
   is nested struct better than just white space?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1556810917


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+namespace plan {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }

Review Comment:
   I cannot get you. Please be more specific : )



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize the query plan part of KQIR [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #2232:
URL: https://github.com/apache/kvrocks/pull/2232#discussion_r1557766469


##########
src/search/ir_plan.h:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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 <limits>
+#include <memory>
+
+#include "ir.h"
+#include "search/ir_sema_checker.h"
+#include "string_util.h"
+
+namespace kqir {
+
+struct PlanOperator : Node {};
+
+struct FullIndexScan : PlanOperator {
+  IndexInfo *index;
+
+  std::string_view Name() const override { return "FullIndexScan"; };
+  std::string Content() const override { return index->name; };
+  std::string Dump() const override { return fmt::format("full-scan {}", Content()); }
+};
+
+struct FieldScan : PlanOperator {
+  FieldInfo *field;
+};
+
+struct Interval {
+  double l, r;  // [l, r)
+
+  std::string ToString() const { return fmt::format("[{}, {})", l, r); }
+};
+
+struct NumericFieldScan : FieldScan {
+  Interval range;
+
+  std::string_view Name() const override { return "NumericFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, range.ToString()); };
+  std::string Dump() const override { return fmt::format("numeric-scan {}", Content()); }
+};
+
+struct TagFieldScan : FieldScan {
+  std::string tag;
+
+  std::string_view Name() const override { return "TagFieldScan"; };
+  std::string Content() const override { return fmt::format("{}, {}", field->name, tag); };
+  std::string Dump() const override { return fmt::format("tag-scan {}", Content()); }
+};
+
+struct Filter : PlanOperator {
+  std::unique_ptr<PlanOperator> source;
+  std::unique_ptr<QueryExpr> filter_expr;
+
+  std::string_view Name() const override { return "Filter"; };
+  std::string Dump() const override { return fmt::format("(filter {}, {})", source->Dump(), Content()); }
+
+  NodeIterator ChildBegin() override { return {source.get(), filter_expr.get()}; }
+  NodeIterator ChildEnd() override { return {}; }
+};
+
+struct Merge : PlanOperator {
+  std::vector<std::unique_ptr<PlanOperator>> ops;
+
+  std::string_view Name() const override { return "Merge"; };
+  std::string Dump() const override {
+    return fmt::format("(merge {})", util::StringJoin(ops, [](const auto &v) { return v->Dump(); }));
+  }
+
+  NodeIterator ChildBegin() override { return NodeIterator(ops.begin()); }
+  NodeIterator ChildEnd() override { return NodeIterator(ops.end()); }
+};
+
+struct Limit : PlanOperator {
+  std::unique_ptr<PlanOperator> op;
+  size_t offset = 0, count = std::numeric_limits<size_t>::max();
+
+  std::string_view Name() const override { return "Limit"; };
+  std::string Dump() const override { return fmt::format("(limit {}, {}: {})", offset, count, op->Dump()); }
+
+  NodeIterator ChildBegin() override { return NodeIterator{op.get()}; }
+  NodeIterator ChildEnd() override { return {}; }
+};
+
+struct Projection : PlanOperator {
+  std::unique_ptr<PlanOperator> source;
+  std::unique_ptr<SelectExpr> select;

Review Comment:
   I just noticed that SelectExpr is array of field, what would `select 1;` like?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org