Skip to content

[Bug]: LOAD DATA parquet decimal scale conversion shifts decimal point #25473

Closed

Description

@Ariznawlll

Bug Report

Description

LOAD DATA INFILE ... format='parquet' handles Parquet DECIMAL values incorrectly when loading into a MatrixOne DECIMAL column with a smaller scale.

When the source Parquet column is decimal128(10,3) and the target MatrixOne column is decimal(10,2), the value is scaled incorrectly by one decimal digit instead of being rounded/truncated to the target scale.

For example:

  • Parquet value 1.235 becomes 12.35 in MO decimal(10,2).
  • Parquet value -1.235 becomes -12.35.
  • Parquet value 12.345 becomes 123.45.

The same Parquet file loads correctly into MO decimal(10,3) and into varchar, so the source file itself is valid. The problem appears when converting a Parquet decimal to a target MO decimal with smaller scale.

Version

Reproduced on:

select git_version();
-- 2a008285e

Steps to Reproduce

Generate a Parquet file with a decimal128(10,3) column:

from decimal import Decimal
import pyarrow as pa
import pyarrow.parquet as pq

path = '/tmp/decimal_scale.parquet'
vals = [Decimal('1.235'), Decimal('-1.235'), Decimal('12.345'), Decimal('0.001')]
pq.write_table(
    pa.Table.from_arrays(
        [pa.array(vals, pa.decimal128(10, 3))],
        names=['dec_col'],
    ),
    path,
)

Run SQL:

drop database if exists parquet_decimal_scale_check;
create database parquet_decimal_scale_check;
use parquet_decimal_scale_check;

create table t_dec3(dec_col decimal(10,3));
load data infile {'filepath'='/tmp/decimal_scale.parquet', 'format'='parquet'} into table t_dec3;
select * from t_dec3 order by dec_col;

create table t_dec2(dec_col decimal(10,2));
load data infile {'filepath'='/tmp/decimal_scale.parquet', 'format'='parquet'} into table t_dec2;
select * from t_dec2 order by dec_col;

create table t_v(dec_col varchar(32));
load data infile {'filepath'='/tmp/decimal_scale.parquet', 'format'='parquet'} into table t_v;
select * from t_v order by dec_col;

Actual Behavior

Loading into the same scale is correct:

t_dec3:
-1.235
0.001
1.235
12.345

Loading into varchar also preserves the source values:

t_v:
-1.235
0.001
1.235
12.345

But loading into decimal(10,2) shifts the decimal point:

t_dec2:
-12.35
0.01
12.35
123.45

Expected Behavior

Loading Parquet decimal128(10,3) into MO decimal(10,2) should round or truncate to the target scale, but should not shift the decimal point.

Expected values should be similar to:

-1.24 / -1.23
0.00 / 0.00
1.24 / 1.23
12.35 / 12.34

The exact rounding/truncation policy can follow MatrixOne's existing decimal cast behavior, but the magnitude should remain correct.

Additional Notes

This was found while validating the Parquet LOAD DATA INFILE feature. Other Parquet type mappings tested successfully, including signed/unsigned integers, float/double, matching-scale decimals, date/datetime/time, varchar/text, varbinary, JSON, bool, NULL, and several unhappy paths.

Activity

  1. added this to the MO-202607 milestone on Jul 6, 2026
  2. added
    kind/bug
    on Jul 6, 2026
  3. added theissue type on Jul 6, 2026
  4. Ariznawlll commented on Jul 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支完成验证,当前问题已修复。

    测试版本:

    • MatrixOne branch:main
    • MatrixOne commit:c8e443bf8610b2af4333ad943ba2075485b16cf8
    • 修复提交:81890b81a(fix(external): rescale parquet decimals on load)

    测试数据:

    • 使用真实 Parquet 文件;
    • 源字段类型为 nullable decimal128(10,3);
    • 数据为 1.235、-1.235、12.345、0.001、9999999.995、NULL。

    测试步骤:

    1. 把同一份 Parquet 文件加载到 DECIMAL(10,2),验证缩小 scale 时的转换结果。
    2. 加载到 DECIMAL(10,3),验证相同 scale 保留原值。
    3. 加载到 DECIMAL(11,4),验证扩大 scale 时正确补零。
    4. 加载到 VARCHAR(32) 作为对照,确认源 Parquet 值正确。
    5. 补充 decimal scale conversion UT 连续 3 轮,并使用 motr 串行、并行重复执行。

    关键结果:

    Parquet decimal(10,3) -> MO decimal(10,2)
    
    -1.235      -> -1.24
     0.001      ->  0.00
     1.235      ->  1.24
    12.345      -> 12.35
    9999999.995 -> 10000000.00
    NULL        -> NULL
    

    加载到相同 scale、扩大 scale 和 VARCHAR 的对照结果也全部正确。未再出现 1.235 -> 12.35 这种小数点整体右移的问题。

    已加入 motr 黑盒回归:

    该 case 内嵌固定 Parquet fixture,通过 MatrixOne stage 上传后执行真实 LOAD DATA ... format='parquet',不依赖 runner 额外安装 pyarrow。motr 在最新 main 上串行 3 轮和并行 3 轮均通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions