@@ -464,3 +464,74 @@ func (t *testSyncerSuite) TestMysqlBinlogCodec() {
464464 require .NoError (t .T (), err )
465465 }
466466}
467+
468+ func (t * testSyncerSuite ) TestFloatWithTrailingZeros () {
469+ t .setupTest (mysql .MySQLFlavor )
470+
471+ str := `DROP TABLE IF EXISTS test_float_zeros`
472+ t .testExecute (str )
473+
474+ // Create table with both float and double columns
475+ str = `CREATE TABLE test_float_zeros (
476+ id INT PRIMARY KEY,
477+ f_val FLOAT,
478+ d_val DOUBLE
479+ )`
480+ t .testExecute (str )
481+
482+ // Test with useFloatWithTrailingZero = true
483+ t .b .cfg .UseFloatWithTrailingZero = true
484+ t .testFloatWithTrailingZerosCase (true )
485+
486+ // Test with useFloatWithTrailingZero = false
487+ t .b .cfg .UseFloatWithTrailingZero = false
488+ t .testFloatWithTrailingZerosCase (false )
489+ }
490+
491+ func (t * testSyncerSuite ) testFloatWithTrailingZerosCase (useTrailingZero bool ) {
492+ // Insert values with trailing zeros
493+ t .testExecute (`INSERT INTO test_float_zeros VALUES (1, 5.1, 5.1)` )
494+ t .testExecute (`INSERT INTO test_float_zeros VALUES (2, 1.100, 1.100)` )
495+
496+ // Get current position
497+ r , err := t .c .Execute ("SHOW MASTER STATUS" )
498+ require .NoError (t .T (), err )
499+ binFile , _ := r .GetString (0 , 0 )
500+ binPos , _ := r .GetInt (0 , 1 )
501+
502+ // Start syncing from current position
503+ s , err := t .b .StartSync (mysql.Position {Name : binFile , Pos : uint32 (binPos )})
504+ require .NoError (t .T (), err )
505+
506+ // Insert another row to trigger binlog events
507+ t .testExecute (`INSERT INTO test_float_zeros VALUES (3, 3.0, 3.0)` )
508+
509+ // Read events and verify
510+ ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Second )
511+ defer cancel ()
512+
513+ for {
514+ evt , err := s .GetEvent (ctx )
515+ require .NoError (t .T (), err )
516+
517+ // We're interested in RowsEvent
518+ if evt .Header .EventType != WRITE_ROWS_EVENTv2 {
519+ continue
520+ }
521+
522+ // Type assert to RowsEvent
523+ rowsEvent := evt .Event .(* RowsEvent )
524+ for _ , row := range rowsEvent .Rows {
525+ // The third row should contain our test values
526+ if row [0 ].(int32 ) == 3 {
527+ // Float should preserve trailing zeros if useFloatWithTrailingZero is true
528+ fVal := row [1 ].(float32 )
529+ if useTrailingZero {
530+ require .Equal (t .T (), "3.0" , fmt .Sprintf ("%.1f" , fVal ))
531+ } else {
532+ require .Equal (t .T (), "3" , fmt .Sprintf ("%.1f" , fVal ))
533+ }
534+ }
535+ }
536+ }
537+ }
0 commit comments