Skip to content

Conversation

@zxc20041
Copy link

@zxc20041 zxc20041 commented Jan 23, 2026

What problem does this PR solve?

Issue Number: close #48203

Related PR: #48695

Problem Summary:
Support for ST_Distance, ST_GeometryType, ST_Length sql functions.

Release note

None

Check List (For Author)

Check List (For Reviewer who merge this PR)

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

@Thearas
Copy link
Contributor

Thearas commented Jan 23, 2026

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?

@zclllyybb zclllyybb self-assigned this Jan 23, 2026
@zxc20041
Copy link
Author

run buildall

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements three spatial SQL functions (ST_Distance, ST_GeometryType, ST_Length) to improve compatibility with other database systems like Trino, Presto, and PostgreSQL, as part of the broader effort outlined in issue #48203.

Changes:

  • Adds ST_Length function to calculate the length/perimeter of geometry objects (in meters for LineString/Polygon/Circle, 0 for Point)
  • Adds ST_GeometryType function to return the geometry type name (e.g., "ST_POINT", "ST_LINESTRING")
  • Adds ST_Distance function to calculate the geodesic distance between two geometry objects (in meters)

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
be/src/geo/geo_types.h Adds virtual method declarations for GeometryType(), Length(), and Distance() to the GeoShape base class and implements them in all derived classes
be/src/geo/st_length.cpp Implements Length() calculations for all geometry types using S2Earth library for geodesic measurements
be/src/geo/st_distance.cpp Implements Distance() calculations between all geometry type combinations with helper functions for point-to-segment, point-to-polyline, and point-to-polygon distances
be/src/geo/CMakeLists.txt Updates build configuration to include the new st_length.cpp and st_distance.cpp source files
be/src/vec/functions/functions_geo.cpp Registers the three new functions (StLength, StGeometryType, StDistance) with the function factory
be/test/geo/geo_types_test.cpp Adds comprehensive C++ unit tests covering all geometry types and type combinations for the new functions
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StLength.java Frontend scalar function class for ST_Length with proper signature (VARCHAR -> DOUBLE)
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StGeometryType.java Frontend scalar function class for ST_GeometryType with proper signature (VARCHAR -> VARCHAR)
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StDistance.java Frontend scalar function class for ST_Distance with proper signature (VARCHAR, VARCHAR -> DOUBLE)
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java Adds visitor methods for the three new function types
fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java Registers the three new scalar functions in the builtin function catalog
regression-test/suites/nereids_p0/sql_functions/spatial_functions/test_gis_function.groovy Adds extensive regression test cases covering all geometry type combinations for the new functions
regression-test/data/nereids_p0/sql_functions/spatial_functions/test_gis_function.out Expected output for the regression tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17617	4705	4546	4546
q2	2023	342	201	201
q3	10232	1267	719	719
q4	10215	811	313	313
q5	7528	2119	1817	1817
q6	185	175	145	145
q7	874	721	595	595
q8	9272	1435	1114	1114
q9	4858	4529	4605	4529
q10	6792	1658	1270	1270
q11	528	292	272	272
q12	335	369	230	230
q13	17795	3778	3111	3111
q14	234	230	210	210
q15	602	531	538	531
q16	641	656	581	581
q17	658	779	505	505
q18	6645	6351	6652	6351
q19	1305	1117	665	665
q20	416	366	247	247
q21	2998	2578	2020	2020
q22	1122	1071	1065	1065
Total cold run time: 102875 ms
Total hot run time: 31037 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5041	4880	4926	4880
q2	332	425	351	351
q3	2359	2865	2426	2426
q4	1406	1876	1503	1503
q5	4525	4426	4420	4420
q6	218	168	140	140
q7	2122	2094	1795	1795
q8	2578	2463	2509	2463
q9	7247	7276	7314	7276
q10	2514	2661	2160	2160
q11	508	454	436	436
q12	675	703	569	569
q13	3352	3809	3106	3106
q14	266	281	275	275
q15	539	503	494	494
q16	637	650	619	619
q17	1121	1289	1329	1289
q18	7424	7332	7150	7150
q19	847	792	802	792
q20	1926	1961	1828	1828
q21	4536	4310	4181	4181
q22	1123	1037	967	967
Total cold run time: 51296 ms
Total hot run time: 49120 ms

