Skip to content

Commit

Permalink
feat(tianmu): rm some useless comment, bit type judge and add select.…
Browse files Browse the repository at this point in the history
…..where test case on bit types stoneatom#919
  • Loading branch information
hustjieke authored and konghaiya committed Mar 7, 2023
1 parent a8460fe commit 19c158d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
25 changes: 25 additions & 0 deletions mysql-test/suite/tianmu/r/bit_type.result
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,29 @@ ERROR 22001: Data too long for column 'bit32' at row 1
insert into bit_test values(b'1', b'1',b'1', b'1', b'1', b'11111111111111111111111111111111111111111111111111111111111111111');
ERROR 22001: Data too long for column 'bit63' at row 1
drop table bit_test;
CREATE TABLE bittest(a bit(8));
INSERT INTO bittest VALUES(b'00111001');
INSERT INTO bittest VALUES(b'00111101');
INSERT INTO bittest VALUES(b'00000001');
insert into bittest values(b'00111010');
insert into bittest values(b'00000000');
select a,a+0,bin(a),oct(a),hex(a) from bittest;
a a+0 bin(a) oct(a) hex(a)
9 57 111001 71 39
= 61 111101 75 3D
 1 1 1 1
: 58 111010 72 3A
0 0 0 0
select hex(a) from bittest where a='0';
hex(a)
0
select hex(a) from bittest where a=0;
hex(a)
0
select hex(a) from bittest where a=48;
hex(a)
select hex(a) from bittest where a=57;
hex(a)
39
drop table bittest;
drop database test_bit;
14 changes: 14 additions & 0 deletions mysql-test/suite/tianmu/t/bit_type.test
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,18 @@ insert into bit_test values(b'1', b'1',b'1',b'1', b'1111111111111111111111111111
insert into bit_test values(b'1', b'1',b'1', b'1', b'1', b'11111111111111111111111111111111111111111111111111111111111111111');
drop table bit_test;

# test select with filters.
CREATE TABLE bittest(a bit(8));
INSERT INTO bittest VALUES(b'00111001');
INSERT INTO bittest VALUES(b'00111101');
INSERT INTO bittest VALUES(b'00000001');
insert into bittest values(b'00111010');
insert into bittest values(b'00000000');
select a,a+0,bin(a),oct(a),hex(a) from bittest;
select hex(a) from bittest where a='0';
select hex(a) from bittest where a=0;
select hex(a) from bittest where a=48;
select hex(a) from bittest where a=57;
drop table bittest;

drop database test_bit;
4 changes: 2 additions & 2 deletions storage/tianmu/common/txt_data_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ std::unique_ptr<exporter::DataExporter> TxtDataFormat::CreateDataExporter(const
//! or number of chars if collation not binary and ColumnType::STRING or ColumnType::VARCHAR
uint TxtDataFormat::StaticExtrnalSize(ColumnType attrt, uint precision, int scale, const DTCollation *col) {
if (attrt == ColumnType::NUM)
// because "-0.1" may be declared as DEC(1,1), so 18 decimal places may take
// 21 characters, "-0.xxxxx...", "-", "0", "." need extra 3 bytes, 21 = 3 + 18.
return 1 + precision + (scale ? 1 : 0) + (precision == (uint)scale ? 1 : 0);
// because "-0.1" may be declared as DEC(1,1), so 18 decimal places may take
// 21 characters, "-0.xxxxx...", "-", "0", "." need extra 3 bytes, 21 = 3 + 18.
if (attrt == ColumnType::BIT) // unsigned value.
return precision; // e.g.: if precison = 4, bit value max display will be "1010", one byte one digit.
if (attrt == ColumnType::BYTE || attrt == ColumnType::VARBYTE || attrt == ColumnType::BIN)
Expand Down
1 change: 0 additions & 1 deletion storage/tianmu/core/data_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ DataType::DataType(common::ColumnType atype, int prec, int scale, DTCollation co
fixmax = MAX(TIANMU_TINYINT_MAX, -TIANMU_TINYINT_MIN);
break;
case common::ColumnType::BIT:
DEBUG_ASSERT((prec > 0) && (prec <= common::TIANMU_BIT_MAX_PREC));
valtype = ValueType::VT_FIXED;
fixmax = MAX(common::TIANMU_BIGINT_MAX,
-common::TIANMU_BIGINT_MIN); // TODO(fix max value with common::TIANMU_BIT_MAX_PREC)
Expand Down
1 change: 0 additions & 1 deletion storage/tianmu/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ void Engine::EncodeInsertRecord(const std::string &table_path, int table_id, Fie
} break;
case MYSQL_TYPE_BIT: {
int64_t v = f->val_int();
// DEBUG_ASSERT(v < 0, "bit type data should never less than 0.");
// open it when support M = 64, now all value parsed is < 0.
if (v > common::TIANMU_BIGINT_MAX) // v > bigint max when uint64_t is supported
v = common::TIANMU_BIGINT_MAX; // TODO(fix with bit prec)
Expand Down
8 changes: 5 additions & 3 deletions storage/tianmu/core/tianmu_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,11 @@ types::TianmuDataType &TianmuAttr::GetValueData(size_t obj, types::TianmuDataTyp
else if (ATI::IsDateTimeType(a_type)) {
((types::TianmuDateTime &) value) = types::TianmuDateTime(this->GetNotNullValueInt64(obj), a_type);
} else if (ATI::IsRealType(a_type))
((types::TianmuNum &) value).Assign(this->GetNotNullValueInt64(obj), 0, true, a_type);
else
((types::TianmuNum &) value).Assign(this->GetNotNullValueInt64(obj), Type().GetScale());
((types::TianmuNum &)value).Assign(this->GetNotNullValueInt64(obj), 0, true, a_type);
else if (ATI::IsBitType(a_type)) {
((types::TianmuNum &)value).Assign(this->GetNotNullValueInt64(obj), Type().GetScale(), false, a_type);
} else
((types::TianmuNum &)value).Assign(this->GetNotNullValueInt64(obj), Type().GetScale());
}
return value;
}
Expand Down

0 comments on commit 19c158d

Please sign in to comment.