MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
column.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 <string.h>
14
15#include "storage/field/field_meta.h"
16
20// TODO: `Column` currently only support fixed-length type.
21class Column
22{
23public:
24 enum class Type
25 {
26 NORMAL_COLUMN,
28 };
29
30 Column() = default;
31 Column(const Column &) = delete;
32 Column(Column &&) = delete;
33
34 Column(const FieldMeta &meta, size_t size = DEFAULT_CAPACITY);
35 Column(AttrType attr_type, int attr_len, size_t size = DEFAULT_CAPACITY);
36
37 void init(const FieldMeta &meta, size_t size = DEFAULT_CAPACITY);
38 void init(AttrType attr_type, int attr_len, size_t size = DEFAULT_CAPACITY);
39 void init(const Value &value);
40
41 virtual ~Column() { reset(); }
42
43 void reset();
44
45 RC append_one(char *data);
46
52 RC append(char *data, int count);
53
57 Value get_value(int index) const;
58
62 int data_len() const { return count_ * attr_len_; }
63
64 char *data() const { return data_; }
65
69 void reset_data() { count_ = 0; }
70
74 void reference(const Column &column);
75
76 void set_column_type(Type column_type) { column_type_ = column_type; }
77 void set_count(int count) { count_ = count; }
78
79 int count() const { return count_; }
80 int capacity() const { return capacity_; }
81 AttrType attr_type() const { return attr_type_; }
82 int attr_len() const { return attr_len_; }
83 Type column_type() const { return column_type_; }
84
85private:
86 static constexpr size_t DEFAULT_CAPACITY = 8192;
87
88 char *data_ = nullptr;
90 int count_ = 0;
92 int capacity_ = 0;
94 bool own_ = true;
96 AttrType attr_type_ = AttrType::UNDEFINED;
98 int attr_len_ = -1;
100 Type column_type_ = Type::NORMAL_COLUMN;
101};
A column contains multiple values in contiguous memory with a specified type.
Definition: column.h:22
int capacity_
当前容量,count_ <= capacity_
Definition: column.h:92
void reset_data()
重置列数据,但不修改元信息
Definition: column.h:69
int count_
当前列值数量
Definition: column.h:90
int attr_len_
列属性类型长度(目前只支持定长)
Definition: column.h:98
AttrType attr_type_
列属性类型
Definition: column.h:96
Type
Definition: column.h:25
@ CONSTANT_COLUMN
Normal column represents a list of fixed-length values
int data_len() const
获取列数据的实际大小(字节)
Definition: column.h:62
bool own_
是否拥有内存
Definition: column.h:94
RC append(char *data, int count)
向 Column 追加写入数据
Definition: column.cpp:91
Value get_value(int index) const
获取 index 位置的列值
Definition: column.cpp:109
Type column_type_
列类型
Definition: column.h:100
void reference(const Column &column)
引用另一个 Column
Definition: column.cpp:117
字段元数据
Definition: field_meta.h:30
属性的值
Definition: value.h:30