MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
calc_physical_operator.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/07/01.
13//
14
15#pragma once
16
17#include "sql/operator/physical_operator.h"
18#include "sql/expr/tuple.h"
19
21{
22public:
23 CalcPhysicalOperator(std::vector<std::unique_ptr<Expression>> &&expressions)
24 : expressions_(std::move(expressions)), tuple_(expressions_)
25 {}
26
27 virtual ~CalcPhysicalOperator() = default;
28
29 PhysicalOperatorType type() const override
30 {
31 return PhysicalOperatorType::CALC;
32 }
33
34 std::string name() const override
35 {
36 return "CALC";
37 }
38 std::string param() const override
39 {
40 return "";
41 }
42
43 RC open(Trx *trx) override { return RC::SUCCESS;}
44 RC next() override
45 {
46 RC rc = RC::SUCCESS;
47 if (emitted_) {
48 rc = RC::RECORD_EOF;
49 return rc;
50 }
51 emitted_ = true;
52
53 int cell_num = tuple_.cell_num();
54 for (int i = 0; i < cell_num; i++) {
55 Value value;
56 rc = tuple_.cell_at(i, value);
57 if (OB_FAIL(rc)) {
58 return rc;
59 }
60 }
61 return RC::SUCCESS;
62 }
63 RC close() override { return RC::SUCCESS; }
64
65 int cell_num() const
66 {
67 return tuple_.cell_num();
68 }
69
70 Tuple *current_tuple() override
71 {
72 return &tuple_;
73 }
74
75 const std::vector<std::unique_ptr<Expression>> &expressions() const
76 {
77 return expressions_;
78 }
79
80private:
81 std::vector<std::unique_ptr<Expression>> expressions_;
82 ExpressionTuple tuple_;
83 bool emitted_ = false;
84};
Definition: calc_physical_operator.h:21
std::string name() const override
Definition: calc_physical_operator.h:34
Definition: tuple.h:294
int cell_num() const override
获取元组中的Cell的个数
Definition: tuple.h:305
RC cell_at(int index, Value &cell) const override
获取指定位置的Cell
Definition: tuple.h:310
与LogicalOperator对应,物理算子描述执行计划将如何执行
Definition: physical_operator.h:57
事务接口
Definition: trx.h:142
元组的抽象描述
Definition: tuple.h:84
属性的值
Definition: value.h:40
PhysicalOperatorType
物理算子类型
Definition: physical_operator.h:39