Skip to content

Commit 2845321

Browse files
replicators: Don't attempt to pad nulls in CHAR columns
CHAR columns are fixed-width, if the value is shorter than the column width, it should be padded with spaces. If the value column is NULL, it should not attempt to pad. Fixes: REA-4476 Change-Id: Ieafd250603295f07096fcf070da5bc85034bfef2 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/7633 Tested-by: Buildkite CI Reviewed-by: Jason Brown <[email protected]>
1 parent 3fe7927 commit 2845321

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

replicators/src/mysql_connector/snapshot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ fn mysql_row_to_noria_row(row: mysql::Row) -> ReadySetResult<Vec<readyset_data::
775775
// ENUM and SET columns are stored as integers and retrieved as strings. We don't need
776776
// padding.
777777
let require_padding = col.column_type() == ColumnType::MYSQL_TYPE_STRING
778+
&& val != mysql_common::value::Value::NULL
778779
&& !flags.contains(ColumnFlags::ENUM_FLAG)
779780
&& !flags.contains(ColumnFlags::SET_FLAG);
780781
match require_padding {

replicators/tests/tests.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,8 @@ async fn mysql_char_collation_padding_inner() -> ReadySetResult<()> {
810810
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
811811
INSERT INTO `col_pad` VALUES (1, 'ࠈࠈ');
812812
INSERT INTO `col_pad` VALUES (2, 'A');
813-
INSERT INTO `col_pad` VALUES (3, 'AAA');",
813+
INSERT INTO `col_pad` VALUES (3, 'AAA');
814+
INSERT INTO `col_pad` (id) VALUES (4);",
814815
)
815816
.await?;
816817
let (mut ctx, shutdown_tx) = TestHandle::start_noria(url.to_string(), None).await?;
@@ -840,6 +841,7 @@ async fn mysql_char_collation_padding_inner() -> ReadySetResult<()> {
840841
DfValue::Int(3),
841842
DfValue::TinyText(TinyText::from_arr(b"AAA")),
842843
],
844+
&[DfValue::Int(4), DfValue::None],
843845
],
844846
)
845847
.await?;
@@ -848,9 +850,10 @@ async fn mysql_char_collation_padding_inner() -> ReadySetResult<()> {
848850
client
849851
.query(
850852
"
851-
INSERT INTO `col_pad` VALUES (4, 'Bࠉ');
852-
INSERT INTO `col_pad` VALUES (5, 'B');
853-
INSERT INTO `col_pad` VALUES (6, 'BBB');
853+
INSERT INTO `col_pad` VALUES (5, 'Bࠉ');
854+
INSERT INTO `col_pad` VALUES (6, 'B');
855+
INSERT INTO `col_pad` VALUES (7, 'BBB');
856+
INSERT INTO `col_pad` (id) VALUES (8);
854857
",
855858
)
856859
.await
@@ -875,22 +878,24 @@ async fn mysql_char_collation_padding_inner() -> ReadySetResult<()> {
875878
DfValue::Int(3),
876879
DfValue::TinyText(TinyText::from_arr(b"AAA")),
877880
],
881+
&[DfValue::Int(4), DfValue::None],
878882
&[
879-
DfValue::Int(4),
883+
DfValue::Int(5),
880884
// 'Bࠉ ' is the UTF-8 encoding of U+E42 U+E0A089 U+20
881885
DfValue::TinyText(
882886
TinyText::from_slice(vec![0x42, 0xE0, 0xA0, 0x89, 0x20].as_slice())
883887
.unwrap_or_else(|_| TinyText::from_arr(b"")),
884888
),
885889
],
886890
&[
887-
DfValue::Int(5),
891+
DfValue::Int(6),
888892
DfValue::TinyText(TinyText::from_arr(b"B ")),
889893
],
890894
&[
891-
DfValue::Int(6),
895+
DfValue::Int(7),
892896
DfValue::TinyText(TinyText::from_arr(b"BBB")),
893897
],
898+
&[DfValue::Int(8), DfValue::None],
894899
],
895900
)
896901
.await?;

0 commit comments

Comments
 (0)