-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tianmu): support add integer/decimal column DDL with default valu…
…e. (#1187) [summary] check the default value of field,please see tianmu_attr.cpp for details: 1. if field is integer type but not real type; 2. if field is integer type and also real type; 3. if field is not integer type;
- Loading branch information
lujiashun
committed
Jan 11, 2023
1 parent
3fa2aab
commit 13f62b6
Showing
11 changed files
with
250 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
DROP DATABASE IF EXISTS issuse1187_test; | ||
CREATE DATABASE issuse1187_test; | ||
create table t1(id int,name varchar(5)) ; | ||
insert into t1 values(1,'AAA'),(2,'BBB'); | ||
alter table t1 add column age int null; | ||
select * from t1; | ||
id name age | ||
1 AAA NULL | ||
2 BBB NULL | ||
create table t2(id int,name varchar(5)) ; | ||
insert into t2 values(1,'AAA'),(2,'BBB'); | ||
alter table t2 add column age int not null; | ||
select * from t2; | ||
id name age | ||
1 AAA 0 | ||
2 BBB 0 | ||
create table t3(id int,name varchar(5)) ; | ||
insert into t3 values(1,'AAA'),(2,'BBB'); | ||
alter table t3 add column age int not null default 66; | ||
select * from t3; | ||
id name age | ||
1 AAA 66 | ||
2 BBB 66 | ||
create table t4(id int,name varchar(5)) ; | ||
insert into t4 values(1,'AAA'),(2,'BBB'); | ||
alter table t4 add column age DECIMAL(17,9); | ||
select * from t4; | ||
id name age | ||
1 AAA NULL | ||
2 BBB NULL | ||
create table t5(id int,name varchar(5)) ; | ||
insert into t5 values(1,'AAA'),(2,'BBB'); | ||
alter table t5 add column age DECIMAL(17,9) not null; | ||
select * from t5; | ||
id name age | ||
1 AAA 0.000000000 | ||
2 BBB 0.000000000 | ||
create table t6(id int,name varchar(5)) ; | ||
insert into t6 values(1,'AAA'),(2,'BBB'); | ||
alter table t6 add column age DECIMAL(17,9) not null default '800.0024'; | ||
select * from t6; | ||
id name age | ||
1 AAA 800.002400000 | ||
2 BBB 800.002400000 | ||
DROP DATABASE issuse1187_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--source include/have_tianmu.inc | ||
|
||
--disable_warnings | ||
DROP DATABASE IF EXISTS issuse1187_test; | ||
--enable_warnings | ||
|
||
CREATE DATABASE issuse1187_test; | ||
|
||
create table t1(id int,name varchar(5)) ; | ||
insert into t1 values(1,'AAA'),(2,'BBB'); | ||
alter table t1 add column age int null; | ||
select * from t1; | ||
|
||
create table t2(id int,name varchar(5)) ; | ||
insert into t2 values(1,'AAA'),(2,'BBB'); | ||
alter table t2 add column age int not null; | ||
select * from t2; | ||
|
||
create table t3(id int,name varchar(5)) ; | ||
insert into t3 values(1,'AAA'),(2,'BBB'); | ||
alter table t3 add column age int not null default 66; | ||
select * from t3; | ||
|
||
create table t4(id int,name varchar(5)) ; | ||
insert into t4 values(1,'AAA'),(2,'BBB'); | ||
alter table t4 add column age DECIMAL(17,9); | ||
select * from t4; | ||
|
||
create table t5(id int,name varchar(5)) ; | ||
insert into t5 values(1,'AAA'),(2,'BBB'); | ||
alter table t5 add column age DECIMAL(17,9) not null; | ||
select * from t5; | ||
|
||
create table t6(id int,name varchar(5)) ; | ||
insert into t6 values(1,'AAA'),(2,'BBB'); | ||
alter table t6 add column age DECIMAL(17,9) not null default '800.0024'; | ||
select * from t6; | ||
|
||
DROP DATABASE issuse1187_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,68 @@ | ||
/* Copyright (c) 2022 StoneAtom, Inc. All rights reserved. | ||
Use is subject to license terms | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; version 2 of the License. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA | ||
*/ | ||
#ifndef TIANMU_CORE_VALUE_H_ | ||
#define TIANMU_CORE_VALUE_H_ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <variant> | ||
|
||
namespace Tianmu { | ||
namespace core { | ||
class Value final { | ||
public: | ||
Value() = default; | ||
explicit Value(int64_t i) { var = i; } | ||
~Value() = default; | ||
|
||
bool HasValue() const { return !std::holds_alternative<std::monostate>(var); } | ||
bool IsInt() const { return std::holds_alternative<int64_t>(var); } | ||
bool IsDouble() const { return std::holds_alternative<double>(var); } | ||
bool IsString() const { return std::holds_alternative<std::string>(var); } | ||
bool IsStringView() const { return std::holds_alternative<std::string_view>(var); } | ||
|
||
void SetInt(int64_t v) { var = v; } | ||
int64_t &GetInt() { return std::get<int64_t>(var); } | ||
const int64_t &GetInt() const { return std::get<int64_t>(var); } | ||
|
||
void SetDouble(double v) { var = v; } | ||
double &GetDouble() { return std::get<double>(var); } | ||
const double &GetDouble() const { return std::get<double>(var); } | ||
|
||
void SetString(char *s, uint n) { var.emplace<std::string>(s, n); } | ||
std::string &GetString() { return std::get<std::string>(var); } | ||
const std::string &GetString() const { return std::get<std::string>(var); } | ||
|
||
void SetStringView(char *s, uint n) { var.emplace<std::string_view>(s, n); } | ||
std::string_view &GetStringView() { return std::get<std::string_view>(var); } | ||
const std::string_view &GetStringView() const { return std::get<std::string_view>(var); } | ||
|
||
private: | ||
std::variant<std::monostate, int64_t, double, std::string, std::string_view> var; | ||
}; | ||
} // namespace core | ||
} // namespace Tianmu | ||
|
||
#endif // TIANMU_CORE_VALUE_H_ | ||
/* Copyright (c) 2022 StoneAtom, Inc. All rights reserved. | ||
Use is subject to license terms | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; version 2 of the License. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA | ||
*/ | ||
#ifndef TIANMU_CORE_VALUE_H_ | ||
#define TIANMU_CORE_VALUE_H_ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <variant> | ||
|
||
namespace Tianmu { | ||
namespace core { | ||
class Value final { | ||
public: | ||
Value() = default; | ||
// just to skip debian compiler error for copy constructor; | ||
Value(const Value &other) : var() { var = other.var; } | ||
Value &operator=(const Value &other) { | ||
if (this != &other) { | ||
var = other.var; | ||
} | ||
return *this; | ||
} | ||
explicit Value(int64_t i) { var = i; } | ||
~Value() = default; | ||
|
||
bool HasValue() const { return !std::holds_alternative<std::monostate>(var); } | ||
bool IsInt() const { return std::holds_alternative<int64_t>(var); } | ||
bool IsDouble() const { return std::holds_alternative<double>(var); } | ||
bool IsString() const { return std::holds_alternative<std::string>(var); } | ||
bool IsStringView() const { return std::holds_alternative<std::string_view>(var); } | ||
|
||
void SetInt(int64_t v) { var = v; } | ||
int64_t &GetInt() { return std::get<int64_t>(var); } | ||
const int64_t &GetInt() const { return std::get<int64_t>(var); } | ||
|
||
void SetDouble(double v) { var = v; } | ||
double &GetDouble() { return std::get<double>(var); } | ||
const double &GetDouble() const { return std::get<double>(var); } | ||
|
||
void SetString(char *s, uint n) { var.emplace<std::string>(s, n); } | ||
std::string &GetString() { return std::get<std::string>(var); } | ||
const std::string &GetString() const { return std::get<std::string>(var); } | ||
|
||
void SetStringView(char *s, uint n) { var.emplace<std::string_view>(s, n); } | ||
std::string_view &GetStringView() { return std::get<std::string_view>(var); } | ||
const std::string_view &GetStringView() const { return std::get<std::string_view>(var); } | ||
|
||
private: | ||
std::variant<std::monostate, int64_t, double, std::string, std::string_view> var; | ||
}; | ||
} // namespace core | ||
} // namespace Tianmu | ||
|
||
#endif // TIANMU_CORE_VALUE_H_ |
Oops, something went wrong.