duckdb / duckdb_mysql

MIT License
45 stars 10 forks source link

BIT(1) Column incorrectly being parsed as blob #25

Closed ShahBinoy closed 7 months ago

ShahBinoy commented 7 months ago

DuckDb version: 0.9.2 MySQL Version: 8.x

D select id,value_as_boolean,is_deleted from user_profile_value where id = 17999;
┌───────┬──────────────────┬────────────┐
│  id   │ value_as_boolean │ is_deleted │
│ int64 │       blob       │    blob    │
├───────┼──────────────────┼────────────┤
│ 17999 │ \x00             │ \x00       │
└───────┴──────────────────┴────────────┘

D describe user_profile_value;
┌───────────────────────┬─────────────┬─────────┬─────────┬─────────┬───────┐
│      column_name      │ column_type │  null   │   key   │ default │ extra │
│        varchar        │   varchar   │ varchar │ varchar │ varchar │ int32 │
├───────────────────────┼─────────────┼─────────┼─────────┼─────────┼───────┤
│ id                    │ BIGINT      │ NO      │         │         │       │
│ user_profile_field_id │ BIGINT      │ YES     │         │         │       │
│ value_as_string       │ VARCHAR     │ YES     │         │         │       │
│ value_as_number       │ DOUBLE      │ YES     │         │         │       │
│ value_as_file         │ VARCHAR     │ YES     │         │         │       │
│ value_as_boolean      │ BLOB        │ YES     │         │         │       │
│ unit_id               │ BIGINT      │ YES     │         │         │       │
│ file_name             │ VARCHAR     │ YES     │         │         │       │
│ file_size             │ BIGINT      │ YES     │         │         │       │
│ created_on            │ BIGINT      │ YES     │         │         │       │
├───────────────────────┴─────────────┴─────────┴─────────┴─────────┴───────┤
│ 14 rows                                                         6 columns │
└───────────────────────────────────────────────────────────────────────────┘

The actual type of value_as_boolean is bit(1) and values are representative of 0 and 1 for true/false.

Below is the describe from the source schema in mysql

Field Type Null Key Default Extra
id bigint NO PRI auto_increment
user_profile_field_id bigint YES MUL ""
value_as_string varchar(4096) YES MUL ""
value_as_number double YES MUL ""
value_as_file varchar(1024) YES "" ""
value_as_boolean bit(1) YES MUL ""
unit_id bigint YES MUL ""
file_name varchar(255) YES "" ""
file_size bigint YES "" ""
created_on bigint YES "" ""
Mytherin commented 7 months ago

Thanks for the report! In my opinion it is rather strange to use BIT(1) as a boolean field - but it seems that's the way it's done in MySQL :) I've pushed a fix for this in #26.

As a work-around you could always convert a blob to a boolean by doing a comparison, e.g. value_as_boolean=blob '\x01'.