Merge branch 'master' of github.com:CartoDB/cartodb-postgresql into seq-drop

This commit is contained in:
Paul Ramsey 2018-03-09 09:58:25 -08:00
commit 62c27ab140
10 changed files with 69 additions and 6 deletions

View File

@ -1,7 +1,7 @@
# cartodb/Makefile # cartodb/Makefile
EXTENSION = cartodb EXTENSION = cartodb
EXTVERSION = 0.20.0 EXTVERSION = 0.21.0
SED = sed SED = sed
AWK = awk AWK = awk
@ -84,6 +84,7 @@ UPGRADABLE = \
0.19.1 \ 0.19.1 \
0.19.2 \ 0.19.2 \
0.20.0 \ 0.20.0 \
0.21.0 \
$(EXTVERSION)dev \ $(EXTVERSION)dev \
$(EXTVERSION)next \ $(EXTVERSION)next \
$(END) $(END)

View File

@ -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) 0.20.0 (2017-11-08)
* Added VOLATILITY and PARALLEL categories to all functions * Added VOLATILITY and PARALLEL categories to all functions

View File

@ -10,6 +10,10 @@ AS $$
WHERE path[1] % 2 != 0 WHERE path[1] % 2 != 0
$$ LANGUAGE 'sql' IMMUTABLE STRICT PARALLEL SAFE; $$ 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 -- Fill given extent with an hexagonal coverage
-- --
@ -26,9 +30,12 @@ $$ LANGUAGE 'sql' IMMUTABLE STRICT PARALLEL SAFE;
-- The parameter is checked for having the same SRID -- The parameter is checked for having the same SRID
-- as the extent. -- 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); -- 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 RETURNS SETOF GEOMETRY
AS $$ AS $$
DECLARE DECLARE
@ -107,6 +114,12 @@ BEGIN
vstartary := ARRAY[ vstart - (vstep/2.0), vstart ]; vstartary := ARRAY[ vstart - (vstep/2.0), vstart ];
END IF; 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; vstartidx := abs(hskip)%2;
RAISE DEBUG 'vstartary: % : %', vstartary[1], vstartary[2]; RAISE DEBUG 'vstartary: % : %', vstartary[1], vstartary[2];

View File

@ -111,6 +111,7 @@ AS $$
BEGIN BEGIN
EXECUTE 'GRANT USAGE ON SCHEMA "' || from_schema || '" TO "' || to_role_name || '"'; 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 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 END
$$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;

View File

@ -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 -- Fill given extent with a rectangular coverage
-- --
@ -15,8 +18,11 @@
-- The parameter is checked for having the same SRID -- The parameter is checked for having the same SRID
-- as the extent. -- 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.
-- --
CREATE OR REPLACE FUNCTION CDB_RectangleGrid(ext GEOMETRY, width FLOAT8, height FLOAT8, origin GEOMETRY DEFAULT NULL) CREATE OR REPLACE FUNCTION CDB_RectangleGrid(ext GEOMETRY, width FLOAT8, height FLOAT8, origin GEOMETRY DEFAULT NULL, maxcells INTEGER DEFAULT 512*512)
RETURNS SETOF GEOMETRY RETURNS SETOF GEOMETRY
AS $$ AS $$
DECLARE DECLARE
@ -79,6 +85,12 @@ BEGIN
--RAISE DEBUG 'hend: %', hend; --RAISE DEBUG 'hend: %', hend;
--RAISE DEBUG 'vend: %', vend; --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; x := hstart;
WHILE x < hend LOOP -- over X WHILE x < hend LOOP -- over X
y := vstart; y := vstart;

View File

@ -1,3 +1,6 @@
set client_min_messages to error;
\set VERBOSITY TERSE
-- Check correctness of an hexagons grid -- Check correctness of an hexagons grid
-- --
-- Cells must have no overlaps and have a number of -- Cells must have no overlaps and have a number of
@ -45,3 +48,9 @@ WITH
0.002 as radius ), 0.002 as radius ),
grid AS ( SELECT CDB_HexagonGrid(env, radius) AS cell from params) grid AS ( SELECT CDB_HexagonGrid(env, radius) AS cell from params)
SELECT '#160', count(cell) > 23000 from grid; 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);

View File

@ -1,2 +1,5 @@
SET
9|63|count / npoints 9|63|count / npoints
#160|t #160|t
3886
ERROR: The requested grid is too big to be rendered

View File

@ -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);

View File

@ -0,0 +1,3 @@
SET
10000
ERROR: The requested grid is too big to be rendered

View File

@ -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() { 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_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_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 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_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_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_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() { 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() { 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_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_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_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_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() { function test_giving_permissions_to_two_tables_and_removing_from_first_table_should_not_remove_from_second() {