File: st_collect.result

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (244 lines) | stat: -rw-r--r-- 10,546 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# setup of data for tests involving simple aggregations and group by
CREATE TABLE table_simple_aggregation ( running_number INTEGER NOT NULL
AUTO_INCREMENT, grouping_condition INTEGER, location GEOMETRY , PRIMARY KEY (
running_number));
INSERT INTO table_simple_aggregation ( grouping_condition, location ) VALUES
( 0,ST_GEOMFROMTEXT('POINT(0 0)',4326)),
( 1,ST_GEOMFROMTEXT('POINT(0 0)',4326)),
( 0,ST_GEOMFROMTEXT('POINT(1 0)',4326)),
( 1,ST_GEOMFROMTEXT('POINT(2 0)',4326)),
( 0,ST_GEOMFROMTEXT('POINT(3 0)',4326));
# Functional requirement F-4: ST_COLLECT shall support simple table
# aggregations
# result shall be 1
SELECT ST_EQUALS( (SELECT ST_COLLECT( location ) AS t FROM
table_simple_aggregation) , ST_GEOMFROMTEXT('MULTIPOINT((0 0),(0 0),(1 0),(2
0),(3 0)) ',4326));
ST_EQUALS( (SELECT ST_COLLECT( location ) AS t FROM
table_simple_aggregation) , ST_GEOMFROMTEXT('MULTIPOINT((0 0),(0 0),(1 0),(2
0),(3 0)) ',4326))
1
# Functional requirement F-8 Shall support DISTINCT in aggregates
# result shall be 1
SELECT ST_EQUALS( (SELECT ST_COLLECT( DISTINCT location ) AS t FROM
table_simple_aggregation) , ST_GEOMFROMTEXT('MULTIPOINT((0 0),(1 0),(2 0),(3
0)) ',4326));
ST_EQUALS( (SELECT ST_COLLECT( DISTINCT location ) AS t FROM
table_simple_aggregation) , ST_GEOMFROMTEXT('MULTIPOINT((0 0),(1 0),(2 0),(3
0)) ',4326))
1
# Functional requirement F-5: ST_COLLECT shall support group by, which
# is given by aggregation machinery
# result shall be
# MULTIPOINT((0 0),(1 0),(3 0))
# MULTIPOINT((2 0),(0 0))
SELECT ST_ASTEXT(ST_COLLECT( DISTINCT location )) AS t FROM
table_simple_aggregation GROUP BY grouping_condition;
t
MULTIPOINT((0 0),(1 0),(3 0))
MULTIPOINT((0 0),(2 0))
# Distinct with rollup 
SELECT st_astext(ST_COLLECT( distinct location )) AS t from
table_simple_aggregation group by st_latitude(location) with rollup;
t
MULTIPOINT((0 0))
MULTIPOINT((1 0))
MULTIPOINT((2 0))
MULTIPOINT((3 0))
MULTIPOINT((0 0),(1 0),(2 0),(3 0))
INSERT INTO table_simple_aggregation (location) VALUES
( ST_GEOMFROMTEXT('POINT(0 -0)'         ,4326)),
( NULL);
# F-7 Aggregations with Nulls inside will just miss an element for each
# Null
# the result here shall be 1
SELECT ST_EQUALS((SELECT ST_COLLECT(LOCATION) AS T FROM
table_simple_aggregation), ST_GEOMFROMTEXT('GEOMETRYCOLLECTION( MULTIPOINT((0
0),(1 0),(3 0)), MULTIPOINT((2 0),(0 0)), POINT(0 0))',4326));
ST_EQUALS((SELECT ST_COLLECT(LOCATION) AS T FROM
table_simple_aggregation), ST_GEOMFROMTEXT('GEOMETRYCOLLECTION( MULTIPOINT((0
0),(1 0),(3 0)), MULTIPOINT((2 0),(0 0)), POINT(0 0))',4326))
1
# F-1 ST_COLLECT SHALL only return NULL if all elements are NULL or the
# aggregate is empty.
# as only a null is aggregated the result of the subquery shall be NULL
# and the result of the whole query shall be 1
SELECT  (SELECT ST_COLLECT(location) AS t FROM table_simple_aggregation WHERE
location = NULL) IS NULL;
(SELECT ST_COLLECT(location) AS t FROM table_simple_aggregation WHERE
location = NULL) IS NULL
1
# as no element is aggregated the result of the subquery shall be NULL
# and the result of the whole query shall be 1
SELECT  (SELECT ST_COLLECT(location) AS t FROM table_simple_aggregation WHERE
st_srid(location)=2110) IS NULL;
(SELECT ST_COLLECT(location) AS t FROM table_simple_aggregation WHERE
st_srid(location)=2110) IS NULL
1
INSERT INTO table_simple_aggregation (location) VALUES
( ST_GEOMFROMTEXT('POINT(0 -0)'         ,4326)),
( NULL),
( NULL);
SELECT ST_ASTEXT(ST_COLLECT(location) OVER ( ROWS BETWEEN 1 PRECEDING AND
CURRENT ROW))  FROM table_simple_aggregation;
ST_ASTEXT(ST_COLLECT(location) OVER ( ROWS BETWEEN 1 PRECEDING AND
CURRENT ROW))
MULTIPOINT((0 0))
MULTIPOINT((0 0),(0 0))
MULTIPOINT((0 0),(1 0))
MULTIPOINT((1 0),(2 0))
MULTIPOINT((2 0),(3 0))
MULTIPOINT((3 0),(0 0))
MULTIPOINT((0 0))
MULTIPOINT((0 0))
MULTIPOINT((0 0))
NULL
Excercising multiple code paths.
SELECT ST_ASTEXT(ST_COLLECT(DISTINCT location)) AS geo, SUM(running_number)
OVER()  FROM table_simple_aggregation GROUP BY running_number;
geo	SUM(running_number)
MULTIPOINT((0 0))	55
MULTIPOINT((0 0))	55
MULTIPOINT((0 0))	55
MULTIPOINT((0 0))	55
MULTIPOINT((1 0))	55
MULTIPOINT((2 0))	55
MULTIPOINT((3 0))	55
NULL	55
NULL	55
NULL	55
OVER()
SELECT ST_ASTEXT(ST_COLLECT(DISTINCT location)) AS geo, SUM(grouping_condition)
OVER(), grouping_condition FROM table_simple_aggregation GROUP BY
grouping_condition;
geo	SUM(grouping_condition)
MULTIPOINT((0 0))	1	NULL
MULTIPOINT((0 0),(1 0),(3 0))	1	0
MULTIPOINT((0 0),(2 0))	1	1
OVER()	grouping_condition
SELECT ST_ASTEXT(ST_COLLECT(location)) AS geo, SUM(grouping_condition) OVER(),
grouping_condition FROM table_simple_aggregation GROUP BY grouping_condition;
geo	SUM(grouping_condition) OVER()	grouping_condition
MULTIPOINT((0 0),(0 0))	1	NULL
MULTIPOINT((0 0),(1 0),(3 0))	1	0
MULTIPOINT((0 0),(2 0))	1	1
SELECT ST_ASTEXT(ST_COLLECT(location)) AS geo, SUM(running_number) OVER()  FROM
table_simple_aggregation GROUP BY running_number;
geo	SUM(running_number) OVER()
MULTIPOINT((0 0))	55
MULTIPOINT((0 0))	55
MULTIPOINT((0 0))	55
MULTIPOINT((0 0))	55
MULTIPOINT((1 0))	55
MULTIPOINT((2 0))	55
MULTIPOINT((3 0))	55
NULL	55
NULL	55
NULL	55
# Teardown of testing NULL data
DROP TABLE table_simple_aggregation;
# Setup for testing handling of multiple SRS
CREATE TABLE multi_srs_table ( running_number INTEGER NOT NULL AUTO_INCREMENT,
geometry GEOMETRY , PRIMARY KEY ( running_number ));
INSERT INTO multi_srs_table( geometry ) VALUES
(ST_GEOMFROMTEXT('POINT(60 -24)'         ,4326)),
(ST_GEOMFROMTEXT('POINT(61 -24)'         ,4326)),
(ST_GEOMFROMTEXT('POINT(38 77)'));
# F-2 a) If the elements in an aggregate is of different SRSs,
# ST_COLLECT MUST raise ER_GIS_DIFFERENT_SRIDS.
SELECT ST_ASTEXT(ST_COLLECT(geometry)) AS t FROM multi_srs_table;
ERROR 22S05: Arguments to function st_collect contains geometries with different SRIDs: 4326 and 0. All geometries must have the same SRID.
# F-2 b) If all the elements in an aggregate is of same SRS, ST_COLLECT
# MUST return a result in that SRS.
# result shall be one MULTIPOINT((60 -24),(61 -24)) with SRID 4326 and
# one
# Multipoint((38 77)) with SRID 0. There is some rounding issue on the
# result, bug #31535105
SELECT st_srid(geometry),ST_ASTEXT(ST_COLLECT( geometry )) AS t FROM
multi_srs_table GROUP BY ST_SRID(geometry);
st_srid(geometry)	t
0	MULTIPOINT((38 77))
4326	MULTIPOINT((60 -24),(61.00000000000001 -24))
Rollup needs all SRIDs to be the same. 
SELECT st_srid(geometry),ST_ASTEXT(ST_COLLECT( geometry )) AS t FROM
multi_srs_table GROUP BY ST_SRID(geometry) WITH ROLLUP;
ERROR 22S05: Arguments to function st_collect contains geometries with different SRIDs: 0 and 4326. All geometries must have the same SRID.
# Triggering a codepath for geometrycollection in temp tables
INSERT INTO multi_srs_table( geometry ) VALUES
(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION(POINT(60 -24))'         ,4326));
SELECT st_srid(geometry),ST_ASTEXT(ST_COLLECT( geometry )) AS t FROM
multi_srs_table GROUP BY ST_SRID(geometry);
st_srid(geometry)	t
0	MULTIPOINT((38 77))
4326	GEOMETRYCOLLECTION(POINT(60 -24),POINT(61.00000000000001 -24),GEOMETRYCOLLECTION(POINT(60 -24)))
#teardown of testing handling of multiple SRS
DROP TABLE multi_srs_table;
# setup of testing handling different geometry types
CREATE TABLE simple_table ( running_number INTEGER NOT NULL AUTO_INCREMENT ,
geo GEOMETRY, PRIMARY KEY ( RUNNING_NUMBER));
INSERT INTO simple_table ( geo) VALUES
(ST_GEOMFROMTEXT('POINT(0 0)')),
(ST_GEOMFROMTEXT('LINESTRING(1 0, 1 1)')),
(ST_GEOMFROMTEXT('LINESTRING(2 0, 2 1)')),
(ST_GEOMFROMTEXT('POLYGON((3 0, 0 0, 0 3, 3 3, 3 0))')),
(ST_GEOMFROMTEXT('POLYGON((4 0, 0 0, 0 4, 4 4, 4 0))')),
(ST_GEOMFROMTEXT('MULTIPOINT(5 0)')),
(ST_GEOMFROMTEXT('MULTIPOINT(6 0)')),
(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY')),
(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY'));
# Functional requirement F-9 a, b, and c ) An aggregation containing
# more than one type of geometry or any MULTI is GEOMETRYCOLLECTION, if
# it only contains a single type of POINTS, LINESTRINGS or POLYGONS it
# will be a MULTI of the same kind.
# MP: Multipoint
# MPoly: Multipolygon
# MLS: Multilinestring
# GC: geometrycollection
# Functional requirement F-6 shall support window functions
# result is expected for come in this order: MP, GC, MLS, GC, MPpoly,
# GC, GC, GC, GC
SELECT ST_ASTEXT(ST_COLLECT(geo) OVER( ORDER BY running_number ROWS BETWEEN 1
PRECEDING AND CURRENT ROW)) AS geocollect  FROM simple_table;
geocollect
MULTIPOINT((0 0))
GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(1 0,1 1))
MULTILINESTRING((1 0,1 1),(2 0,2 1))
GEOMETRYCOLLECTION(LINESTRING(2 0,2 1),POLYGON((3 0,3 3,0 3,0 0,3 0)))
MULTIPOLYGON(((3 0,3 3,0 3,0 0,3 0)),((4 0,4 4,0 4,0 0,4 0)))
GEOMETRYCOLLECTION(POLYGON((4 0,4 4,0 4,0 0,4 0)),MULTIPOINT((5 0)))
GEOMETRYCOLLECTION(MULTIPOINT((5 0)),MULTIPOINT((6 0)))
GEOMETRYCOLLECTION(MULTIPOINT((6 0)),GEOMETRYCOLLECTION EMPTY)
GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY,GEOMETRYCOLLECTION EMPTY)
# with DISTINCT this result is expected to be:
# GEMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)
# GEMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)
SELECT ST_ASTEXT(ST_COLLECT( DISTINCT geo) OVER( ORDER BY running_number ROWS
BETWEEN 1 PRECEDING AND CURRENT ROW)) AS geocollect  FROM simple_table WHERE
ST_EQUALS(geo,ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY'));
geocollect
GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)
GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)
# Exercising the "copy" constructor
SELECT ST_ASTEXT(ST_COLLECT(geo)) FROM simple_table GROUP BY geo WITH ROLLUP;
ST_ASTEXT(ST_COLLECT(geo))
MULTIPOINT((0 0))
MULTILINESTRING((2 0,2 1))
MULTILINESTRING((1 0,1 1))
MULTIPOLYGON(((3 0,3 3,0 3,0 0,3 0)))
MULTIPOLYGON(((4 0,4 4,0 4,0 0,4 0)))
GEOMETRYCOLLECTION(MULTIPOINT((5 0)))
GEOMETRYCOLLECTION(MULTIPOINT((6 0)))
GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY,GEOMETRYCOLLECTION EMPTY)
GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(2 0,2 1),LINESTRING(1 0,1 1),POLYGON((3 0,3 3,0 3,0 0,3 0)),POLYGON((4 0,4 4,0 4,0 0,4 0)),MULTIPOINT((5 0)),MULTIPOINT((6 0)),GEOMETRYCOLLECTION EMPTY,GEOMETRYCOLLECTION EMPTY)
# Casting Geometry as decimal invokes val_decimal()
SELECT CAST(ST_COLLECT(geo) AS DECIMAL ) FROM simple_table;
CAST(ST_COLLECT(geo) AS DECIMAL )
0
DROP TABLE simple_table;
set @d:=repeat(1,228);
select st_collect(substr(@d,110,47));
ERROR SR001: There's no spatial reference system with SRID 825307441.
select st_collect(left(@d,42));
ERROR SR001: There's no spatial reference system with SRID 825307441.
select st_collect(right(@d,42));
ERROR SR001: There's no spatial reference system with SRID 825307441.