Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zachasme committed Nov 5, 2024
1 parent 49789eb commit d941038
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 55 deletions.
6 changes: 3 additions & 3 deletions h3/sql/updates/h3--4.1.3--unreleased.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ CREATE OR REPLACE FUNCTION
AS 'h3' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

ALTER TYPE h3index SET (
RECEIVE = h3index_recv,
SEND = h3index_send
);
RECEIVE = h3index_recv,
SEND = h3index_send
);
2 changes: 1 addition & 1 deletion h3/src/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ h3index_recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);

PG_RETURN_POINTER(pq_getmsgint64(buf));
PG_RETURN_H3INDEX(pq_getmsgint64(buf));
}

Datum
Expand Down
36 changes: 10 additions & 26 deletions h3/test/expected/type.out
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,15 @@ SELECT :hexagon = :asbigint::h3index;
--
-- TEST binary io
--
CREATE OR REPLACE FUNCTION copy_to_and_from_file(index h3index) RETURNS BOOLEAN LANGUAGE PLPGSQL AS
$$
DECLARE
result BOOL;
BEGIN
CREATE TEMPORARY TABLE from_temp (val h3index);
INSERT INTO from_temp (val) VALUES (index);
CREATE TEMPORARY TABLE to_tmp (val h3index);
IF (
SELECT CASE setting WHEN 'windows' THEN true ELSE false END AS isWindows
FROM pg_catalog.pg_file_settings
WHERE name = 'dynamic_shared_memory_type'
)
THEN
COPY (SELECT val FROM from_temp) TO 'C:\Windows\Temp\test.bin' (FORMAT binary);
COPY to_tmp FROM 'C:\Windows\Temp\test.bin' (FORMAT binary);
ELSE
COPY (SELECT val FROM from_temp) TO '/tmp/test.bin' (FORMAT binary);
COPY to_tmp FROM '/tmp/test.bin' (FORMAT binary);
END IF;

SELECT val = index into result FROM to_tmp WHERE val = index;
RETURN result;
END;
$$;
SELECT copy_to_and_from_file(:hexagon);
CREATE TEMPORARY TABLE h3_test_binary_send (hex h3index PRIMARY KEY);
CREATE TEMPORARY TABLE h3_test_binary_recv (hex h3index PRIMARY KEY);
INSERT INTO h3_test_binary_send (hex) SELECT * from h3_get_res_0_cells();
COPY h3_test_binary_send TO '/tmp/h3_test_binary.bin' (FORMAT binary);
COPY h3_test_binary_recv FROM '/tmp/h3_test_binary.bin' (FORMAT binary);
-- same data after re-import
SELECT array_agg(hex) is null FROM (
SELECT hex FROM h3_test_binary_send
EXCEPT SELECT hex FROM h3_test_binary_recv
) q;
t

35 changes: 10 additions & 25 deletions h3/test/sql/type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,14 @@ SELECT :hexagon = :asbigint::h3index;
--
-- TEST binary io
--
CREATE OR REPLACE FUNCTION copy_to_and_from_file(index h3index) RETURNS BOOLEAN LANGUAGE PLPGSQL AS
$$
DECLARE
result BOOL;
BEGIN
CREATE TEMPORARY TABLE from_temp (val h3index);
INSERT INTO from_temp (val) VALUES (index);
CREATE TEMPORARY TABLE to_tmp (val h3index);
IF (
SELECT CASE setting WHEN 'windows' THEN true ELSE false END AS isWindows
FROM pg_catalog.pg_file_settings
WHERE name = 'dynamic_shared_memory_type'
)
THEN
COPY (SELECT val FROM from_temp) TO 'C:\Windows\Temp\test.bin' (FORMAT binary);
COPY to_tmp FROM 'C:\Windows\Temp\test.bin' (FORMAT binary);
ELSE
COPY (SELECT val FROM from_temp) TO '/tmp/test.bin' (FORMAT binary);
COPY to_tmp FROM '/tmp/test.bin' (FORMAT binary);
END IF;
CREATE TEMPORARY TABLE h3_test_binary_send (hex h3index PRIMARY KEY);
CREATE TEMPORARY TABLE h3_test_binary_recv (hex h3index PRIMARY KEY);
INSERT INTO h3_test_binary_send (hex) SELECT * from h3_get_res_0_cells();
COPY h3_test_binary_send TO '/tmp/h3_test_binary.bin' (FORMAT binary);
COPY h3_test_binary_recv FROM '/tmp/h3_test_binary.bin' (FORMAT binary);

SELECT val = index into result FROM to_tmp WHERE val = index;
RETURN result;
END;
$$;
SELECT copy_to_and_from_file(:hexagon);
-- same data after re-import
SELECT array_agg(hex) is null FROM (
SELECT hex FROM h3_test_binary_send
EXCEPT SELECT hex FROM h3_test_binary_recv
) q;

0 comments on commit d941038

Please sign in to comment.