Skip to content

Conversation

@amorynan
Copy link
Contributor

@amorynan amorynan commented Mar 12, 2025

What problem does this PR solve?

before this pr , we deduce the precision of the function named_struct containing the decimal type is same with the precision of the decimal type in select . In this case we can not make right named_struct for multiple decimal value
like :

mysql> create table t01 (a decimal(6,3), d struct<col:bigint, col1:decimal(7,2)>) properties ("replication_num"="1");
Query OK, 0 rows affected (0.14 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 345.24));
Query OK, 1 row affected (0.26 sec)
{'label':'label_a2dc895ee7834701_841639ad6d93923f', 'status':'VISIBLE', 'txnId':'9010'}

mysql> select named_struct("col_11", a, "col_12", d) from t01;
+--------------------------------------------------------+
| named_struct("col_11", a, "col_12", d)                 |
+--------------------------------------------------------+
| {"col_11":123.321, "col_12":{"col":1, "col1":345.240}} |
+--------------------------------------------------------+
1 row in set (0.17 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 12345.24));
Query OK, 1 row affected (0.17 sec)
{'label':'label_77ed6047f6a6494d_810c26becfd0535c', 'status':'VISIBLE', 'txnId':'9011'}
mysql> select named_struct("col_11", a, "col_12", d) from t01;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[E-255]Arithmetic overflow when converting value 12345.24 from type Decimal(7, 2) to type Decimal(6, 3)
mysql> desc verbose select named_struct("col_11", a, "col_12", d) from t01;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PLAN FRAGMENT 0                                                                                                                                                                              |
|   OUTPUT EXPRS:                                                                                                                                                                              |
|     named_struct("col_11", a, "col_12", d)[#2]                                                                                                                                               |
|   PARTITION: RANDOM                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                  |
|                                                                                                                                                                                              |
|   VRESULT SINK                                                                                                                                                                               |
|      MYSQL_PROTOCAL                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   0:VOlapScanNode(50)                                                                                                                                                                        |
|      TABLE: tt.t01(t01), PREAGGREGATION: ON                                                                                                                                                  |
|      partitions=1/1 (t01)                                                                                                                                                                    |
|      tablets=10/10, tabletList=1741751856342,1741751856344,1741751856346 ...                                                                                                                 |
|      cardinality=2, avgRowSize=2955.0, numNodes=1                                                                                                                                            |
|      pushAggOp=NONE                                                                                                                                                                          |
|      final projections: named_struct('col_11', a[#0], 'col_12', CAST(d[#1] AS struct<col:bigint,col1:decimalv3(6,3)>))                                                                       |
|      final project output tuple id: 1                                                                                                                                                        |
|      tuple ids: 0                                                                                                                                                                            |
|                                                                                                                                                                                              |
| Tuples:                                                                                                                                                                                      |
| TupleDescriptor{id=0, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=0, col=a, colUniqueId=0, type=decimalv3(6,3), nullable=true, isAutoIncrement=false, subColPath=null}                                                                     |
|   SlotDescriptor{id=1, col=d, colUniqueId=1, type=struct<col:bigint,col1:decimalv3(7,2)>, nullable=true, isAutoIncrement=false, subColPath=null}                                             |
|                                                                                                                                                                                              |
| TupleDescriptor{id=1, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=2, col=null, colUniqueId=null, type=struct<col_11:decimalv3(6,3),col_12:struct<col:bigint,col1:decimalv3(6,3)>>, nullable=false, isAutoIncrement=false, subColPath=null} |
|                                                                                                                                                                                              |
|                                                                                                                                                                                              |
|

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@amorynan
Copy link
Contributor Author

run buildall

@Thearas
Copy link
Contributor

Thearas commented Mar 12, 2025

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@eldenmoon eldenmoon requested a review from morrySnow March 12, 2025 08:30
@doris-robot
Copy link

TPC-H: Total hot run time: 32514 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 4fe0c31a1ce20c29fa10ea44e2504b1611681910, data reload: false

------ Round 1 ----------------------------------
q1	17599	5238	5214	5214
q2	2043	296	162	162
q3	10421	1274	709	709
q4	10214	1015	536	536
q5	7497	2452	2319	2319
q6	192	161	132	132
q7	919	736	596	596
q8	9299	1317	1073	1073
q9	4940	4748	4820	4748
q10	6811	2348	1905	1905
q11	464	271	247	247
q12	341	354	214	214
q13	17759	3684	3047	3047
q14	230	230	213	213
q15	528	482	482	482
q16	614	621	576	576
q17	569	863	346	346
q18	6705	6416	6336	6336
q19	1078	954	545	545
q20	324	323	194	194
q21	2959	2134	1934	1934
q22	1074	1044	986	986
Total cold run time: 102580 ms
Total hot run time: 32514 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5168	5110	5118	5110
q2	246	322	225	225
q3	2158	2671	2342	2342
q4	1471	1817	1398	1398
q5	4274	4125	4141	4125
q6	209	167	124	124
q7	1901	1890	1773	1773
q8	2606	2684	2630	2630
q9	7260	7075	7280	7075
q10	2996	3171	2737	2737
q11	575	509	486	486
q12	722	773	597	597
q13	3415	3888	3305	3305
q14	292	315	267	267
q15	528	479	487	479
q16	633	698	628	628
q17	1144	1579	1368	1368
q18	7771	7655	7625	7625
q19	807	818	816	816
q20	2004	2004	1889	1889
q21	5429	5004	4930	4930
q22	1109	1116	1025	1025
Total cold run time: 52718 ms
Total hot run time: 50954 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 184441 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 4fe0c31a1ce20c29fa10ea44e2504b1611681910, data reload: false

query1	980	384	376	376
query2	6529	1987	1940	1940
query3	6795	210	213	210
query4	26815	23623	23746	23623
query5	5463	652	496	496
query6	305	202	223	202
query7	4619	491	290	290
query8	318	237	232	232
query9	8654	2616	2624	2616
query10	522	332	256	256
query11	15464	15137	14816	14816
query12	160	110	114	110
query13	1654	541	418	418
query14	9593	6601	6225	6225
query15	216	184	170	170
query16	7648	648	477	477
query17	1208	710	532	532
query18	1975	400	294	294
query19	178	175	149	149
query20	117	112	114	112
query21	208	121	103	103
query22	4335	4323	4127	4127
query23	33741	32924	32936	32924
query24	7718	2374	2375	2374
query25	508	450	387	387
query26	1230	269	153	153
query27	2506	465	321	321
query28	4290	2446	2411	2411
query29	708	571	425	425
query30	282	221	197	197
query31	911	848	756	756
query32	74	64	63	63
query33	551	363	304	304
query34	782	841	496	496
query35	788	817	727	727
query36	973	997	907	907
query37	119	99	75	75
query38	4107	4055	4160	4055
query39	1463	1402	1424	1402
query40	206	114	108	108
query41	55	52	50	50
query42	116	101	104	101
query43	511	521	481	481
query44	1271	795	785	785
query45	173	166	165	165
query46	828	1021	624	624
query47	1759	1799	1702	1702
query48	380	426	330	330
query49	791	510	434	434
query50	690	733	404	404
query51	4196	4194	4246	4194
query52	104	111	94	94
query53	236	252	188	188
query54	484	492	405	405
query55	90	81	79	79
query56	279	261	297	261
query57	1128	1147	1070	1070
query58	258	226	250	226
query59	2739	2778	2708	2708
query60	280	270	265	265
query61	122	118	115	115
query62	806	749	660	660
query63	229	182	196	182
query64	4213	990	667	667
query65	4446	4339	4339	4339
query66	991	402	301	301
query67	15640	15667	15158	15158
query68	8640	882	509	509
query69	488	294	259	259
query70	1186	1103	1109	1103
query71	494	284	263	263
query72	5203	2682	3592	2682
query73	809	752	351	351
query74	9002	8908	8753	8753
query75	4080	3141	2671	2671
query76	3734	1179	730	730
query77	796	374	278	278
query78	10003	10178	9333	9333
query79	2660	821	590	590
query80	706	518	477	477
query81	461	260	216	216
query82	650	129	95	95
query83	200	168	153	153
query84	287	97	73	73
query85	745	354	310	310
query86	342	312	302	302
query87	4428	4421	4305	4305
query88	3284	2274	2281	2274
query89	387	313	290	290
query90	1984	213	214	213
query91	137	140	116	116
query92	81	68	58	58
query93	1247	1074	587	587
query94	668	406	303	303
query95	350	271	255	255
query96	484	558	278	278
query97	3392	3422	3294	3294
query98	247	206	195	195
query99	1454	1388	1278	1278
Total cold run time: 276157 ms
Total hot run time: 184441 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 30.53 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 4fe0c31a1ce20c29fa10ea44e2504b1611681910, data reload: false

query1	0.03	0.03	0.04
query2	0.07	0.04	0.03
query3	0.24	0.07	0.06
query4	1.62	0.11	0.12
query5	0.56	0.55	0.58
query6	1.18	0.71	0.73
query7	0.02	0.01	0.02
query8	0.04	0.03	0.03
query9	0.58	0.52	0.51
query10	0.57	0.61	0.57
query11	0.15	0.11	0.11
query12	0.14	0.11	0.11
query13	0.62	0.61	0.60
query14	2.82	2.68	2.82
query15	0.93	0.84	0.85
query16	0.38	0.38	0.39
query17	1.03	1.02	1.05
query18	0.21	0.20	0.19
query19	1.94	1.98	1.83
query20	0.01	0.01	0.01
query21	15.34	0.92	0.54
query22	0.77	1.33	0.71
query23	14.75	1.36	0.65
query24	6.73	1.96	0.41
query25	0.47	0.27	0.13
query26	0.57	0.15	0.14
query27	0.04	0.05	0.05
query28	9.65	0.89	0.43
query29	12.56	3.97	3.33
query30	0.25	0.08	0.07
query31	2.83	0.57	0.40
query32	3.24	0.54	0.46
query33	3.00	3.14	2.99
query34	15.78	5.15	4.51
query35	4.60	4.55	4.57
query36	0.65	0.49	0.48
query37	0.09	0.06	0.06
query38	0.05	0.03	0.03
query39	0.02	0.02	0.02
query40	0.18	0.13	0.14
query41	0.08	0.03	0.02
query42	0.03	0.02	0.02
query43	0.03	0.03	0.02
Total cold run time: 104.85 s
Total hot run time: 30.53 s

@amorynan
Copy link
Contributor Author

run buildall

@amorynan amorynan requested a review from morrySnow March 13, 2025 03:29
@doris-robot
Copy link

TPC-H: Total hot run time: 33129 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 009b2ea3cb054249adeb09e950d371d424a11c7c, data reload: false

------ Round 1 ----------------------------------
q1	18517	5213	5062	5062
q2	2371	293	166	166
q3	11372	1237	766	766
q4	10210	1047	546	546
q5	7512	2411	2419	2411
q6	202	172	147	147
q7	937	759	667	667
q8	9498	1326	1165	1165
q9	5501	5032	4963	4963
q10	8032	2323	1895	1895
q11	489	279	264	264
q12	356	359	218	218
q13	18343	3733	3215	3215
q14	245	244	202	202
q15	538	487	483	483
q16	633	618	581	581
q17	597	851	358	358
q18	6830	6345	6283	6283
q19	2199	983	558	558
q20	316	321	189	189
q21	2977	2158	2004	2004
q22	1031	1005	986	986
Total cold run time: 108706 ms
Total hot run time: 33129 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5276	5173	5140	5140
q2	238	324	239	239
q3	2185	2724	2309	2309
q4	1447	1803	1351	1351
q5	4200	4114	4361	4114
q6	218	174	135	135
q7	1984	1897	1789	1789
q8	2620	2757	2646	2646
q9	7259	7174	7147	7147
q10	2998	3184	2682	2682
q11	560	494	499	494
q12	689	747	625	625
q13	3555	3904	3344	3344
q14	293	284	268	268
q15	520	469	467	467
q16	667	700	659	659
q17	1120	1617	1306	1306
q18	7666	7580	7530	7530
q19	880	834	890	834
q20	2010	2007	1909	1909
q21	5552	4762	4772	4762
q22	1075	1013	1017	1013
Total cold run time: 53012 ms
Total hot run time: 50763 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 191266 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 009b2ea3cb054249adeb09e950d371d424a11c7c, data reload: false

query1	1391	1010	960	960
query2	6130	1876	1836	1836
query3	10955	4558	4457	4457
query4	53496	25779	23024	23024
query5	5000	553	485	485
query6	362	201	195	195
query7	4884	493	287	287
query8	311	255	243	243
query9	5798	2626	2604	2604
query10	403	323	239	239
query11	15134	15206	14858	14858
query12	167	110	100	100
query13	1041	509	383	383
query14	9978	6651	6687	6651
query15	205	209	180	180
query16	7077	631	461	461
query17	1054	746	583	583
query18	1522	422	325	325
query19	194	187	167	167
query20	129	122	122	122
query21	208	129	116	116
query22	4358	4675	4415	4415
query23	34051	33372	33639	33372
query24	5724	2427	2430	2427
query25	499	528	382	382
query26	769	277	156	156
query27	1936	508	330	330
query28	2854	2466	2438	2438
query29	580	556	415	415
query30	274	223	189	189
query31	852	883	801	801
query32	74	62	60	60
query33	454	354	312	312
query34	757	861	503	503
query35	808	839	766	766
query36	939	970	907	907
query37	121	100	75	75
query38	4053	4314	4282	4282
query39	1493	1441	1439	1439
query40	207	121	111	111
query41	53	52	50	50
query42	118	104	104	104
query43	477	518	462	462
query44	1310	784	787	784
query45	183	175	161	161
query46	845	1017	635	635
query47	1883	1901	1811	1811
query48	375	407	301	301
query49	683	540	418	418
query50	720	763	415	415
query51	4316	4276	4292	4276
query52	109	103	94	94
query53	233	264	192	192
query54	500	487	411	411
query55	80	80	82	80
query56	250	268	262	262
query57	1150	1174	1125	1125
query58	257	246	234	234
query59	2644	2899	2601	2601
query60	291	292	267	267
query61	143	122	127	122
query62	777	746	666	666
query63	229	193	186	186
query64	1782	1035	740	740
query65	4527	4416	4449	4416
query66	721	391	291	291
query67	16155	15482	15245	15245
query68	7157	823	505	505
query69	535	294	257	257
query70	1170	1090	1071	1071
query71	489	295	273	273
query72	5780	3645	3854	3645
query73	1441	742	343	343
query74	8896	9227	8677	8677
query75	3858	3145	2754	2754
query76	4318	1196	754	754
query77	633	364	271	271
query78	10060	10031	9284	9284
query79	5544	806	562	562
query80	716	536	441	441
query81	490	264	217	217
query82	749	130	95	95
query83	271	169	150	150
query84	279	103	74	74
query85	816	350	307	307
query86	344	300	266	266
query87	4455	4438	4251	4251
query88	3353	2216	2221	2216
query89	469	314	276	276
query90	1965	214	212	212
query91	142	138	109	109
query92	69	62	54	54
query93	2397	1055	572	572
query94	737	408	299	299
query95	348	274	271	271
query96	489	558	275	275
query97	3325	3418	3307	3307
query98	226	209	204	204
query99	1425	1402	1269	1269
Total cold run time: 299999 ms
Total hot run time: 191266 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 31.04 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 009b2ea3cb054249adeb09e950d371d424a11c7c, data reload: false

query1	0.04	0.04	0.03
query2	0.07	0.03	0.04
query3	0.23	0.06	0.06
query4	1.62	0.10	0.10
query5	0.57	0.54	0.53
query6	1.20	0.72	0.73
query7	0.03	0.02	0.02
query8	0.04	0.03	0.03
query9	0.59	0.51	0.53
query10	0.59	0.61	0.58
query11	0.16	0.11	0.11
query12	0.15	0.12	0.12
query13	0.62	0.60	0.60
query14	2.68	2.81	2.80
query15	0.93	0.87	0.87
query16	0.38	0.39	0.40
query17	1.01	1.02	1.07
query18	0.21	0.20	0.19
query19	1.92	1.87	1.93
query20	0.01	0.01	0.01
query21	15.37	0.88	0.55
query22	0.75	1.21	0.64
query23	14.98	1.37	0.61
query24	7.28	0.81	2.02
query25	0.49	0.23	0.07
query26	0.64	0.16	0.15
query27	0.05	0.05	0.05
query28	9.55	0.79	0.43
query29	12.54	4.09	3.42
query30	0.25	0.09	0.07
query31	2.83	0.62	0.39
query32	3.23	0.55	0.46
query33	3.03	3.01	3.13
query34	15.71	5.10	4.48
query35	4.52	4.58	4.52
query36	0.66	0.48	0.50
query37	0.09	0.06	0.07
query38	0.05	0.04	0.03
query39	0.03	0.03	0.02
query40	0.18	0.13	0.12
query41	0.08	0.03	0.03
query42	0.03	0.02	0.02
query43	0.04	0.03	0.03
Total cold run time: 105.43 s
Total hot run time: 31.04 s

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Mar 14, 2025
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

Copy link
Member

@eldenmoon eldenmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eldenmoon eldenmoon merged commit 292147c into apache:master Mar 18, 2025
26 of 28 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 18, 2025
… nested decimal precision (#48964)

before this pr , we deduce the precision of the function named_struct
containing the decimal type is same with the precision of the decimal
type in select . In this case we can not make right named_struct for
multiple decimal value
like :
```
mysql> create table t01 (a decimal(6,3), d struct<col:bigint, col1:decimal(7,2)>) properties ("replication_num"="1");
Query OK, 0 rows affected (0.14 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 345.24));
Query OK, 1 row affected (0.26 sec)
{'label':'label_a2dc895ee7834701_841639ad6d93923f', 'status':'VISIBLE', 'txnId':'9010'}

mysql> select named_struct("col_11", a, "col_12", d) from t01;
+--------------------------------------------------------+
| named_struct("col_11", a, "col_12", d)                 |
+--------------------------------------------------------+
| {"col_11":123.321, "col_12":{"col":1, "col1":345.240}} |
+--------------------------------------------------------+
1 row in set (0.17 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 12345.24));
Query OK, 1 row affected (0.17 sec)
{'label':'label_77ed6047f6a6494d_810c26becfd0535c', 'status':'VISIBLE', 'txnId':'9011'}
mysql> select named_struct("col_11", a, "col_12", d) from t01;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[E-255]Arithmetic overflow when converting value 12345.24 from type Decimal(7, 2) to type Decimal(6, 3)
mysql> desc verbose select named_struct("col_11", a, "col_12", d) from t01;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PLAN FRAGMENT 0                                                                                                                                                                              |
|   OUTPUT EXPRS:                                                                                                                                                                              |
|     named_struct("col_11", a, "col_12", d)[#2]                                                                                                                                               |
|   PARTITION: RANDOM                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                  |
|                                                                                                                                                                                              |
|   VRESULT SINK                                                                                                                                                                               |
|      MYSQL_PROTOCAL                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   0:VOlapScanNode(50)                                                                                                                                                                        |
|      TABLE: tt.t01(t01), PREAGGREGATION: ON                                                                                                                                                  |
|      partitions=1/1 (t01)                                                                                                                                                                    |
|      tablets=10/10, tabletList=1741751856342,1741751856344,1741751856346 ...                                                                                                                 |
|      cardinality=2, avgRowSize=2955.0, numNodes=1                                                                                                                                            |
|      pushAggOp=NONE                                                                                                                                                                          |
|      final projections: named_struct('col_11', a[#0], 'col_12', CAST(d[#1] AS struct<col:bigint,col1:decimalv3(6,3)>))                                                                       |
|      final project output tuple id: 1                                                                                                                                                        |
|      tuple ids: 0                                                                                                                                                                            |
|                                                                                                                                                                                              |
| Tuples:                                                                                                                                                                                      |
| TupleDescriptor{id=0, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=0, col=a, colUniqueId=0, type=decimalv3(6,3), nullable=true, isAutoIncrement=false, subColPath=null}                                                                     |
|   SlotDescriptor{id=1, col=d, colUniqueId=1, type=struct<col:bigint,col1:decimalv3(7,2)>, nullable=true, isAutoIncrement=false, subColPath=null}                                             |
|                                                                                                                                                                                              |
| TupleDescriptor{id=1, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=2, col=null, colUniqueId=null, type=struct<col_11:decimalv3(6,3),col_12:struct<col:bigint,col1:decimalv3(6,3)>>, nullable=false, isAutoIncrement=false, subColPath=null} |
|                                                                                                                                                                                              |
|                                                                                                                                                                                              |
|
```
github-actions bot pushed a commit that referenced this pull request Mar 18, 2025
… nested decimal precision (#48964)

before this pr , we deduce the precision of the function named_struct
containing the decimal type is same with the precision of the decimal
type in select . In this case we can not make right named_struct for
multiple decimal value
like :
```
mysql> create table t01 (a decimal(6,3), d struct<col:bigint, col1:decimal(7,2)>) properties ("replication_num"="1");
Query OK, 0 rows affected (0.14 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 345.24));
Query OK, 1 row affected (0.26 sec)
{'label':'label_a2dc895ee7834701_841639ad6d93923f', 'status':'VISIBLE', 'txnId':'9010'}

mysql> select named_struct("col_11", a, "col_12", d) from t01;
+--------------------------------------------------------+
| named_struct("col_11", a, "col_12", d)                 |
+--------------------------------------------------------+
| {"col_11":123.321, "col_12":{"col":1, "col1":345.240}} |
+--------------------------------------------------------+
1 row in set (0.17 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 12345.24));
Query OK, 1 row affected (0.17 sec)
{'label':'label_77ed6047f6a6494d_810c26becfd0535c', 'status':'VISIBLE', 'txnId':'9011'}
mysql> select named_struct("col_11", a, "col_12", d) from t01;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[E-255]Arithmetic overflow when converting value 12345.24 from type Decimal(7, 2) to type Decimal(6, 3)
mysql> desc verbose select named_struct("col_11", a, "col_12", d) from t01;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PLAN FRAGMENT 0                                                                                                                                                                              |
|   OUTPUT EXPRS:                                                                                                                                                                              |
|     named_struct("col_11", a, "col_12", d)[#2]                                                                                                                                               |
|   PARTITION: RANDOM                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                  |
|                                                                                                                                                                                              |
|   VRESULT SINK                                                                                                                                                                               |
|      MYSQL_PROTOCAL                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   0:VOlapScanNode(50)                                                                                                                                                                        |
|      TABLE: tt.t01(t01), PREAGGREGATION: ON                                                                                                                                                  |
|      partitions=1/1 (t01)                                                                                                                                                                    |
|      tablets=10/10, tabletList=1741751856342,1741751856344,1741751856346 ...                                                                                                                 |
|      cardinality=2, avgRowSize=2955.0, numNodes=1                                                                                                                                            |
|      pushAggOp=NONE                                                                                                                                                                          |
|      final projections: named_struct('col_11', a[#0], 'col_12', CAST(d[#1] AS struct<col:bigint,col1:decimalv3(6,3)>))                                                                       |
|      final project output tuple id: 1                                                                                                                                                        |
|      tuple ids: 0                                                                                                                                                                            |
|                                                                                                                                                                                              |
| Tuples:                                                                                                                                                                                      |
| TupleDescriptor{id=0, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=0, col=a, colUniqueId=0, type=decimalv3(6,3), nullable=true, isAutoIncrement=false, subColPath=null}                                                                     |
|   SlotDescriptor{id=1, col=d, colUniqueId=1, type=struct<col:bigint,col1:decimalv3(7,2)>, nullable=true, isAutoIncrement=false, subColPath=null}                                             |
|                                                                                                                                                                                              |
| TupleDescriptor{id=1, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=2, col=null, colUniqueId=null, type=struct<col_11:decimalv3(6,3),col_12:struct<col:bigint,col1:decimalv3(6,3)>>, nullable=false, isAutoIncrement=false, subColPath=null} |
|                                                                                                                                                                                              |
|                                                                                                                                                                                              |
|
```
dataroaring pushed a commit that referenced this pull request Mar 18, 2025
…ce wrong for nested decimal precision #48964 (#49189)

Cherry-picked from #48964

Co-authored-by: amory <wangqiannan@selectdb.com>
amorynan pushed a commit to amorynan/doris that referenced this pull request Mar 22, 2025
… nested decimal precision (apache#48964)

before this pr , we deduce the precision of the function named_struct
containing the decimal type is same with the precision of the decimal
type in select . In this case we can not make right named_struct for
multiple decimal value
like :
```
mysql> create table t01 (a decimal(6,3), d struct<col:bigint, col1:decimal(7,2)>) properties ("replication_num"="1");
Query OK, 0 rows affected (0.14 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 345.24));
Query OK, 1 row affected (0.26 sec)
{'label':'label_a2dc895ee7834701_841639ad6d93923f', 'status':'VISIBLE', 'txnId':'9010'}

mysql> select named_struct("col_11", a, "col_12", d) from t01;
+--------------------------------------------------------+
| named_struct("col_11", a, "col_12", d)                 |
+--------------------------------------------------------+
| {"col_11":123.321, "col_12":{"col":1, "col1":345.240}} |
+--------------------------------------------------------+
1 row in set (0.17 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 12345.24));
Query OK, 1 row affected (0.17 sec)
{'label':'label_77ed6047f6a6494d_810c26becfd0535c', 'status':'VISIBLE', 'txnId':'9011'}
mysql> select named_struct("col_11", a, "col_12", d) from t01;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[E-255]Arithmetic overflow when converting value 12345.24 from type Decimal(7, 2) to type Decimal(6, 3)
mysql> desc verbose select named_struct("col_11", a, "col_12", d) from t01;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PLAN FRAGMENT 0                                                                                                                                                                              |
|   OUTPUT EXPRS:                                                                                                                                                                              |
|     named_struct("col_11", a, "col_12", d)[apache#2]                                                                                                                                               |
|   PARTITION: RANDOM                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                  |
|                                                                                                                                                                                              |
|   VRESULT SINK                                                                                                                                                                               |
|      MYSQL_PROTOCAL                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   0:VOlapScanNode(50)                                                                                                                                                                        |
|      TABLE: tt.t01(t01), PREAGGREGATION: ON                                                                                                                                                  |
|      partitions=1/1 (t01)                                                                                                                                                                    |
|      tablets=10/10, tabletList=1741751856342,1741751856344,1741751856346 ...                                                                                                                 |
|      cardinality=2, avgRowSize=2955.0, numNodes=1                                                                                                                                            |
|      pushAggOp=NONE                                                                                                                                                                          |
|      final projections: named_struct('col_11', a[#0], 'col_12', CAST(d[#1] AS struct<col:bigint,col1:decimalv3(6,3)>))                                                                       |
|      final project output tuple id: 1                                                                                                                                                        |
|      tuple ids: 0                                                                                                                                                                            |
|                                                                                                                                                                                              |
| Tuples:                                                                                                                                                                                      |
| TupleDescriptor{id=0, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=0, col=a, colUniqueId=0, type=decimalv3(6,3), nullable=true, isAutoIncrement=false, subColPath=null}                                                                     |
|   SlotDescriptor{id=1, col=d, colUniqueId=1, type=struct<col:bigint,col1:decimalv3(7,2)>, nullable=true, isAutoIncrement=false, subColPath=null}                                             |
|                                                                                                                                                                                              |
| TupleDescriptor{id=1, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=2, col=null, colUniqueId=null, type=struct<col_11:decimalv3(6,3),col_12:struct<col:bigint,col1:decimalv3(6,3)>>, nullable=false, isAutoIncrement=false, subColPath=null} |
|                                                                                                                                                                                              |
|                                                                                                                                                                                              |
|
```
@yiguolei yiguolei mentioned this pull request May 13, 2025
koarz pushed a commit to koarz/doris that referenced this pull request Jun 4, 2025
… nested decimal precision (apache#48964)

before this pr , we deduce the precision of the function named_struct
containing the decimal type is same with the precision of the decimal
type in select . In this case we can not make right named_struct for
multiple decimal value
like :
```
mysql> create table t01 (a decimal(6,3), d struct<col:bigint, col1:decimal(7,2)>) properties ("replication_num"="1");
Query OK, 0 rows affected (0.14 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 345.24));
Query OK, 1 row affected (0.26 sec)
{'label':'label_a2dc895ee7834701_841639ad6d93923f', 'status':'VISIBLE', 'txnId':'9010'}

mysql> select named_struct("col_11", a, "col_12", d) from t01;
+--------------------------------------------------------+
| named_struct("col_11", a, "col_12", d)                 |
+--------------------------------------------------------+
| {"col_11":123.321, "col_12":{"col":1, "col1":345.240}} |
+--------------------------------------------------------+
1 row in set (0.17 sec)

mysql> insert into t01 values (123.321, named_struct('col', 1, 'col1', 12345.24));
Query OK, 1 row affected (0.17 sec)
{'label':'label_77ed6047f6a6494d_810c26becfd0535c', 'status':'VISIBLE', 'txnId':'9011'}
mysql> select named_struct("col_11", a, "col_12", d) from t01;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[E-255]Arithmetic overflow when converting value 12345.24 from type Decimal(7, 2) to type Decimal(6, 3)
mysql> desc verbose select named_struct("col_11", a, "col_12", d) from t01;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PLAN FRAGMENT 0                                                                                                                                                                              |
|   OUTPUT EXPRS:                                                                                                                                                                              |
|     named_struct("col_11", a, "col_12", d)[apache#2]                                                                                                                                               |
|   PARTITION: RANDOM                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                  |
|                                                                                                                                                                                              |
|   VRESULT SINK                                                                                                                                                                               |
|      MYSQL_PROTOCAL                                                                                                                                                                          |
|                                                                                                                                                                                              |
|   0:VOlapScanNode(50)                                                                                                                                                                        |
|      TABLE: tt.t01(t01), PREAGGREGATION: ON                                                                                                                                                  |
|      partitions=1/1 (t01)                                                                                                                                                                    |
|      tablets=10/10, tabletList=1741751856342,1741751856344,1741751856346 ...                                                                                                                 |
|      cardinality=2, avgRowSize=2955.0, numNodes=1                                                                                                                                            |
|      pushAggOp=NONE                                                                                                                                                                          |
|      final projections: named_struct('col_11', a[#0], 'col_12', CAST(d[apache#1] AS struct<col:bigint,col1:decimalv3(6,3)>))                                                                       |
|      final project output tuple id: 1                                                                                                                                                        |
|      tuple ids: 0                                                                                                                                                                            |
|                                                                                                                                                                                              |
| Tuples:                                                                                                                                                                                      |
| TupleDescriptor{id=0, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=0, col=a, colUniqueId=0, type=decimalv3(6,3), nullable=true, isAutoIncrement=false, subColPath=null}                                                                     |
|   SlotDescriptor{id=1, col=d, colUniqueId=1, type=struct<col:bigint,col1:decimalv3(7,2)>, nullable=true, isAutoIncrement=false, subColPath=null}                                             |
|                                                                                                                                                                                              |
| TupleDescriptor{id=1, tbl=t01}                                                                                                                                                               |
|   SlotDescriptor{id=2, col=null, colUniqueId=null, type=struct<col_11:decimalv3(6,3),col_12:struct<col:bigint,col1:decimalv3(6,3)>>, nullable=false, isAutoIncrement=false, subColPath=null} |
|                                                                                                                                                                                              |
|                                                                                                                                                                                              |
|
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/2.1.10-merged dev/3.0.5-merged reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants