From 16d08ef52bfbac1f3e23a68ecd462f6f5916b834 Mon Sep 17 00:00:00 2001 From: Carla Iriberri Date: Tue, 12 Apr 2016 11:10:55 +0200 Subject: [PATCH 1/4] Include and aggregate _vovw_count column to count aggregated features --- scripts-available/CDB_Overviews.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index b80be3d..f00d1b0 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -510,7 +510,11 @@ BEGIN CASE column_type WHEN 'double precision', 'real', 'integer', 'bigint' THEN - RETURN Format('AVG(%s)::' || column_type, qualified_column); + IF column_name = '_vovw_count' THEN + RETURN 'SUM(_vovw_count)'; + ELSE + RETURN Format('AVG(%s)::' || column_type, qualified_column); + END IF; WHEN 'text' THEN -- TODO: we could define a new aggregate function that returns distinct -- separated values with a limit, adding ellipsis if more values existed @@ -648,6 +652,10 @@ AS $$ SELECT * FROM cols ) AS s INTO columns; + IF NOT columns LIKE '%_vovw_count%' THEN + columns := columns || ', n AS _vovw_count'; + END IF; + EXECUTE Format('DROP TABLE IF EXISTS %I.%I CASCADE;', schema_name, overview_rel); -- Now we cluster the data using a grid of size grid_m From f785e71d3b61c986a12e0cd5767e19568b616a2a Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 14 Apr 2016 15:46:03 +0200 Subject: [PATCH 2/4] Fix: numeric is a valid numeric column type Actually this is the type of aggregated _vovw_count columns --- scripts-available/CDB_Overviews.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index f00d1b0..04beae3 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -509,7 +509,7 @@ BEGIN column_type := CDB_ColumnType(reloid, column_name); CASE column_type - WHEN 'double precision', 'real', 'integer', 'bigint' THEN + WHEN 'double precision', 'real', 'integer', 'bigint', 'numeric' THEN IF column_name = '_vovw_count' THEN RETURN 'SUM(_vovw_count)'; ELSE From c595e45c11a1272664f056ca0c589bd7193f4599 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 14 Apr 2016 17:32:18 +0200 Subject: [PATCH 3/4] Add _vovw_count columnt to tables for which overviews are created Initially we planned to add this column to the queries sent to the tiler only, but that makes the column hard to access from the editor. --- scripts-available/CDB_Overviews.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index 04beae3..1285e3c 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -718,6 +718,7 @@ DECLARE overview_z integer; overview_tables REGCLASS[]; overviews_step integer := 1; + has_counter_column boolean; BEGIN -- Determine the referece zoom level EXECUTE 'SELECT ' || quote_ident(refscale_strategy::text) || Format('(''%s'', %s);', reloid, tolerance_px) INTO ref_z; @@ -743,6 +744,17 @@ BEGIN SELECT array_append(overview_tables, base_rel) INTO overview_tables; END LOOP; + IF overview_tables IS NOT NULL AND array_length(overview_tables, 1) > 0 THEN + SELECT EXISTS ( + SELECT * FROM CDB_ColumnNames(reloid) as colname WHERE colname = '_vovw_count' + ) INTO has_counter_column; + IF NOT has_counter_column THEN + EXECUTE Format(' + ALTER TABLE %s ADD COLUMN _vovw_count integer DEFAULT 1; + ', reloid); + END IF; + END IF; + RETURN overview_tables; END; $$ LANGUAGE PLPGSQL; From fd14750ce558965c23fbf1508e1308c6bb26d315 Mon Sep 17 00:00:00 2001 From: Carla Iriberri Date: Thu, 14 Apr 2016 18:23:09 +0200 Subject: [PATCH 4/4] Rename _vovw_count to _feature_count --- scripts-available/CDB_Overviews.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index 1285e3c..20345f2 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -510,8 +510,8 @@ BEGIN CASE column_type WHEN 'double precision', 'real', 'integer', 'bigint', 'numeric' THEN - IF column_name = '_vovw_count' THEN - RETURN 'SUM(_vovw_count)'; + IF column_name = '_feature_count' THEN + RETURN 'SUM(_feature_count)'; ELSE RETURN Format('AVG(%s)::' || column_type, qualified_column); END IF; @@ -652,8 +652,8 @@ AS $$ SELECT * FROM cols ) AS s INTO columns; - IF NOT columns LIKE '%_vovw_count%' THEN - columns := columns || ', n AS _vovw_count'; + IF NOT columns LIKE '%_feature_count%' THEN + columns := columns || ', n AS _feature_count'; END IF; EXECUTE Format('DROP TABLE IF EXISTS %I.%I CASCADE;', schema_name, overview_rel); @@ -746,11 +746,11 @@ BEGIN IF overview_tables IS NOT NULL AND array_length(overview_tables, 1) > 0 THEN SELECT EXISTS ( - SELECT * FROM CDB_ColumnNames(reloid) as colname WHERE colname = '_vovw_count' + SELECT * FROM CDB_ColumnNames(reloid) as colname WHERE colname = '_feature_count' ) INTO has_counter_column; IF NOT has_counter_column THEN EXECUTE Format(' - ALTER TABLE %s ADD COLUMN _vovw_count integer DEFAULT 1; + ALTER TABLE %s ADD COLUMN _feature_count integer DEFAULT 1; ', reloid); END IF; END IF;