diff --git a/Makefile b/Makefile index 01e9325..2f31953 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # cartodb/Makefile EXTENSION = cartodb -EXTVERSION = 0.20.0 +EXTVERSION = 0.21.0 SED = sed AWK = awk @@ -84,6 +84,7 @@ UPGRADABLE = \ 0.19.1 \ 0.19.2 \ 0.20.0 \ + 0.21.0 \ $(EXTVERSION)dev \ $(EXTVERSION)next \ $(END) diff --git a/NEWS.md b/NEWS.md index 233454f..961e9d2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +0.21.0 (2018-02-15) +* Add optional parameter to limit the number of cells in grid-generation functions #322 +* Fix: grant usage on cartodb_id sequence when sharing read write #323 +* Fix: Change sed in-place for tmpfiles 524319 + 0.20.0 (2017-11-08) * Added VOLATILITY and PARALLEL categories to all functions diff --git a/scripts-available/CDB_Hexagon.sql b/scripts-available/CDB_Hexagon.sql index 68430b1..bb2b82d 100644 --- a/scripts-available/CDB_Hexagon.sql +++ b/scripts-available/CDB_Hexagon.sql @@ -10,6 +10,10 @@ AS $$ WHERE path[1] % 2 != 0 $$ LANGUAGE 'sql' IMMUTABLE STRICT PARALLEL SAFE; + +-- In older versions of the extension, CDB_HexagonGrid had a different signature +DROP FUNCTION IF EXISTS cartodb.CDB_HexagonGrid(GEOMETRY, FLOAT8, GEOMETRY); + -- -- Fill given extent with an hexagonal coverage -- @@ -25,10 +29,13 @@ $$ LANGUAGE 'sql' IMMUTABLE STRICT PARALLEL SAFE; -- If omitted the origin will be 0,0. -- The parameter is checked for having the same SRID -- as the extent. --- -- +-- @param maxcells Optional maximum number of grid cells to generate; +-- if the grid requires more cells to cover the extent +-- and exception will occur. +---- -- DROP FUNCTION IF EXISTS CDB_HexagonGrid(ext GEOMETRY, side FLOAT8); -CREATE OR REPLACE FUNCTION CDB_HexagonGrid(ext GEOMETRY, side FLOAT8, origin GEOMETRY DEFAULT NULL) +CREATE OR REPLACE FUNCTION CDB_HexagonGrid(ext GEOMETRY, side FLOAT8, origin GEOMETRY DEFAULT NULL, maxcells INTEGER DEFAULT 512*512) RETURNS SETOF GEOMETRY AS $$ DECLARE @@ -107,6 +114,12 @@ BEGIN vstartary := ARRAY[ vstart - (vstep/2.0), vstart ]; END IF; + If maxcells IS NOT NULL AND maxcells > 0 THEN + IF CEIL((CEIL((vend-vstart)/(vstep/2.0)) * CEIL((hend-hstart)/(hstep*2.0/3.0)))/3.0)::integer > maxcells THEN + RAISE EXCEPTION 'The requested grid is too big to be rendered'; + END IF; + END IF; + vstartidx := abs(hskip)%2; RAISE DEBUG 'vstartary: % : %', vstartary[1], vstartary[2]; diff --git a/scripts-available/CDB_Organizations.sql b/scripts-available/CDB_Organizations.sql index b49529d..9af6081 100644 --- a/scripts-available/CDB_Organizations.sql +++ b/scripts-available/CDB_Organizations.sql @@ -111,6 +111,7 @@ AS $$ BEGIN EXECUTE 'GRANT USAGE ON SCHEMA "' || from_schema || '" TO "' || to_role_name || '"'; EXECUTE 'GRANT SELECT, INSERT, UPDATE, DELETE ON "' || from_schema || '"."' || table_name || '" TO "' || to_role_name || '"'; + EXECUTE 'GRANT USAGE, SELECT ON SEQUENCE ' || pg_catalog.pg_get_serial_sequence(Format('%I.%I', from_schema, table_name), 'cartodb_id') || ' TO "' || to_role_name || '"'; END $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; diff --git a/scripts-available/CDB_RectangleGrid.sql b/scripts-available/CDB_RectangleGrid.sql index c2bc166..6c01e03 100644 --- a/scripts-available/CDB_RectangleGrid.sql +++ b/scripts-available/CDB_RectangleGrid.sql @@ -1,3 +1,6 @@ +-- In older versions of the extension, CDB_RectangleGrid had a different signature +DROP FUNCTION IF EXISTS cartodb.CDB_RectangleGrid(GEOMETRY, FLOAT8, FLOAT8, GEOMETRY); + -- -- Fill given extent with a rectangular coverage -- @@ -14,9 +17,12 @@ -- If omitted the origin will be 0,0. -- The parameter is checked for having the same SRID -- as the extent. --- -- -CREATE OR REPLACE FUNCTION CDB_RectangleGrid(ext GEOMETRY, width FLOAT8, height FLOAT8, origin GEOMETRY DEFAULT NULL) +-- @param maxcells Optional maximum number of grid cells to generate; +-- if the grid requires more cells to cover the extent +-- and exception will occur. +-- +CREATE OR REPLACE FUNCTION CDB_RectangleGrid(ext GEOMETRY, width FLOAT8, height FLOAT8, origin GEOMETRY DEFAULT NULL, maxcells INTEGER DEFAULT 512*512) RETURNS SETOF GEOMETRY AS $$ DECLARE @@ -79,6 +85,12 @@ BEGIN --RAISE DEBUG 'hend: %', hend; --RAISE DEBUG 'vend: %', vend; + If maxcells IS NOT NULL AND maxcells > 0 THEN + IF ((hend - hstart)/hstep * (vend - vstart)/vstep)::integer > maxcells THEN + RAISE EXCEPTION 'The requested grid is too big to be rendered'; + END IF; + END IF; + x := hstart; WHILE x < hend LOOP -- over X y := vstart; diff --git a/test/CDB_HexagonTest.sql b/test/CDB_HexagonTest.sql index 66b52b1..038540d 100644 --- a/test/CDB_HexagonTest.sql +++ b/test/CDB_HexagonTest.sql @@ -1,3 +1,6 @@ +set client_min_messages to error; +\set VERBOSITY TERSE + -- Check correctness of an hexagons grid -- -- Cells must have no overlaps and have a number of @@ -45,3 +48,9 @@ WITH 0.002 as radius ), grid AS ( SELECT CDB_HexagonGrid(env, radius) AS cell from params) SELECT '#160', count(cell) > 23000 from grid; + +-- Check small grids are generated... +SELECT COUNT(*) FROM cartodb.CDB_HexagonGrid(ST_MakeEnvelope(0,0,1000,1000,3857), 10); + +-- But large grids produce an error +SELECT COUNT(*) FROM cartodb.CDB_HexagonGrid(ST_MakeEnvelope(0,0,1000,1000,3857), 1); diff --git a/test/CDB_HexagonTest_expect b/test/CDB_HexagonTest_expect index 08e74f2..42c7fec 100644 --- a/test/CDB_HexagonTest_expect +++ b/test/CDB_HexagonTest_expect @@ -1,2 +1,5 @@ +SET 9|63|count / npoints #160|t +3886 +ERROR: The requested grid is too big to be rendered diff --git a/test/CDB_RectangleTest.sql b/test/CDB_RectangleTest.sql new file mode 100644 index 0000000..a16b7fa --- /dev/null +++ b/test/CDB_RectangleTest.sql @@ -0,0 +1,8 @@ +set client_min_messages to error; +\set VERBOSITY TERSE + +-- Check small grids are generated... +SELECT COUNT(*) FROM cartodb.CDB_RectangleGrid(ST_MakeEnvelope(0,0,1000,1000,3857), 10, 10); + +-- But large grids produce an error +SELECT COUNT(*) FROM cartodb.CDB_RectangleGrid(ST_MakeEnvelope(0,0,1000,1000,3857), 1, 1); diff --git a/test/CDB_RectangleTest_expect b/test/CDB_RectangleTest_expect new file mode 100644 index 0000000..cc1c961 --- /dev/null +++ b/test/CDB_RectangleTest_expect @@ -0,0 +1,3 @@ +SET +10000 +ERROR: The requested grid is too big to be rendered diff --git a/test/organization/test.sh b/test/organization/test.sh index f32dfa7..b7b9d83 100644 --- a/test/organization/test.sh +++ b/test/organization/test.sh @@ -315,6 +315,8 @@ function test_member_1_cannot_grant_read_write_permission_to_other_schema_than_i } function test_member_2_can_write_to_member_1_table_after_write_permission_is_added() { + sql cdb_testmember_1 "ALTER TABLE cdb_testmember_1.foo ADD cartodb_id SERIAL NOT NULL UNIQUE;" + sql cdb_testmember_1 "SELECT * FROM cartodb.CDB_Organization_Add_Table_Read_Write_Permission('cdb_testmember_1', 'foo', 'cdb_testmember_2')" sql cdb_testmember_2 'INSERT INTO cdb_testmember_1.foo VALUES (5), (6), (7), (8), (9);' sql cdb_testmember_1 'SELECT count(*) FROM cdb_testmember_1.foo;' should 10 @@ -322,6 +324,8 @@ function test_member_2_can_write_to_member_1_table_after_write_permission_is_add sql cdb_testmember_2 'DELETE FROM cdb_testmember_1.foo where a = 9;' sql cdb_testmember_1 'SELECT count(*) FROM cdb_testmember_1.foo;' should 9 sql cdb_testmember_2 'SELECT count(*) FROM cdb_testmember_1.foo;' should 9 + + sql cdb_testmember_1 "ALTER TABLE cdb_testmember_1.foo DROP cartodb_id;" } function test_member_1_removes_access_and_member_2_can_no_longer_query_the_table() { @@ -332,10 +336,14 @@ function test_member_1_removes_access_and_member_2_can_no_longer_query_the_table } function test_member_1_removes_access_and_member_2_can_no_longer_write_to_the_table() { + sql cdb_testmember_1 "ALTER TABLE cdb_testmember_1.foo ADD cartodb_id SERIAL NOT NULL UNIQUE;" + sql cdb_testmember_1 "SELECT * FROM cartodb.CDB_Organization_Add_Table_Read_Write_Permission('cdb_testmember_1', 'foo', 'cdb_testmember_2')" sql cdb_testmember_2 'INSERT INTO cdb_testmember_1.foo VALUES (5), (6), (7), (8), (9);' sql cdb_testmember_1 "SELECT * FROM cartodb.CDB_Organization_Remove_Access_Permission('cdb_testmember_1', 'foo', 'cdb_testmember_2')" sql cdb_testmember_2 'INSERT INTO cdb_testmember_1.foo VALUES (5), (6), (7), (8), (9);' fails + + sql cdb_testmember_1 "ALTER TABLE cdb_testmember_1.foo DROP cartodb_id;" } function test_giving_permissions_to_two_tables_and_removing_from_first_table_should_not_remove_from_second() { @@ -418,7 +426,7 @@ function test_cdb_usertables_should_work_with_orgusers() { sql cdb_testmember_1 "CREATE TABLE test_perms_pub (a int)" sql cdb_testmember_1 "INSERT INTO test_perms_pub (a) values (1);" sql cdb_testmember_1 "GRANT SELECT ON TABLE test_perms_pub TO publicuser" - + sql cdb_testmember_1 "CREATE TABLE test_perms_priv (a int)"