MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
integer_type.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/type/data_type.h"
14
19class IntegerType : public DataType
20{
21public:
22 IntegerType() : DataType(AttrType::INTS) {}
23 virtual ~IntegerType() {}
24
25 int compare(const Value &left, const Value &right) const override;
26 int compare(const Column &left, const Column &right, int left_idx, int right_idx) const override;
27
28 RC add(const Value &left, const Value &right, Value &result) const override;
29 RC subtract(const Value &left, const Value &right, Value &result) const override;
30 RC multiply(const Value &left, const Value &right, Value &result) const override;
31 RC negative(const Value &val, Value &result) const override;
32
33 RC cast_to(const Value &val, AttrType type, Value &result) const override;
34
35 int cast_cost(const AttrType type) override
36 {
37 if (type == AttrType::INTS) {
38 return 0;
39 } else if (type == AttrType::FLOATS) {
40 return 1;
41 }
42 return INT32_MAX;
43 }
44
45 RC set_value_from_str(Value &val, const string &data) const override;
46
47 RC to_string(const Value &val, string &result) const override;
48};
A column contains multiple values in contiguous memory with a specified type.
Definition: column.h:23
Definition: data_type.h:30
整型类型
Definition: integer_type.h:20
RC multiply(const Value &left, const Value &right, Value &result) const override
计算 left * right,并将结果保存到 result 中
Definition: integer_type.cpp:66
RC negative(const Value &val, Value &result) const override
计算 -val,并将结果保存到 result 中
Definition: integer_type.cpp:72
RC cast_to(const Value &val, AttrType type, Value &result) const override
将 val 转换为 type 类型,并将结果保存到 result 中
Definition: integer_type.cpp:40
RC subtract(const Value &left, const Value &right, Value &result) const override
计算 left - right,并将结果保存到 result 中
Definition: integer_type.cpp:60
RC add(const Value &left, const Value &right, Value &result) const override
计算 left + right,并将结果保存到 result 中
Definition: integer_type.cpp:54
int cast_cost(const AttrType type) override
计算从 type 到 attr_type 的隐式转换的 cost,如果无法转换,返回 INT32_MAX
Definition: integer_type.h:35
int compare(const Value &left, const Value &right) const override
Definition: integer_type.cpp:18
属性的值
Definition: value.h:31