Skip to content

Commit

Permalink
Initialize the data structure of KQIR (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice committed Mar 20, 2024
1 parent 9879fa3 commit b5207f3
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions src/search/ir.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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 <string>
#include <variant>
#include <vector>

// kqir stands for Kvorcks Query Intermediate Representation
namespace kqir {

struct FieldRef {
std::string name;
};

struct StringLiteral {
std::string val;
};

struct TagContainExpr {
FieldRef field;
StringLiteral tag;
};

struct NumericLiteral {
double val;
};

struct NumericCompareExpr {
enum { EQ, NE, LT, LET, GT, GET } op;
FieldRef field;
NumericLiteral num;
};

struct BoolLiteral {
bool val;
};

struct BooleanExpr {
std::variant<TagContainExpr, NumericCompareExpr, BoolLiteral> expr;
};

struct QueryExpr;

struct LogicalUnaryExpr {
enum { NOT } op;
std::unique_ptr<QueryExpr> inner;
};

struct LogicalBinaryExpr {
enum { AND, OR } op;
std::unique_ptr<QueryExpr> lhs;
std::unique_ptr<QueryExpr> rhs;
};

struct QueryExpr {
std::variant<LogicalUnaryExpr, LogicalBinaryExpr, BooleanExpr> expr;
};

struct Limit {
size_t offset = 0;
size_t count = std::numeric_limits<size_t>::max();
};

struct SortBy {
enum { ASC, DESC } order;
FieldRef field;
};

struct SelectExpr {
std::vector<FieldRef> fields;
};

struct IndexRef {
std::string name;
};

struct SearchStmt {
IndexRef index_ref;
QueryExpr query_expr;
Limit limit;
SortBy sort_by;
SelectExpr select_expr;
};

} // namespace kqir

0 comments on commit b5207f3

Please sign in to comment.