Skip to content

[Bug]: LOAD DATA parquet same-scale DECIMAL path bypasses target precision validation #26265

Closed

Description

@XuPeng-SH

Bug Report

Description

This is a follow-up to #25473 and merged PR #26212.

PR #26212 fixed Parquet DECIMAL rescaling when the source and target scales differ, but the new dispatch still has a gap when the source Parquet DECIMAL scale already matches the target MatrixOne DECIMAL scale.

In that same-scale case, logical DECIMAL columns still go through the raw decodeDecimal{64,128,256}Values path via canUseRawDecimalMapping. That path only checks whether the value fits the storage width (DECIMAL64/128/256), not whether it fits the target column's declared DECIMAL(precision,scale).

As a result, schema-invalid values can be loaded silently into narrower target precisions.

For example, a Parquet DECIMAL(10,2) value 12345.67 can still be accepted into a MatrixOne target column DECIMAL(4,2), even though DECIMAL(4,2) should reject anything outside [-99.99, 99.99].

Version

Observed from the merged logic in PR #26212 (81890b81a1ef479e6452ae81a0067113bdad33e8).

Steps to Reproduce

Generate a Parquet file with a logical DECIMAL column whose scale already matches the target, but whose precision exceeds the target column:

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

path = '/tmp/decimal_same_scale_precision.parquet'
vals = [Decimal('12345.67')]
pq.write_table(
    pa.Table.from_arrays(
        [pa.array(vals, pa.decimal128(10, 2))],
        names=['dec_col'],
    ),
    path,
)

Run SQL:

drop database if exists parquet_decimal_same_scale_precision;
create database parquet_decimal_same_scale_precision;
use parquet_decimal_same_scale_precision;

create table t_bad(dec_col decimal(4,2));
load data infile {'filepath'='/tmp/decimal_same_scale_precision.parquet', 'format'='parquet'} into table t_bad;
select * from t_bad;

Actual Behavior

The load can succeed and store 12345.67 in DECIMAL(4,2).

Expected Behavior

The load should be rejected with a DECIMAL overflow / precision error, because the target column is DECIMAL(4,2).

Root Cause

The merged dispatch uses:

  • canUseRawDecimalMapping(...) to keep same-scale logical DECIMALs on the raw fast path
  • raw decoders decodeDecimal64Values / decodeDecimal128Values / decodeDecimal256Values
  • copyPageToVec / copyDictPageToVec

That path does not receive the target column's declared precision, so it cannot enforce DECIMAL(width,scale) bounds. The new precision-aware helpers (parquetDecimalValueToDecimal64/128/256) are only used when canUseRawDecimalMapping(...) returns false.

Suggested Fix

Only use the raw fast path when both of these are provably safe:

  1. source scale == target scale
  2. source value domain is guaranteed to fit the target precision

Otherwise, logical DECIMAL values should go through the new precision-aware parquetDecimalValueToDecimal64/128/256 helpers even when the scales already match.

Please also add a regression test for:

  • same-scale precision overflow
  • both plain and dictionary Parquet pages
  • DECIMAL64 / DECIMAL128 / DECIMAL256 targets as applicable

Activity

  1. added
    kind/bug
    on Jul 27, 2026
  2. added theissue type on Jul 27, 2026
  3. added
    severity/s0
    and removed on Jul 27, 2026
  4. added
    ai-easy
    on Jul 29, 2026
  5. Repository owner unassigned on Jul 29, 2026
  6. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main(截至 2026-07-30 16:30,Asia/Shanghai)
    • commit:41332062a6740978f269088a92ee362a888c7bd7
    • 部署方式:从该官方 commit 源码构建;etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口 127.0.0.1:6001
    • 测试日期:2026-07-30

    原问题验证

    按 issue 原始方法生成同 scale、超出目标 precision 的 Parquet DECIMAL,分别覆盖 plain page 与 dictionary page。目标 DECIMAL(4,2) 和 DECIMAL(18,2) 均返回 parquet decimal value overflows DECIMAL(...),失败后目标表行数保持 0;完整黑盒独立执行 3 轮,3/3 一致。

    Happy Path 覆盖

    1. 同 scale 且在范围内的 12.34、-99.99 可正常写入 DECIMAL(4,2),排序查询值精确一致。
    2. DECIMAL64、DECIMAL128 两种目标宽度的黑盒路径均完成验证;修复 UT 另覆盖 DECIMAL256。

    Unhappy Path 覆盖

    1. plain page 中超 precision 值被拒绝,目标表保持 0 行。
    2. dictionary page 中重复超 precision 值被拒绝,目标表保持 0 行。
    3. 失败后同一连接继续建表、加载合法文件和查询均正常,未出现部分写入或会话污染。

    白盒验证

    TestParquetDecimalSameScalePrecisionOverflow 连续 3 轮通过,覆盖 plain/dictionary × DECIMAL64/128/256;external 定向 -race 通过。

    回归测试

    修复提交 52fdae7c9(#26274)已加入 pkg/sql/colexec/external/parquet_test.go。

    测试证据

    完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与 -race 输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b

    测试结论

    测试通过。

  7. Ariznawlll commented on Aug 3, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:6b3ad84c9d01d453c2bcdd0f440637350e3aa8c6
    • 测试日期:2026-08-02
    • 部署方式:官方 main 源码构建的 2 CN + 1 TN 本地集群;通过第二个 CN 的 MySQL 入口执行真实 LOAD DATA ... FORMAT='parquet' PARALLEL 'true'。

    原问题验证

    使用真实同 scale Parquet DECIMAL 文件加载到更小 precision 的目标列。每轮覆盖 plain 与 RLE_DICTIONARY 两种页编码,以及目标 DECIMAL(4,2)、DECIMAL(19,2)、DECIMAL(39,2);完整黑盒连续 3 轮均返回 20301 parquet decimal value overflows DECIMAL(p,2)。每个失败用例后立即查询目标表,行数均为 0。

    Happy Path 覆盖

    1. 对应 precision 的正、负最大合法同 scale DECIMAL 值均可成功导入并按精确字符值查询返回。
    2. plain 与 dictionary 两种页编码均覆盖。
    3. TestParquetDecimalSameScalePrecisionOverflow 连续 3 轮通过,覆盖 DECIMAL64/128/256。

    Unhappy Path 覆盖

    1. 同 scale 超过 DECIMAL(4,2) precision:plain/dictionary 均拒绝,0 行写入。
    2. 同 scale 超过 DECIMAL(19,2) precision:plain/dictionary 均拒绝,0 行写入。
    3. 同 scale 超过 DECIMAL(39,2) precision:plain/dictionary 均拒绝,0 行写入。
    4. 每次拒绝后复用同一连接创建目标表并加载合法文件,均正常,未出现部分写入或会话污染。

    白盒验证

    go test ./pkg/sql/colexec/external -count=3 -run '^(TestParquetDecimalSameScalePrecisionOverflow|TestParquet_StringToDatetimeOptional)$' 通过(ok github.com/matrixorigin/matrixone/pkg/sql/colexec/external 0.721s)。对应单测位于 pkg/sql/colexec/external/parquet_test.go。

    回归测试

    当前已有同问题的 external 单元回归;本轮验证的真实 LOAD DATA 结果可作为后续稳定 motr Parquet 黑盒 case 的断言基线,但本次未修改 motr。

    测试证据

    黑盒脚本完整连续 3 轮输出中,6 个超 precision 组合均返回 20301,并对每个目标表断言 COUNT(*)=0;合法正负边界值逐行比对成功。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugphase/testingseverity/s0

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions