Skip to content

Commit a27410e

Browse files
committed
fix: enforce minimum decimal precision and scale in NewArrowWriter and ColumnsToArrowSchema
1 parent 706e016 commit a27410e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

core/dbio/iop/arrow.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ type ArrowWriter struct {
361361
}
362362

363363
func NewArrowWriter(w io.Writer, columns Columns) (a *ArrowWriter, err error) {
364+
365+
// set minimum decimal precision/scale
366+
for i, col := range columns {
367+
columns[i].DbPrecision = lo.Ternary(col.DbPrecision < env.DdlMinDecLength, int(env.DdlMinDecLength), col.DbPrecision)
368+
columns[i].DbScale = lo.Ternary(col.DbScale < env.DdlMinDecScale, env.DdlMinDecScale, col.DbScale)
369+
}
370+
364371
a = &ArrowWriter{
365372
columns: columns,
366373
mem: memory.NewGoAllocator(),
@@ -506,8 +513,6 @@ func ColumnsToArrowSchema(columns Columns) *arrow.Schema {
506513
case FloatType:
507514
arrowType = arrow.PrimitiveTypes.Float64
508515
case DecimalType:
509-
col.DbPrecision = lo.Ternary(col.DbPrecision < env.DdlMinDecLength, int(env.DdlMinDecLength), col.DbPrecision)
510-
col.DbScale = lo.Ternary(col.DbScale < env.DdlMinDecScale, env.DdlMinDecScale, col.DbScale)
511516
arrowType = &arrow.Decimal128Type{Precision: int32(col.DbPrecision), Scale: int32(col.DbScale)}
512517
case DateType:
513518
arrowType = arrow.FixedWidthTypes.Date32

0 commit comments

Comments
 (0)