@zxc20041
Copy link
Author

oops, I forgot to modify be-ut testcase after changing geometry_type

@doris-robot
Copy link

TPC-DS: Total hot run time: 172396 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 daf2d815b177bb1b852fb0deb430a828c70e0f9b, data reload: false

query5	4421	640	501	501
query6	328	226	210	210
query7	4221	464	259	259
query8	341	256	269	256
query9	8731	2838	2874	2838
query10	472	345	269	269
query11	15187	15058	14715	14715
query12	177	120	120	120
query13	1264	471	369	369
query14	6310	3008	2752	2752
query14_1	2689	2616	2653	2616
query15	199	196	179	179
query16	1000	404	452	404
query17	1106	678	576	576
query18	2567	429	338	338
query19	202	182	156	156
query20	126	120	119	119
query21	222	137	116	116
query22	3857	3985	4074	3985
query23	16139	15686	15331	15331
query23_1	15481	15504	15436	15436
query24	7160	1536	1127	1127
query24_1	1134	1174	1168	1168
query25	553	458	442	442
query26	1242	263	145	145
query27	2772	441	280	280
query28	4551	2136	2136	2136
query29	784	528	434	434
query30	306	236	205	205
query31	786	637	577	577
query32	86	74	72	72
query33	518	360	307	307
query34	903	859	521	521
query35	710	769	647	647
query36	880	889	868	868
query37	141	94	91	91
query38	2724	2741	2666	2666
query39	782	754	748	748
query39_1	725	734	706	706
query40	223	134	117	117
query41	67	63	65	63
query42	94	94	95	94
query43	433	437	412	412
query44	1322	735	743	735
query45	188	181	180	180
query46	828	935	585	585
query47	1366	1527	1405	1405
query48	308	311	237	237
query49	609	434	387	387
query50	664	263	199	199
query51	3738	3757	3836	3757
query52	90	93	81	81
query53	208	220	162	162
query54	286	259	249	249
query55	80	77	72	72
query56	293	295	295	295
query57	1026	1030	905	905
query58	270	258	263	258
query59	2081	2170	2112	2112
query60	327	333	310	310
query61	160	157	149	149
query62	379	350	315	315
query63	186	158	166	158
query64	4944	1134	862	862
query65	3852	3731	3769	3731
query66	1439	418	327	327
query67	15545	15618	15528	15528
query68	2499	1055	721	721
query69	394	317	275	275
query70	965	944	943	943
query71	300	276	271	271
query72	5267	3121	3348	3121
query73	607	720	321	321
query74	8716	8710	8650	8650
query75	2314	2351	1907	1907
query76	2297	1043	644	644
query77	385	395	319	319
query78	9754	9849	9099	9099
query79	1077	903	571	571
query80	669	558	486	486
query81	482	260	233	233
query82	1404	148	117	117
query83	366	265	247	247
query84	252	125	96	96
query85	826	491	430	430
query86	368	288	321	288
query87	2896	2857	2767	2767
query88	3438	2582	2538	2538
query89	305	250	226	226
query90	1881	173	166	166
query91	167	162	134	134
query92	80	74	73	73
query93	1051	1029	632	632
query94	449	317	287	287
query95	586	383	308	308
query96	642	493	227	227
query97	2341	2370	2317	2317
query98	215	199	195	195
query99	599	596	532	532
Total cold run time: 245543 ms
Total hot run time: 172396 ms

@doris-robot
Copy link

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

