Skip to content

Commit

Permalink
feat(tianmu): make Unsupported data type more friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
HappenLee authored and mergify[bot] committed Dec 1, 2022
1 parent c5e9ef2 commit 7d10399
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mysql-test/suite/tianmu/r/create_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,8 @@ t1 CREATE TABLE `t1` (
`fld1` int(11) DEFAULT NULL,
`fld2` datetime DEFAULT '1211-01-01 00:00:00'
) ENGINE=TIANMU DEFAULT CHARSET=latin1
# error of support type
create table t_unsupport_type (a2 bit DEFAULT NULL);
ERROR HY000: Unsupported data type[bit]
create table t_unsupport_type (a2 json DEFAULT NULL);
ERROR HY000: Unsupported data type[json]
6 changes: 6 additions & 0 deletions mysql-test/suite/tianmu/t/create_table.test
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,9 @@ drop table t1;
--echo # create table..select based on trigger fields.
create table t1 (fld1 int, fld2 DATETIME DEFAULT '1211:1:1');
show create table t1;

--echo # error of support type
--error 6
create table t_unsupport_type (a2 bit DEFAULT NULL);
--error 6
create table t_unsupport_type (a2 json DEFAULT NULL);
48 changes: 48 additions & 0 deletions storage/tianmu/common/common_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,54 @@ enum class ColumnType : unsigned char {
UNK = 255
};

#define MYSQL_ENUM_FIELD_TYPE \
DISPOSE(MYSQL_TYPE_DECIMAL, "decimal") \
DISPOSE(MYSQL_TYPE_TINY, "tiny") \
DISPOSE(MYSQL_TYPE_SHORT, "short") \
DISPOSE(MYSQL_TYPE_LONG, "long") \
DISPOSE(MYSQL_TYPE_FLOAT, "float") \
DISPOSE(MYSQL_TYPE_DOUBLE, "double") \
DISPOSE(MYSQL_TYPE_NULL, "null") \
DISPOSE(MYSQL_TYPE_TIMESTAMP, "timestamp") \
DISPOSE(MYSQL_TYPE_LONGLONG, "longlong") \
DISPOSE(MYSQL_TYPE_INT24, "int24") \
DISPOSE(MYSQL_TYPE_DATE, "date") \
DISPOSE(MYSQL_TYPE_TIME, "time") \
DISPOSE(MYSQL_TYPE_DATETIME, "datetime") \
DISPOSE(MYSQL_TYPE_YEAR, "year") \
DISPOSE(MYSQL_TYPE_NEWDATE, "newdate") \
DISPOSE(MYSQL_TYPE_VARCHAR, "varchar") \
DISPOSE(MYSQL_TYPE_BIT, "bit") \
DISPOSE(MYSQL_TYPE_TIMESTAMP2, "timestamp2") \
DISPOSE(MYSQL_TYPE_DATETIME2, "datetime2") \
DISPOSE(MYSQL_TYPE_TIME2, "time2") \
DISPOSE(MYSQL_TYPE_JSON, "json") \
DISPOSE(MYSQL_TYPE_NEWDECIMAL, "newdecimal") \
DISPOSE(MYSQL_TYPE_ENUM, "enum") \
DISPOSE(MYSQL_TYPE_SET, "set") \
DISPOSE(MYSQL_TYPE_TINY_BLOB, "tiny_blob") \
DISPOSE(MYSQL_TYPE_MEDIUM_BLOB, "medium_blob") \
DISPOSE(MYSQL_TYPE_LONG_BLOB, "long_blob") \
DISPOSE(MYSQL_TYPE_BLOB, "blob") \
DISPOSE(MYSQL_TYPE_VAR_STRING, "var_string") \
DISPOSE(MYSQL_TYPE_STRING, "string") \
DISPOSE(MYSQL_TYPE_GEOMETRY, "geometry")

#define DISPOSE(mark, name) {mark, name},
constexpr std::pair<int, const char*> enum_field_types_name[] =
{
MYSQL_ENUM_FIELD_TYPE
};
#undef DISPOSE

constexpr const char* get_enum_field_types_name(int type) {
for (auto type_name : enum_field_types_name) {
if (type_name.first == type)
return type_name.second;
}
return "unkonwn type";
}

enum class PackType { INT, STR };

constexpr double PLUS_INF_DBL = DBL_MAX;
Expand Down
4 changes: 3 additions & 1 deletion storage/tianmu/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <set>
#include <tuple>

#include "common/common_definitions.h"
#include "common/data_format.h"
#include "common/exception.h"
#include "common/mysql_gate.h"
Expand Down Expand Up @@ -749,7 +750,8 @@ AttributeTypeInfo Engine::GetAttrTypeInfo(const Field &field) {
}
[[fallthrough]];
default:
throw common::UnsupportedDataTypeException("Unsupported data type.");
throw common::UnsupportedDataTypeException(
std::string("Unsupported data type[") + common::get_enum_field_types_name(field.type()) + std::string("]"));
}
throw;
}
Expand Down

0 comments on commit 7d10399

Please sign in to comment.