MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
filter_stmt.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by Wangyunlai on 2022/5/22.
13//
14
15#pragma once
16
17#include <vector>
18#include <unordered_map>
19#include "sql/parser/parse_defs.h"
20#include "sql/stmt/stmt.h"
21#include "sql/expr/expression.h"
22
23class Db;
24class Table;
25class FieldMeta;
26
27struct FilterObj
28{
29 bool is_attr;
30 Field field;
31 Value value;
32
33 void init_attr(const Field &field)
34 {
35 is_attr = true;
36 this->field = field;
37 }
38
39 void init_value(const Value &value)
40 {
41 is_attr = false;
42 this->value = value;
43 }
44};
45
47{
48public:
49 FilterUnit() = default;
51 {}
52
53 void set_comp(CompOp comp)
54 {
55 comp_ = comp;
56 }
57
58 CompOp comp() const
59 {
60 return comp_;
61 }
62
63 void set_left(const FilterObj &obj)
64 {
65 left_ = obj;
66 }
67 void set_right(const FilterObj &obj)
68 {
69 right_ = obj;
70 }
71
72 const FilterObj &left() const
73 {
74 return left_;
75 }
76 const FilterObj &right() const
77 {
78 return right_;
79 }
80
81private:
82 CompOp comp_ = NO_OP;
83 FilterObj left_;
84 FilterObj right_;
85};
86
92{
93public:
94 FilterStmt() = default;
95 virtual ~FilterStmt();
96
97public:
98 const std::vector<FilterUnit *> &filter_units() const
99 {
100 return filter_units_;
101 }
102
103public:
104 static RC create(Db *db, Table *default_table, std::unordered_map<std::string, Table *> *tables,
105 const ConditionSqlNode *conditions, int condition_num, FilterStmt *&stmt);
106
107 static RC create_filter_unit(Db *db, Table *default_table, std::unordered_map<std::string, Table *> *tables,
108 const ConditionSqlNode &condition, FilterUnit *&filter_unit);
109
110private:
111 std::vector<FilterUnit *> filter_units_; // 默认当前都是AND关系
112};
一个DB实例负责管理一批表
Definition: db.h:34
字段元数据
Definition: field_meta.h:31
字段
Definition: field.h:25
Filter/谓词/过滤语句
Definition: filter_stmt.h:92
Definition: filter_stmt.h:47
Definition: table.h:37
属性的值
Definition: value.h:40
CompOp
描述比较运算符
Definition: parse_defs.h:48
表示一个条件比较
Definition: parse_defs.h:67
Definition: filter_stmt.h:28