table_meta.h 2.2 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
羽飞's avatar
羽飞 已提交
12
// Created by Wangyunlai on 2021/5/12.
羽飞's avatar
羽飞 已提交
13 14
//

羽飞's avatar
羽飞 已提交
15
#pragma once
羽飞's avatar
羽飞 已提交
16 17 18 19

#include <string>
#include <vector>

羽飞's avatar
羽飞 已提交
20 21 22
#include "common/rc.h"
#include "storage/field/field_meta.h"
#include "storage/index/index_meta.h"
羽飞's avatar
羽飞 已提交
23 24
#include "common/lang/serializable.h"

羽飞's avatar
羽飞 已提交
25 26
class TableMeta : public common::Serializable
{
羽飞's avatar
羽飞 已提交
27 28 29 30 31 32 33 34
public:
  TableMeta() = default;
  ~TableMeta() = default;

  TableMeta(const TableMeta &other);

  void swap(TableMeta &other) noexcept;

35
  RC init(int32_t table_id, const char *name, int field_num, const AttrInfo attributes[]);
羽飞's avatar
羽飞 已提交
36 37 38 39

  RC add_index(const IndexMeta &index);

public:
40
  int32_t table_id() const { return table_id_; }
L
Longda 已提交
41 42 43 44 45
  const char *name() const;
  const FieldMeta *trx_field() const;
  const FieldMeta *field(int index) const;
  const FieldMeta *field(const char *name) const;
  const FieldMeta *find_field_by_offset(int offset) const;
L
Longda Feng 已提交
46 47 48 49
  const std::vector<FieldMeta> *field_metas() const
  {
    return &fields_;
  }
羽飞's avatar
羽飞 已提交
50 51
  auto trx_fields() const -> const std::pair<const FieldMeta *, int>;
  
L
Longda Feng 已提交
52
  int field_num() const;  // sys field included
羽飞's avatar
羽飞 已提交
53 54
  int sys_field_num() const;

L
Longda 已提交
55 56 57
  const IndexMeta *index(const char *name) const;
  const IndexMeta *find_index_by_field(const char *field) const;
  const IndexMeta *index(int i) const;
羽飞's avatar
羽飞 已提交
58 59 60 61 62
  int index_num() const;

  int record_size() const;

public:
L
Longda 已提交
63 64 65
  int serialize(std::ostream &os) const override;
  int deserialize(std::istream &is) override;
  int get_serial_size() const override;
羽飞's avatar
羽飞 已提交
66 67 68
  void to_string(std::string &output) const override;
  void desc(std::ostream &os) const;

L
Longda 已提交
69
protected:
70
  int32_t     table_id_ = -1;
L
Longda 已提交
71 72 73
  std::string name_;
  std::vector<FieldMeta> fields_;  // 包含sys_fields
  std::vector<IndexMeta> indexes_;
羽飞's avatar
羽飞 已提交
74

L
Longda 已提交
75
  int record_size_ = 0;
羽飞's avatar
羽飞 已提交
76
};