diff --git a/mysql-test/suite/tianmu/r/create_table.result b/mysql-test/suite/tianmu/r/create_table.result index 137042d505..12c8ba729a 100644 --- a/mysql-test/suite/tianmu/r/create_table.result +++ b/mysql-test/suite/tianmu/r/create_table.result @@ -574,7 +574,33 @@ t1 CREATE TABLE `t1` ( `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] +drop table if exists bittypes; +Warnings: +Note 1051 Unknown table 'test.bittypes' +create table bittypes ( +id int not null primary key, +bit1 bit(1), +bit2 bit(2), +bit4 bit(4), +bit8 bit(8), +bit16 bit(16), +bit32 bit(32), +bit63 bit(63) +) ENGINE=tianmu DEFAULT CHARSET=utf8mb4; +show create table bittypes; +Table Create Table +bittypes CREATE TABLE `bittypes` ( + `id` int(11) NOT NULL, + `bit1` bit(1) DEFAULT NULL, + `bit2` bit(2) DEFAULT NULL, + `bit4` bit(4) DEFAULT NULL, + `bit8` bit(8) DEFAULT NULL, + `bit16` bit(16) DEFAULT NULL, + `bit32` bit(32) DEFAULT NULL, + `bit63` bit(63) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 +create table tc(a bit(64)) engine=tianmu; +ERROR HY000: The bit(M) type, M must be less than or equal to 63 in tianmu engine. diff --git a/mysql-test/suite/tianmu/t/create_table.test b/mysql-test/suite/tianmu/t/create_table.test index 5c86b8eb6a..6df708eb74 100644 --- a/mysql-test/suite/tianmu/t/create_table.test +++ b/mysql-test/suite/tianmu/t/create_table.test @@ -397,6 +397,23 @@ 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); + +# test new type bit +drop table if exists bittypes; +create table bittypes ( + id int not null primary key, + + bit1 bit(1), + bit2 bit(2), + bit4 bit(4), + bit8 bit(8), + bit16 bit(16), + bit32 bit(32), + bit63 bit(63) + +) ENGINE=tianmu DEFAULT CHARSET=utf8mb4; +show create table bittypes; + +--error 6 +create table tc(a bit(64)) engine=tianmu; diff --git a/storage/tianmu/common/common_definitions.h b/storage/tianmu/common/common_definitions.h index 58e5df7655..81d751c34e 100644 --- a/storage/tianmu/common/common_definitions.h +++ b/storage/tianmu/common/common_definitions.h @@ -70,6 +70,7 @@ enum class ColumnType : unsigned char { MEDIUMINT, BIGINT, LONGTEXT, + BIT, UNK = 255 }; @@ -137,6 +138,8 @@ constexpr int64_t TIANMU_BIGINT_MIN = NULL_VALUE_64; constexpr int32_t TIANMU_MAX_INDEX_COL_LEN_LARGE = 3072; constexpr int32_t TIANMU_MAX_INDEX_COL_LEN_SMALL = 767; +constexpr uint32_t kTianmuBitMaxPrec = 63; // in the future we'll expand to 64. + #define NULL_VALUE_D (*(double *)("\x01\x00\x00\x00\x00\x00\x00\x80")) #define TIANMU_INT_MIN (-2147483647) #define TIANMU_MEDIUMINT_MAX ((1 << 23) - 1) diff --git a/storage/tianmu/core/aggregator_basic.cpp b/storage/tianmu/core/aggregator_basic.cpp index a4fbdbe156..e1747647b9 100644 --- a/storage/tianmu/core/aggregator_basic.cpp +++ b/storage/tianmu/core/aggregator_basic.cpp @@ -570,8 +570,8 @@ types::BString AggregatorListT::GetValueT(unsigned char *buf) { if ((*p != static_cast(AggregatedValue_Mark::AM_NOT_FILL)) && (*p != static_cast( AggregatedValue_Mark::AM_STRING_NULL))) // empty string indicator: len==0 and nontrivial character - return types::BString("", 0, true); // empty string - return types::BString(); // null value + return types::BString("", 0, true); // empty string + return types::BString(); // null value } types::BString res(p, len); return res; diff --git a/storage/tianmu/core/data_type.cpp b/storage/tianmu/core/data_type.cpp index f55ab379d5..e8f784efc1 100644 --- a/storage/tianmu/core/data_type.cpp +++ b/storage/tianmu/core/data_type.cpp @@ -53,6 +53,11 @@ DataType::DataType(common::ColumnType atype, int prec, int scale, DTCollation co valtype = ValueType::VT_FIXED; fixmax = MAX(TIANMU_TINYINT_MAX, -TIANMU_TINYINT_MIN); break; + case common::ColumnType::BIT: + DEBUG_ASSERT((prec > 0) && (prec <= common::kTianmuBitMaxPrec)); + valtype = ValueType::VT_FIXED; + fixmax = MAX(TIANMU_TINYINT_MAX, -TIANMU_TINYINT_MIN); // TODO(fix max value with common::kTianmuBitMaxPrec) + break; case common::ColumnType::NUM: DEBUG_ASSERT((prec > 0) && (prec <= 19) && (fixscale >= 0)); diff --git a/storage/tianmu/core/engine.cpp b/storage/tianmu/core/engine.cpp index b7a3fec888..aafcf3686b 100644 --- a/storage/tianmu/core/engine.cpp +++ b/storage/tianmu/core/engine.cpp @@ -487,6 +487,14 @@ void Engine::EncodeRecord(const std::string &table_path, int table_id, Field **f *(int64_t *)ptr = v; ptr += sizeof(int64_t); } break; + case MYSQL_TYPE_BIT: { + int64_t v = f->val_int(); + ASSERT(v < 0, "bit type data should never less than 0."); + if (v > common::TIANMU_BIGINT_MAX) // how can v > bigint max ?? + v = common::TIANMU_BIGINT_MAX; // TODO(fix with bit prec) + *(int64_t *)ptr = v; + ptr += sizeof(int64_t); + } break; case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: { @@ -555,7 +563,6 @@ void Engine::EncodeRecord(const std::string &table_path, int table_id, Field **f case MYSQL_TYPE_ENUM: case MYSQL_TYPE_GEOMETRY: case MYSQL_TYPE_NULL: - case MYSQL_TYPE_BIT: default: throw common::Exception("unsupported mysql type " + std::to_string(f->type())); break; @@ -710,6 +717,13 @@ AttributeTypeInfo Engine::GetAttrTypeInfo(const Field &field) { } throw common::UnsupportedDataTypeException(); } + case MYSQL_TYPE_BIT: { + const Field_bit_as_char *f_bit = ((const Field_bit_as_char *)&field); + if (/*f_bit->field_length > 0 && */ f_bit->field_length <= common::kTianmuBitMaxPrec) + return AttributeTypeInfo(common::ColumnType::NUM, notnull, f_bit->field_length); + throw common::UnsupportedDataTypeException( + "The bit(M) type, M must be less than or equal to 63 in tianmu engine."); + } case MYSQL_TYPE_NEWDECIMAL: { const Field_new_decimal *fnd = ((const Field_new_decimal *)&field); if (/*fnd->precision > 0 && */ fnd->precision <= 18 /*&& fnd->dec >= 0*/ diff --git a/storage/tianmu/core/tianmu_attr_typeinfo.h b/storage/tianmu/core/tianmu_attr_typeinfo.h index ee0bd3e175..cc52d1fab6 100644 --- a/storage/tianmu/core/tianmu_attr_typeinfo.h +++ b/storage/tianmu/core/tianmu_attr_typeinfo.h @@ -41,16 +41,18 @@ class ATI { } static bool IsFixedNumericType(common::ColumnType attr_type) { return IsInteger32Type(attr_type) || attr_type == common::ColumnType::BIGINT || - attr_type == common::ColumnType::NUM; + attr_type == common::ColumnType::NUM || attr_type == common::ColumnType::BIT; } static bool IsRealType(common::ColumnType attr_type) { return attr_type == common::ColumnType::FLOAT || attr_type == common::ColumnType::REAL; } + + static bool IsBitType(common::ColumnType attr_type) { return attr_type == common::ColumnType::BIT; } + static bool IsNumericType(common::ColumnType attr_type) { - return IsInteger32Type(attr_type) || attr_type == common::ColumnType::BIGINT || - attr_type == common::ColumnType::NUM || attr_type == common::ColumnType::FLOAT || - attr_type == common::ColumnType::REAL; + return IsIntegerType(attr_type) || attr_type == common::ColumnType::NUM || attr_type == common::ColumnType::FLOAT || + attr_type == common::ColumnType::REAL || attr_type == common::ColumnType::BIT; } static bool IsBinType(common::ColumnType attr_type) {