Merge pull request #227 from CartoDB/226-add_count_aggregated_features
Include and aggregate _vovw_count column to count aggregated features
This commit is contained in:
@@ -539,8 +539,12 @@ BEGIN
|
|||||||
column_type := CDB_ColumnType(reloid, column_name);
|
column_type := CDB_ColumnType(reloid, column_name);
|
||||||
|
|
||||||
CASE column_type
|
CASE column_type
|
||||||
WHEN 'double precision', 'real', 'integer', 'bigint' THEN
|
WHEN 'double precision', 'real', 'integer', 'bigint', 'numeric' THEN
|
||||||
RETURN Format('AVG(%s)::' || column_type, qualified_column);
|
IF column_name = '_feature_count' THEN
|
||||||
|
RETURN 'SUM(_feature_count)';
|
||||||
|
ELSE
|
||||||
|
RETURN Format('AVG(%s)::' || column_type, qualified_column);
|
||||||
|
END IF;
|
||||||
WHEN 'text' THEN
|
WHEN 'text' THEN
|
||||||
-- TODO: we could define a new aggregate function that returns distinct
|
-- TODO: we could define a new aggregate function that returns distinct
|
||||||
-- separated values with a limit, adding ellipsis if more values existed
|
-- separated values with a limit, adding ellipsis if more values existed
|
||||||
@@ -677,6 +681,10 @@ AS $$
|
|||||||
SELECT * FROM cols
|
SELECT * FROM cols
|
||||||
) AS s INTO columns;
|
) AS s INTO columns;
|
||||||
|
|
||||||
|
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);
|
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
|
-- Now we cluster the data using a grid of size grid_m
|
||||||
@@ -739,6 +747,7 @@ DECLARE
|
|||||||
overview_z integer;
|
overview_z integer;
|
||||||
overview_tables REGCLASS[];
|
overview_tables REGCLASS[];
|
||||||
overviews_step integer := 1;
|
overviews_step integer := 1;
|
||||||
|
has_counter_column boolean;
|
||||||
BEGIN
|
BEGIN
|
||||||
-- Determine the referece zoom level
|
-- Determine the referece zoom level
|
||||||
EXECUTE 'SELECT ' || quote_ident(refscale_strategy::text) || Format('(''%s'', %s);', reloid, tolerance_px) INTO ref_z;
|
EXECUTE 'SELECT ' || quote_ident(refscale_strategy::text) || Format('(''%s'', %s);', reloid, tolerance_px) INTO ref_z;
|
||||||
@@ -768,6 +777,17 @@ BEGIN
|
|||||||
SELECT array_append(overview_tables, base_rel) INTO overview_tables;
|
SELECT array_append(overview_tables, base_rel) INTO overview_tables;
|
||||||
END LOOP;
|
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 = '_feature_count'
|
||||||
|
) INTO has_counter_column;
|
||||||
|
IF NOT has_counter_column THEN
|
||||||
|
EXECUTE Format('
|
||||||
|
ALTER TABLE %s ADD COLUMN _feature_count integer DEFAULT 1;
|
||||||
|
', reloid);
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
|
||||||
RETURN overview_tables;
|
RETURN overview_tables;
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE PLPGSQL;
|
$$ LANGUAGE PLPGSQL;
|
||||||
|
|||||||
Reference in New Issue
Block a user