MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
expression_tuple.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 2024/5/31.
13//
14
15#pragma once
16
17#include "common/lang/vector.h"
18#include "sql/expr/tuple.h"
19#include "common/value.h"
20#include "common/sys/rc.h"
21
22template <typename ExprPointerType>
23class ExpressionTuple : public Tuple
24{
25public:
26 ExpressionTuple(const vector<ExprPointerType> &expressions) : expressions_(expressions) {}
27 virtual ~ExpressionTuple() = default;
28
29 void set_tuple(const Tuple *tuple) { child_tuple_ = tuple; }
30
31 int cell_num() const override { return static_cast<int>(expressions_.size()); }
32
33 RC cell_at(int index, Value &cell) const override
34 {
35 if (index < 0 || index >= cell_num()) {
36 return RC::INVALID_ARGUMENT;
37 }
38
39 const ExprPointerType &expression = expressions_[index];
40 return get_value(expression, cell);
41 }
42
43 RC spec_at(int index, TupleCellSpec &spec) const override
44 {
45 if (index < 0 || index >= cell_num()) {
46 return RC::INVALID_ARGUMENT;
47 }
48
49 const ExprPointerType &expression = expressions_[index];
50 spec = TupleCellSpec(expression->name());
51 return RC::SUCCESS;
52 }
53
54 RC find_cell(const TupleCellSpec &spec, Value &cell) const override
55 {
56 RC rc = RC::SUCCESS;
57 if (child_tuple_ != nullptr) {
58 rc = child_tuple_->find_cell(spec, cell);
59 if (OB_SUCC(rc)) {
60 return rc;
61 }
62 }
63
64 rc = RC::NOTFOUND;
65 for (const ExprPointerType &expression : expressions_) {
66 if (0 == strcmp(spec.alias(), expression->name())) {
67 rc = get_value(expression, cell);
68 break;
69 }
70 }
71
72 return rc;
73 }
74
75private:
76 RC get_value(const ExprPointerType &expression, Value &value) const
77 {
78 RC rc = RC::SUCCESS;
79 if (child_tuple_ != nullptr) {
80 rc = expression->get_value(*child_tuple_, value);
81 } else {
82 rc = expression->try_get_value(value);
83 }
84 return rc;
85 }
86
87private:
88 const vector<ExprPointerType> &expressions_;
89 const Tuple *child_tuple_ = nullptr;
90};
Definition: expression_tuple.h:24
RC find_cell(const TupleCellSpec &spec, Value &cell) const override
根据cell的描述,获取cell的值
Definition: expression_tuple.h:54
int cell_num() const override
获取元组中的Cell的个数
Definition: expression_tuple.h:31
RC cell_at(int index, Value &cell) const override
获取指定位置的Cell
Definition: expression_tuple.h:33
Definition: tuple_cell.h:20
元组的抽象描述
Definition: tuple.h:66
virtual RC find_cell(const TupleCellSpec &spec, Value &cell) const =0
根据cell的描述,获取cell的值
属性的值
Definition: value.h:30