MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
全部  文件 函数 变量 枚举 枚举值 宏定义  
string_list_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/11/18.
13//
14
15#pragma once
16
17#include <vector>
18#include "sql/operator/physical_operator.h"
19
26{
27public:
29 {}
30
31 virtual ~StringListPhysicalOperator() = default;
32
33 template <typename InputIt>
34 void append(InputIt begin, InputIt end)
35 {
36 strings_.emplace_back(begin, end);
37 }
38
39 void append(std::initializer_list<std::string> init)
40 {
41 strings_.emplace_back(init);
42 }
43
44 template <typename T>
45 void append(const T &v)
46 {
47 strings_.emplace_back(1, v);
48 }
49
50 PhysicalOperatorType type() const override
51 {
52 return PhysicalOperatorType::STRING_LIST;
53 }
54
55 RC open(Trx *) override
56 {
57 return RC::SUCCESS;
58 }
59
60 RC next() override
61 {
62 if (!started_) {
63 started_ = true;
64 iterator_ = strings_.begin();
65 } else if (iterator_ != strings_.end()) {
66 ++iterator_;
67 }
68 return iterator_ == strings_.end() ? RC::RECORD_EOF : RC::SUCCESS;
69 }
70
71 virtual RC close() override
72 {
73 iterator_ = strings_.end();
74 return RC::SUCCESS;
75 }
76
77 virtual Tuple *current_tuple() override
78 {
79 if (iterator_ == strings_.end()) {
80 return nullptr;
81 }
82
83 const StringList &string_list = *iterator_;
84 std::vector<Value> cells;
85 for (const std::string &s : string_list) {
86
87 Value value;
88 value.set_string(s.c_str());
89 cells.push_back(value);
90 }
91 tuple_.set_cells(cells);
92 return &tuple_;
93 }
94
95private:
96 using StringList = std::vector<std::string>;
97 using StringListList = std::vector<StringList>;
98 StringListList strings_;
99 StringListList::iterator iterator_;
100 bool started_ = false;
101 ValueListTuple tuple_;
102};
与LogicalOperator对应,物理算子描述执行计划将如何执行
Definition: physical_operator.h:57
字符串列表物理算子
Definition: string_list_physical_operator.h:26
事务接口
Definition: trx.h:142
元组的抽象描述
Definition: tuple.h:84
一些常量值组成的Tuple
Definition: tuple.h:340
属性的值
Definition: value.h:40
PhysicalOperatorType
物理算子类型
Definition: physical_operator.h:39