Repository navigation
Description
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:
- source scale == target scale
- 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
Ariznawlll commentedon Jul 30, 2026
测试版本
main(截至 2026-07-30 16:30,Asia/Shanghai)41332062a6740978f269088a92ee362a888c7bd7etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口127.0.0.1:6001原问题验证
按 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 覆盖
12.34、-99.99可正常写入DECIMAL(4,2),排序查询值精确一致。Unhappy Path 覆盖
白盒验证
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测试结论
测试通过。
Ariznawlll commentedon Aug 3, 2026
测试版本
main6b3ad84c9d01d453c2bcdd0f440637350e3aa8c6LOAD 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 覆盖
TestParquetDecimalSameScalePrecisionOverflow连续 3 轮通过,覆盖 DECIMAL64/128/256。Unhappy Path 覆盖
DECIMAL(4,2)precision:plain/dictionary 均拒绝,0 行写入。DECIMAL(19,2)precision:plain/dictionary 均拒绝,0 行写入。DECIMAL(39,2)precision:plain/dictionary 均拒绝,0 行写入。白盒验证
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;合法正负边界值逐行比对成功。测试结论
测试通过。