@@ -567,3 +567,61 @@ func Test_Column_SimpleAggregateFunc(t *testing.T) {
567567 }
568568 }
569569}
570+
571+ func Test_Column_Decimal64 (t * testing.T ) {
572+ var (
573+ buf bytes.Buffer
574+ encoder = binary .NewEncoder (& buf )
575+ decoder = binary .NewDecoder (& buf )
576+ )
577+ if columnBase , err := columns .Factory ("column_name" , "Decimal(18,5)" , time .Local ); assert .NoError (t , err ) {
578+
579+ decimalCol , ok := columnBase .(* columns.Decimal )
580+ if assert .True (t , ok ) {
581+ assert .Equal (t , 18 , decimalCol .GetPrecision ())
582+ assert .Equal (t , 5 , decimalCol .GetScale ())
583+ }
584+
585+ if err := columnBase .Write (encoder , float64 (1123.12345 )); assert .NoError (t , err ) {
586+ if v , err := columnBase .Read (decoder ); assert .NoError (t , err ) {
587+ assert .Equal (t , int64 (112312345 ), v )
588+ }
589+ }
590+ if assert .Equal (t , "column_name" , columnBase .Name ()) && assert .Equal (t , "Decimal(18,5)" , columnBase .CHType ()) {
591+ assert .Equal (t , reflect .Int64 , columnBase .ScanType ().Kind ())
592+ }
593+ }
594+ }
595+
596+ func Test_Column_NullableDecimal64 (t * testing.T ) {
597+ var (
598+ buf bytes.Buffer
599+ encoder = binary .NewEncoder (& buf )
600+ decoder = binary .NewDecoder (& buf )
601+ )
602+ if columnBase , err := columns .Factory ("column_name" , "Nullable(Decimal(18,5))" , time .Local ); assert .NoError (t , err ) {
603+
604+ nullableCol , ok := columnBase .(* columns.Nullable )
605+ if assert .True (t , ok ) {
606+ decimalCol := nullableCol .GetColumn ().(* columns.Decimal )
607+ assert .Equal (t , 18 , decimalCol .GetPrecision ())
608+ assert .Equal (t , 5 , decimalCol .GetScale ())
609+ }
610+
611+ if err := nullableCol .WriteNull (encoder , encoder , float64 (1123.12345 )); assert .NoError (t , err ) {
612+ if v , err := nullableCol .ReadNull (decoder , 1 ); assert .NoError (t , err ) {
613+ assert .Equal (t , int64 (112312345 ), v [0 ])
614+ }
615+ }
616+
617+ if err := nullableCol .WriteNull (encoder , encoder , nil ); assert .NoError (t , err ) {
618+ if v , err := nullableCol .ReadNull (decoder , 1 ); assert .NoError (t , err ) {
619+ assert .Nil (t , v [0 ])
620+ }
621+ }
622+
623+ if assert .Equal (t , "column_name" , columnBase .Name ()) && assert .Equal (t , "Nullable(Decimal(18,5))" , columnBase .CHType ()) {
624+ assert .Equal (t , reflect .Int64 , columnBase .ScanType ().Kind ())
625+ }
626+ }
627+ }
0 commit comments