query1	0.06	0.04	0.04
query2	0.09	0.06	0.05
query3	0.26	0.09	0.09
query4	1.61	0.12	0.11
query5	0.28	0.26	0.26
query6	1.14	0.65	0.65
query7	0.03	0.03	0.02
query8	0.05	0.04	0.04
query9	0.58	0.49	0.49
query10	0.55	0.55	0.55
query11	0.14	0.10	0.10
query12	0.14	0.11	0.11
query13	0.60	0.58	0.58
query14	0.96	0.94	0.93
query15	0.79	0.77	0.78
query16	0.39	0.39	0.40
query17	1.05	1.02	1.04
query18	0.24	0.22	0.21
query19	1.90	1.90	1.89
query20	0.02	0.02	0.02
query21	15.43	0.26	0.13
query22	5.36	0.05	0.05
query23	15.80	0.29	0.10
query24	1.21	0.24	0.56
query25	0.09	0.08	0.06
query26	0.14	0.13	0.13
query27	0.08	0.06	0.06
query28	4.59	1.08	0.89
query29	12.54	3.91	3.13
query30	0.28	0.13	0.12
query31	2.81	0.66	0.38
query32	3.24	0.57	0.46
query33	2.95	3.05	3.06
query34	16.21	5.08	4.43
query35	4.42	4.40	4.43
query36	0.66	0.50	0.48
query37	0.11	0.06	0.06
query38	0.07	0.04	0.04
query39	0.05	0.03	0.03
query40	0.17	0.14	0.13
query41	0.08	0.04	0.03
query42	0.05	0.03	0.03
query43	0.05	0.03	0.03
Total cold run time: 97.27 s
Total hot run time: 26.78 s

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 8.33% (3/36) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 91.67% (33/36) 🎉
Increment coverage report
Complete coverage report

@zxc20041
Copy link
Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17699	4840	4560	4560
q2	2059	337	198	198
q3	10171	1277	742	742
q4	10200	813	308	308
q5	7531	2055	1812	1812
q6	192	172	141	141
q7	869	726	583	583
q8	9276	1388	1075	1075
q9	5027	4607	4536	4536
q10	6837	1699	1276	1276
q11	546	306	282	282
q12	392	385	225	225
q13	17797	3837	3085	3085
q14	241	249	219	219
q15	599	530	538	530
q16	631	634	590	590
q17	657	824	486	486
q18	6518	6538	6611	6538
q19	1424	1058	667	667
q20	432	376	240	240
q21	3047	2277	2207	2207
q22	1129	1092	1028	1028
Total cold run time: 103274 ms
Total hot run time: 31328 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5146	4852	4990	4852
q2	341	399	340	340
q3	2373	2889	2527	2527
q4	1409	1923	1473	1473
q5	4615	4432	4551	4432
q6	218	168	131	131
q7	2095	2027	1758	1758
q8	2518	2418	2402	2402
q9	7071	7321	7120	7120
q10	2483	2730	2250	2250
q11	534	454	432	432
q12	667	684	582	582
q13	3365	3796	3082	3082
q14	276	283	259	259
q15	542	500	502	500
q16	606	666	629	629
q17	1093	1313	1409	1313
q18	7146	7392	7267	7267
q19	817	819	813	813
q20	1918	1961	1809	1809
q21	4509	4275	4122	4122
q22	1081	1053	985	985
Total cold run time: 50823 ms
Total hot run time: 49078 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 172939 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 1aae56ddc136ea939b623d88dc99660ada2b0b3d, data reload: false

