MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
chunk.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#pragma once
12
13#include "common/sys/rc.h"
14#include "common/log/log.h"
15#include "common/lang/memory.h"
16#include "common/lang/vector.h"
17#include "storage/common/column.h"
18
22class Chunk
23{
24public:
25 Chunk() = default;
26 Chunk(const Chunk &) = delete;
27 Chunk(Chunk &&) = delete;
28
29 int column_num() const { return columns_.size(); }
30
31 Column &column(size_t idx)
32 {
33 ASSERT(idx < columns_.size(), "invalid column index");
34 return *columns_[idx];
35 }
36
37 Column *column_ptr(size_t idx)
38 {
39 ASSERT(idx < columns_.size(), "invalid column index");
40 return &column(idx);
41 }
42
43 int column_ids(size_t i)
44 {
45 ASSERT(i < column_ids_.size(), "invalid column index");
46 return column_ids_[i];
47 }
48
49 void add_column(unique_ptr<Column> col, int col_id);
50
51 RC reference(Chunk &chunk);
52
56 int rows() const;
57
61 int capacity() const;
62
71 Value get_value(int col_idx, int row_idx) const { return columns_[col_idx]->get_value(row_idx); }
72
76 void reset_data();
77
78 void reset();
79
80private:
81 vector<unique_ptr<Column>> columns_;
82 // TODO: remove it and support multi-tables,
83 // `columnd_ids` store the ids of child operator that need to be output
84 vector<int> column_ids_;
85};
A Chunk represents a set of columns.
Definition: chunk.h:23
int capacity() const
获取 Chunk 的容量
Definition: chunk.cpp:41
Value get_value(int col_idx, int row_idx) const
从 Chunk 中获得指定行指定列的 Value
Definition: chunk.h:71
void reset_data()
重置 Chunk 中的数据,不会修改 Chunk 的列属性。
Definition: chunk.cpp:49
int rows() const
获取 Chunk 中的行数
Definition: chunk.cpp:33
A column contains multiple values in contiguous memory with a specified type.
Definition: column.h:22
属性的值
Definition: value.h:30