Skip to content

Commit

Permalink
add test & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiaoying committed Oct 2, 2024
1 parent 06e90d1 commit 4e14d32
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions connectorx-python/connectorx/tests/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ def test_mysql_types_binary(mysql_url: str) -> None:
"test_mediumtext": pd.Series(
[None, b"", b"medium text!!!!"], dtype="object"
),
"test_bit": pd.Series(
[b'\x17', b'\x18', None]
),
},
)
assert_frame_equal(df, expected, check_names=True)
Expand Down Expand Up @@ -406,6 +409,9 @@ def test_mysql_types_text(mysql_url: str) -> None:
"test_mediumtext": pd.Series(
[None, b"", b"medium text!!!!"], dtype="object"
),
"test_bit": pd.Series(
[b'\x17', b'\x18', None]
),
},
)
assert_frame_equal(df, expected, check_names=True)
Expand Down
2 changes: 2 additions & 0 deletions connectorx-python/src/pandas/transports/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl_transport!(
{ MediumBlob[Vec<u8>] => Bytes[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => Bytes[Vec<u8>] | conversion none }
{ Json[Value] => String[String] | conversion option }
{ Bit[Vec<u8>] => Bytes[Vec<u8>] | conversion none }
}
);

Expand Down Expand Up @@ -81,6 +82,7 @@ impl_transport!(
{ MediumBlob[Vec<u8>] => Bytes[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => Bytes[Vec<u8>] | conversion none }
{ Json[Value] => String[String] | conversion option }
{ Bit[Vec<u8>] => Bytes[Vec<u8>] | conversion none }
}
);

Expand Down
5 changes: 3 additions & 2 deletions connectorx/src/sources/mysql/typesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum MySQLTypeSystem {
MediumBlob(bool),
LongBlob(bool),
Json(bool),
Bit(bool),
}

impl_typesystem! {
Expand All @@ -51,7 +52,7 @@ impl_typesystem! {
{ Time => NaiveTime }
{ Decimal => Decimal }
{ Char | VarChar | Enum => String }
{ TinyBlob | Blob | MediumBlob | LongBlob => Vec<u8>}
{ TinyBlob | Blob | MediumBlob | LongBlob | Bit => Vec<u8>}
{ Json => Value }
}
}
Expand Down Expand Up @@ -116,7 +117,7 @@ impl<'a> From<(&'a ColumnType, &'a ColumnFlags)> for MySQLTypeSystem {
ColumnType::MYSQL_TYPE_LONG_BLOB => LongBlob(null_ok),
ColumnType::MYSQL_TYPE_JSON => Json(null_ok),
ColumnType::MYSQL_TYPE_VARCHAR => VarChar(null_ok),
ColumnType::MYSQL_TYPE_BIT => LongLong(null_ok),
ColumnType::MYSQL_TYPE_BIT => Bit(null_ok),
_ => unimplemented!("{}", format!("{:?}", ty)),
}
}
Expand Down
2 changes: 2 additions & 0 deletions connectorx/src/transports/mysql_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl_transport!(
{ MediumBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ Json[Value] => LargeUtf8[String] | conversion option }
{ Bit[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
}
);

Expand Down Expand Up @@ -100,6 +101,7 @@ impl_transport!(
{ MediumBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ Json[Value] => LargeUtf8[String] | conversion option }
{ Bit[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
}
);

Expand Down
2 changes: 2 additions & 0 deletions connectorx/src/transports/mysql_arrow2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl_transport!(
{ Blob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ MediumBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ Bit[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
}
);

Expand Down Expand Up @@ -100,6 +101,7 @@ impl_transport!(
{ Blob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ MediumBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ Bit[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
}
);

Expand Down
2 changes: 2 additions & 0 deletions connectorx/src/transports/mysql_arrowstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl_transport!(
{ MediumBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ Json[Value] => LargeUtf8[String] | conversion option }
{ Bit[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
}
);

Expand Down Expand Up @@ -99,6 +100,7 @@ impl_transport!(
{ MediumBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ LongBlob[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
{ Json[Value] => LargeUtf8[String] | conversion option }
{ Bit[Vec<u8>] => LargeBinary[Vec<u8>] | conversion none }
}
);

Expand Down
9 changes: 5 additions & 4 deletions scripts/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ CREATE TABLE IF NOT EXISTS test_types(
test_longblob LONGBLOB,
test_enum ENUM('apple', 'banana', 'orange', 'mango'),
test_json JSON,
test_mediumtext MEDIUMTEXT
test_mediumtext MEDIUMTEXT,
test_bit BIT(5)
);

INSERT INTO test_types VALUES ('1970-01-01 00:00:01', NULL, '00:00:00', '1970-01-01 00:00:01', 1.1, 1, NULL, 'char1', -128, -32768, -8388608, -2147483648, -9223372036854775808, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, -2.2E-308, 1.2345, 1901, NULL, NULL, NULL, NULL, 'apple', '{"name": "piggy", "age": 1}', NULL);
INSERT INTO test_types VALUES ('2038-01-19 00:00:00', '1970-01-01', NULL, '2038-01-19 00:0:00', NULL, 2, 'varchar2', NULL, 127, 32767, 8388607, 2147483647, 9223372036854775807, 255, 65535, 16777215, 4294967295, 1.844674407E19, 2147483647, 65535, -1.1E-38, NULL, -1.1E-3, 2155, 'tinyblob2', 'blobblobblobblob2', 'mediumblob2', 'longblob2', NULL, '{"name": "kitty", "age": 2}', '');
INSERT INTO test_types VALUES (NULL, '2038-01-19', '23:59:59', NULL, 3.3, NULL, 'varchar3', 'char3', NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, -2147483648, 0, 3.4E38, 1.7E308, 1.7E30, NULL, 'tinyblob3', 'blobblobblobblob3', 'mediumblob3', 'longblob3', 'mango', NULL, 'medium text!!!!');
INSERT INTO test_types VALUES ('1970-01-01 00:00:01', NULL, '00:00:00', '1970-01-01 00:00:01', 1.1, 1, NULL, 'char1', -128, -32768, -8388608, -2147483648, -9223372036854775808, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, -2.2E-308, 1.2345, 1901, NULL, NULL, NULL, NULL, 'apple', '{"name": "piggy", "age": 1}', NULL, b'10111');
INSERT INTO test_types VALUES ('2038-01-19 00:00:00', '1970-01-01', NULL, '2038-01-19 00:0:00', NULL, 2, 'varchar2', NULL, 127, 32767, 8388607, 2147483647, 9223372036854775807, 255, 65535, 16777215, 4294967295, 1.844674407E19, 2147483647, 65535, -1.1E-38, NULL, -1.1E-3, 2155, 'tinyblob2', 'blobblobblobblob2', 'mediumblob2', 'longblob2', NULL, '{"name": "kitty", "age": 2}', '', b'11000');
INSERT INTO test_types VALUES (NULL, '2038-01-19', '23:59:59', NULL, 3.3, NULL, 'varchar3', 'char3', NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, -2147483648, 0, 3.4E38, 1.7E308, 1.7E30, NULL, 'tinyblob3', 'blobblobblobblob3', 'mediumblob3', 'longblob3', 'mango', NULL, 'medium text!!!!', NULL);

0 comments on commit 4e14d32

Please sign in to comment.