query5	4362	643	483	483
query6	331	221	209	209
query7	4218	463	268	268
query8	360	277	238	238
query9	8710	2880	2901	2880
query10	469	313	288	288
query11	15168	15114	15050	15050
query12	183	125	117	117
query13	1253	482	381	381
query14	6467	3066	2812	2812
query14_1	2783	2659	2672	2659
query15	200	193	174	174
query16	983	477	482	477
query17	1122	681	575	575
query18	2582	431	344	344
query19	214	194	153	153
query20	124	119	116	116
query21	220	136	124	124
query22	3886	3913	3843	3843
query23	15990	15501	15336	15336
query23_1	15237	15447	15401	15401
query24	7131	1547	1156	1156
query24_1	1158	1175	1191	1175
query25	542	460	416	416
query26	842	285	150	150
query27	2730	439	279	279
query28	4485	2183	2163	2163
query29	756	549	444	444
query30	319	248	212	212
query31	756	632	568	568
query32	91	78	75	75
query33	529	352	324	324
query34	867	881	556	556
query35	717	795	688	688
query36	913	890	837	837
query37	142	102	88	88
query38	2747	2691	2652	2652
query39	788	755	739	739
query39_1	710	714	714	714
query40	229	140	120	120
query41	74	67	67	67
query42	99	94	96	94
query43	473	448	422	422
query44	1329	767	753	753
query45	194	202	188	188
query46	832	979	577	577
query47	1372	1472	1385	1385
query48	313	323	237	237
query49	589	417	340	340
query50	666	273	198	198
query51	3814	3797	3751	3751
query52	86	92	84	84
query53	213	216	162	162
query54	274	257	259	257
query55	84	80	76	76
query56	300	284	287	284
query57	1008	1021	966	966
query58	263	257	256	256
query59	2058	2215	2037	2037
query60	339	348	311	311
query61	146	147	147	147
query62	377	355	299	299
query63	196	165	166	165
query64	4115	1216	850	850
query65	3789	3735	3770	3735
query66	1352	411	333	333
query67	15598	15676	15405	15405
query68	2764	1069	716	716
query69	417	314	276	276
query70	994	970	950	950
query71	301	305	276	276
query72	5417	3210	3232	3210
query73	624	723	314	314
query74	8715	8791	8590	8590
query75	2313	2329	1912	1912
query76	2388	1044	683	683
query77	364	387	300	300
query78	9865	9962	9128	9128
query79	1075	935	583	583
query80	1263	523	436	436
query81	540	263	233	233
query82	989	155	120	120
query83	347	265	245	245
query84	253	112	99	99
query85	874	493	403	403
query86	403	290	321	290
query87	2879	2892	2750	2750
query88	3534	2604	2576	2576
query89	300	267	243	243
query90	1924	175	158	158
query91	163	152	132	132
query92	74	74	68	68
query93	1170	1048	640	640
query94	635	316	296	296
query95	576	350	369	350
query96	653	494	235	235
query97	2367	2331	2336	2331
query98	213	199	196	196
query99	602	573	508	508
Total cold run time: 244968 ms
Total hot run time: 172939 ms

@doris-robot
Copy link

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

query1	0.05	0.05	0.05
query2	0.10	0.05	0.05
query3	0.27	0.09	0.08
query4	1.61	0.11	0.10
query5	0.27	0.25	0.25
query6	1.14	0.67	0.64
query7	0.03	0.03	0.02
query8	0.06	0.04	0.03
query9	0.57	0.51	0.48
query10	0.54	0.55	0.55
query11	0.14	0.09	0.10
query12	0.15	0.11	0.11
query13	0.61	0.59	0.60
query14	0.95	0.94	0.94
query15	0.79	0.77	0.79
query16	0.40	0.40	0.39
query17	1.06	1.04	1.00
query18	0.22	0.22	0.22
query19	1.91	1.88	1.82
query20	0.02	0.01	0.02
query21	15.45	0.23	0.13
query22	5.07	0.07	0.05
query23	15.76	0.29	0.10
query24	1.07	0.37	0.70
query25	0.10	0.10	0.10
query26	0.14	0.13	0.13
query27	0.07	0.06	0.05
query28	4.47	1.08	0.88
query29	12.54	3.95	3.13
query30	0.28	0.14	0.12
query31	2.82	0.61	0.39
query32	3.24	0.56	0.45
query33	2.97	2.99	3.08
query34	16.25	5.11	4.42
query35	4.43	4.44	4.45
query36	0.65	0.50	0.49
query37	0.10	0.06	0.06
query38	0.08	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.14	0.14
query41	0.10	0.03	0.03
query42	0.05	0.03	0.03
query43	0.05	0.04	0.04
Total cold run time: 96.79 s
Total hot run time: 26.8 s

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 8.33% (3/36) 🎉
Increment coverage report
Complete coverage report

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 63.12% (243/385) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.47% (19135/36469)
Line Coverage 35.85% (177841/496056)
Region Coverage 32.30% (137349/425181)
Branch Coverage 33.26% (59517/178943)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 84.68% (326/385) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.53% (25570/35748)
Line Coverage 54.11% (268125/495524)
Region Coverage 51.52% (221389/429694)
Branch Coverage 53.10% (95425/179714)

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 91.67% (33/36) 🎉
Increment coverage report
Complete coverage report

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue] Support All SQL Functions in Other SQL System

5 participants