From 3026650797d33cd42ccbfcb101f8f8ac97949f02 Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Thu, 18 Apr 2019 05:35:07 +0000 Subject: [PATCH] Remove ST_Accum. Please use array_agg instead. Closes #4356 Closes https://github.com/postgis/postgis/pull/393 git-svn-id: http://svn.osgeo.org/postgis/trunk@17397 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + doc/reference_accessor.xml | 4 +-- doc/reference_constructor.xml | 8 ++--- doc/reference_processing.xml | 61 ---------------------------------- postgis/legacy.sql.in | 10 ------ postgis/lwgeom_accum.c | 22 ------------ postgis/postgis.sql.in | 19 ----------- postgis/postgis_drop_after.sql | 2 ++ postgis/postgis_legacy.c | 1 + regress/core/cluster.sql | 4 +-- 10 files changed, 11 insertions(+), 121 deletions(-) diff --git a/NEWS b/NEWS index 13aba984b..5e8daa9d2 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,7 @@ PostGIS 3.0.0 - #4268, Bump minimum SFCGAL version to 1.3.1 (Darafei Praliaskouski) - #4331, ST_3DMakeBox now returns error instead of a miniscule box (Regina Obe) - #4342, Removed "versioned" variants of ST_AsGeoJSON and ST_AsKML (Paul Ramsey) + - #4356, ST_Accum removed. Use array_agg instead. (Darafei Praliaskouski) * New Features * - #2902, postgis_geos_noop (Sandro Santilli) diff --git a/doc/reference_accessor.xml b/doc/reference_accessor.xml index 65a125fe4..9dccc6a93 100644 --- a/doc/reference_accessor.xml +++ b/doc/reference_accessor.xml @@ -1588,7 +1588,7 @@ Allowed flags are documented in or to generate line strings. @@ -1604,15 +1604,14 @@ FROM Build province boundaries with holes representing lakes in the province from a set of province polygons/multipolygons and water linestrings. - This is an example of using PostGIS ST_Accum. The CASE construct is used because feeding a null array into ST_MakePolygon results in NULL. A left join is used to guarantee we get all provinces back even if they have no lakes. SELECT p.gid, p.province_name, CASE WHEN - ST_Accum(w.the_geom) IS NULL THEN p.the_geom - ELSE ST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)), ST_Accum(w.the_geom)) END + array_agg(w.the_geom) IS NULL THEN p.the_geom + ELSE ST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)), array_agg(w.the_geom)) END FROM provinces p LEFT JOIN waterlines w ON (ST_Within(w.the_geom, p.the_geom) AND ST_IsClosed(w.the_geom)) @@ -1641,7 +1640,6 @@ FROM See Also , - , , , , diff --git a/doc/reference_processing.xml b/doc/reference_processing.xml index 7adddcb1a..8d5541aa0 100644 --- a/doc/reference_processing.xml +++ b/doc/reference_processing.xml @@ -1,67 +1,6 @@ Geometry Processing - - - - ST_Accum - - An aggregate function to construct an array of geometries. - - - - - - geometry[] ST_Accum - geometry set geomfield - - - - - - Description - - An aggregate function to construct an array of geometries. - Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced. - &Z_support; - &curve_support; - &P_support; - &T_support; - - - - - Examples - - SELECT (ST_Accum(the_geom)) As all_em, ST_AsText((ST_Accum(the_geom))[1]) As grabone, -(ST_Accum(the_geom))[2:4] as grab_rest - FROM (SELECT ST_MakePoint(a*CAST(random()*10 As integer), a*CAST(random()*10 As integer), a*CAST(random()*10 As integer)) As the_geom - FROM generate_series(1,4) a) As foo; - -all_em|grabone | grab_rest - --------------------------------------------------------------------------------+ - - {0101000080000000000000144000000000000024400000000000001040: - 0101000080000000000 -00018400000000000002C400000000000003040: -0101000080000000000000354000000000000038400000000000001840: -010100008000000000000040400000000000003C400000000000003040} | - POINT(5 10) | {010100008000000000000018400000000000002C400000000000003040: - 0101000080000000000000354000000000000038400000000000001840: - 010100008000000000000040400000000000003C400000000000003040} -(1 row) - - - - - - See Also - - - - - ST_Buffer diff --git a/postgis/legacy.sql.in b/postgis/legacy.sql.in index 985f8217e..6a720dda0 100644 --- a/postgis/legacy.sql.in +++ b/postgis/legacy.sql.in @@ -2091,16 +2091,6 @@ CREATE OR REPLACE FUNCTION ST_distance_sphere(geom1 geometry, geom2 geometry) -- end Old underscored_names replaced by CamelCase names - ---- Start Aggregates and supporting functions -- --- Deprecation in: 1.2.3 --- Changed: 2.5.0 use 'internal' stype -CREATE AGGREGATE accum ( - sfunc = pgis_geometry_accum_transfn, - basetype = geometry, - stype = internal, - finalfunc = pgis_geometry_accum_finalfn - ); -- Deprecation in 1.2.3 CREATE OR REPLACE FUNCTION collect(geometry, geometry) RETURNS geometry diff --git a/postgis/lwgeom_accum.c b/postgis/lwgeom_accum.c index db7ccd3fe..ad28228f8 100644 --- a/postgis/lwgeom_accum.c +++ b/postgis/lwgeom_accum.c @@ -42,7 +42,6 @@ Datum PGISDirectFunctionCall1(PGFunction func, Datum arg1); Datum PGISDirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2); Datum pgis_geometry_accum_transfn(PG_FUNCTION_ARGS); -Datum pgis_geometry_accum_finalfn(PG_FUNCTION_ARGS); Datum pgis_geometry_union_finalfn(PG_FUNCTION_ARGS); Datum pgis_geometry_collect_finalfn(PG_FUNCTION_ARGS); Datum pgis_geometry_polygonize_finalfn(PG_FUNCTION_ARGS); @@ -175,27 +174,6 @@ pgis_accum_finalfn(pgis_abs *p, MemoryContext mctx, __attribute__((__unused__)) return result; } -/** -** The "accum" final function just returns the geometry[] -*/ -PG_FUNCTION_INFO_V1(pgis_geometry_accum_finalfn); -Datum -pgis_geometry_accum_finalfn(PG_FUNCTION_ARGS) -{ - pgis_abs *p; - Datum result = 0; - - if (PG_ARGISNULL(0)) - PG_RETURN_NULL(); /* returns null iff no input values */ - - p = (pgis_abs*) PG_GETARG_POINTER(0); - - result = pgis_accum_finalfn(p, CurrentMemoryContext, fcinfo); - - PG_RETURN_DATUM(result); - -} - /** * The "union" final function passes the geometry[] to a union * conversion before returning the result. diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in index 4133362c4..586036999 100644 --- a/postgis/postgis.sql.in +++ b/postgis/postgis.sql.in @@ -3820,13 +3820,6 @@ CREATE OR REPLACE FUNCTION pgis_geometry_accum_transfn(internal, geometry, float AS 'MODULE_PATHNAME' LANGUAGE 'c' _PARALLEL; --- Availability: 1.4.0 --- Changed: 2.5.0 use 'internal' transfer type -CREATE OR REPLACE FUNCTION pgis_geometry_accum_finalfn(internal) - RETURNS geometry[] - AS 'MODULE_PATHNAME' - LANGUAGE 'c' _PARALLEL; - -- Availability: 1.4.0 -- Changed: 2.5.0 use 'internal' transfer type CREATE OR REPLACE FUNCTION pgis_geometry_union_finalfn(internal) @@ -3869,18 +3862,6 @@ CREATE OR REPLACE FUNCTION pgis_geometry_makeline_finalfn(internal) AS 'MODULE_PATHNAME' LANGUAGE 'c' _PARALLEL; --- Availability: 1.2.2 --- Changed: 2.4.0 marked parallel safe --- Changed: 2.5.0 use 'internal' stype -CREATE AGGREGATE ST_Accum (geometry) ( - sfunc = pgis_geometry_accum_transfn, - stype = internal, -#if POSTGIS_PGSQL_VERSION >= 96 - parallel = safe, -#endif - finalfunc = pgis_geometry_accum_finalfn - ); - -- Availability: 1.4.0 CREATE OR REPLACE FUNCTION ST_Union (geometry[]) RETURNS geometry diff --git a/postgis/postgis_drop_after.sql b/postgis/postgis_drop_after.sql index 90079f9eb..b62dd2372 100644 --- a/postgis/postgis_drop_after.sql +++ b/postgis/postgis_drop_after.sql @@ -27,6 +27,8 @@ DROP AGGREGATE IF EXISTS collect(geometry); -- Deprecated in 1.2.3, Dropped in 2 DROP AGGREGATE IF EXISTS st_geomunion(geometry); DROP AGGREGATE IF EXISTS accum_old(geometry); DROP AGGREGATE IF EXISTS st_accum_old(geometry); +DROP AGGREGATE IF EXISTS st_accum(geometry); -- Dropped in 3.0.0 +DROP FUNCTION IF EXISTS pgis_geometry_accum_finalfn(internal); DROP AGGREGATE IF EXISTS st_astwkb_agg(geometry, integer); -- temporarely introduced before 2.2.0 final DROP AGGREGATE IF EXISTS st_astwkb_agg(geometry, integer, bigint); -- temporarely introduced before 2.2.0 final diff --git a/postgis/postgis_legacy.c b/postgis/postgis_legacy.c index 429012de7..d5cc9ef56 100644 --- a/postgis/postgis_legacy.c +++ b/postgis/postgis_legacy.c @@ -74,3 +74,4 @@ POSTGIS_DEPRECATE("3.0.0", distance3d); POSTGIS_DEPRECATE("3.0.0", sfcgal_distance3d); POSTGIS_DEPRECATE("3.0.0", LWGEOM_mindistance3d); POSTGIS_DEPRECATE("3.0.0", intersects); +POSTGIS_DEPRECATE("3.0.0", pgis_geometry_accum_finalfn); diff --git a/regress/core/cluster.sql b/regress/core/cluster.sql index 006d59598..d8ed0a89d 100644 --- a/regress/core/cluster.sql +++ b/regress/core/cluster.sql @@ -11,9 +11,9 @@ INSERT INTO cluster_inputs VALUES (7, 'POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))'); SELECT 't1', ST_AsText(unnest(ST_ClusterIntersecting(geom ORDER BY id))) FROM cluster_inputs; -SELECT 't2', ST_AsText(unnest(ST_ClusterIntersecting(ST_Accum(geom ORDER BY id)))) FROM cluster_inputs; +SELECT 't2', ST_AsText(unnest(ST_ClusterIntersecting(array_agg(geom ORDER BY id)))) FROM cluster_inputs; SELECT 't3', ST_AsText(unnest(ST_ClusterWithin(geom, 1.4 ORDER BY id))) FROM cluster_inputs; -SELECT 't4', ST_AsText(unnest(ST_ClusterWithin(ST_Accum(geom ORDER BY id), 1.5))) FROM cluster_inputs; +SELECT 't4', ST_AsText(unnest(ST_ClusterWithin(array_agg(geom ORDER BY id), 1.5))) FROM cluster_inputs; -- tests for ST_DBSCAN -- 2.40.0