Skip to content

Commit

Permalink
[pg15] test: fully port regress create_operator, create_type, with
Browse files Browse the repository at this point in the history
Summary:
Fully port regress tests

- create_operator to yb_pg_create_operator
- create_type to yb_pg_create_type
- with to yb_pg_with

so that test TestPgRegressPgMisc passes.

Test Plan:
On Almalinux 8:

    #!/usr/bin/env bash
    set -eu
    ./yb_build.sh fastdebug --gcc11
    for _ in {1..50}; do grep TestPgRegressPgMisc pg15_tests/passing_tests.tsv; done | pg15_tests/run_tests.sh

Jenkins: rebase: pg15

Reviewers: aagrawal, tfoucher

Reviewed By: aagrawal

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D34444
  • Loading branch information
jaki committed Apr 24, 2024
1 parent 679befb commit b68a24e
Show file tree
Hide file tree
Showing 7 changed files with 2,135 additions and 429 deletions.
1 change: 1 addition & 0 deletions pg15_tests/passing_tests.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ JAVA org.yb.pgsql.TestPgRegressJson
JAVA org.yb.pgsql.TestPgRegressMatview
JAVA org.yb.pgsql.TestPgRegressMisc#testPgRegressMiscSerial2
JAVA org.yb.pgsql.TestPgRegressNonTxnCopy
JAVA org.yb.pgsql.TestPgRegressPgMisc
JAVA org.yb.pgsql.TestPgRegressProc
JAVA org.yb.pgsql.TestPgRegressPublication
JAVA org.yb.pgsql.TestPgRegressPushdown#testPgRegressPushdown
Expand Down
68 changes: 41 additions & 27 deletions src/postgres/src/test/regress/expected/yb_pg_create_operator.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ CREATE OPERATOR ## (
commutator = ##
);
CREATE OPERATOR @#@ (
rightarg = int8, -- left unary
procedure = numeric_fac
);
CREATE OPERATOR #@# (
leftarg = int8, -- right unary
procedure = numeric_fac
rightarg = int8, -- prefix
procedure = factorial
);
CREATE OPERATOR #%# (
leftarg = int8, -- right unary
procedure = numeric_fac
leftarg = int8, -- fail, postfix is no longer supported
procedure = factorial
);
ERROR: operator right argument type must be specified
DETAIL: Postfix operators are not supported.
-- Test operator created above
SELECT @#@ 24;
?column?
Expand All @@ -27,12 +25,23 @@ SELECT @#@ 24;
(1 row)

-- Test comments
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
ERROR: operator does not exist: integer ######
-- => is disallowed now
COMMENT ON OPERATOR ###### (NONE, int4) IS 'bad prefix';
ERROR: operator does not exist: ###### integer
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad postfix';
ERROR: postfix operators are not supported
COMMENT ON OPERATOR ###### (int4, int8) IS 'bad infix';
ERROR: operator does not exist: integer ###### bigint
-- Check that DROP on a nonexistent op behaves sanely, too
DROP OPERATOR ###### (NONE, int4);
ERROR: operator does not exist: ###### integer
DROP OPERATOR ###### (int4, NONE);
ERROR: postfix operators are not supported
DROP OPERATOR ###### (int4, int8);
ERROR: operator does not exist: integer ###### bigint
-- => is disallowed as an operator name now
CREATE OPERATOR => (
leftarg = int8, -- right unary
procedure = numeric_fac
rightarg = int8,
procedure = factorial
);
ERROR: syntax error at or near "=>"
LINE 1: CREATE OPERATOR => (
Expand All @@ -41,15 +50,20 @@ LINE 1: CREATE OPERATOR => (
-- (=> is tested elsewhere)
-- this is legal because ! is not allowed in sql ops
CREATE OPERATOR !=- (
leftarg = int8, -- right unary
procedure = numeric_fac
rightarg = int8,
procedure = factorial
);
SELECT 2 !=-;
SELECT !=- 10;
?column?
----------
2
3628800
(1 row)

-- postfix operators don't work anymore
SELECT 10 !=-;
ERROR: syntax error at or near ";"
LINE 1: SELECT 10 !=-;
^
-- make sure lexer returns != as <> even in edge cases
SELECT 2 !=/**/ 1, 2 !=/**/ 2;
?column? | ?column?
Expand Down Expand Up @@ -119,24 +133,24 @@ GRANT USAGE ON SCHEMA schema_op1 TO PUBLIC;
REVOKE USAGE ON SCHEMA schema_op1 FROM regress_rol_op1;
SET ROLE regress_rol_op1;
CREATE OPERATOR schema_op1.#*# (
leftarg = int8, -- right unary
procedure = numeric_fac
rightarg = int8,
procedure = factorial
);
ERROR: permission denied for schema schema_op1
ROLLBACK;
-- Should fail. SETOF type functions not allowed as argument (testing leftarg)
BEGIN TRANSACTION;
CREATE OPERATOR #*# (
leftarg = SETOF int8,
procedure = numeric_fac
procedure = factorial
);
ERROR: SETOF type not allowed for operator argument
ROLLBACK;
-- Should fail. SETOF type functions not allowed as argument (testing rightarg)
BEGIN TRANSACTION;
CREATE OPERATOR #*# (
rightarg = SETOF int8,
procedure = numeric_fac
procedure = factorial
);
ERROR: SETOF type not allowed for operator argument
ROLLBACK;
Expand All @@ -159,19 +173,19 @@ CREATE OPERATOR === (
ROLLBACK;
-- Should fail. Invalid attribute
CREATE OPERATOR #@%# (
leftarg = int8, -- right unary
procedure = numeric_fac,
rightarg = int8,
procedure = factorial,
invalid_att = int8
);
WARNING: operator attribute "invalid_att" not recognized
-- Should fail. At least leftarg or rightarg should be mandatorily specified
-- Should fail. At least rightarg should be mandatorily specified
CREATE OPERATOR #@%# (
procedure = numeric_fac
procedure = factorial
);
ERROR: at least one of leftarg or rightarg must be specified
ERROR: operator argument types must be specified
-- Should fail. Procedure should be mandatorily specified
CREATE OPERATOR #@%# (
leftarg = int8
rightarg = int8
);
ERROR: operator function must be specified
-- Should fail. CREATE OPERATOR requires USAGE on TYPE
Expand Down
76 changes: 39 additions & 37 deletions src/postgres/src/test/regress/expected/yb_pg_create_type.out
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ SELECT * FROM default_test;
zippo | 42
(1 row)

-- We need a shell type to test some CREATE TYPE failure cases with
CREATE TYPE bogus_type;
-- invalid: non-lowercase quoted identifiers
CREATE TYPE case_int42 (
CREATE TYPE bogus_type (
"Internallength" = 4,
"Input" = int42_in,
"Output" = int42_out,
Expand All @@ -136,6 +138,20 @@ WARNING: type attribute "Passedbyvalue" not recognized
LINE 7: "Passedbyvalue"
^
ERROR: type input function must be specified
-- invalid: input/output function incompatibility
CREATE TYPE bogus_type (INPUT = array_in,
OUTPUT = array_out,
ELEMENT = int,
INTERNALLENGTH = 32);
ERROR: type input function array_in must return type bogus_type
DROP TYPE bogus_type;
-- It no longer is possible to issue CREATE TYPE without making a shell first
CREATE TYPE bogus_type (INPUT = array_in,
OUTPUT = array_out,
ELEMENT = int,
INTERNALLENGTH = 32);
ERROR: type "bogus_type" does not exist
HINT: Create the type as a shell type, then create its I/O functions, then do a full CREATE TYPE.
-- Test stand-alone composite type
CREATE TYPE default_test_row AS (f1 text_w_default, f2 int42);
CREATE FUNCTION get_default_test() RETURNS SETOF default_test_row AS '
Expand All @@ -162,31 +178,25 @@ ERROR: type "text_w_default" already exists
DROP TYPE default_test_row CASCADE;
NOTICE: drop cascades to function get_default_test()
DROP TABLE default_test;
-- Check type create with input/output incompatibility
CREATE TYPE not_existing_type (INPUT = array_in,
OUTPUT = array_out,
ELEMENT = int,
INTERNALLENGTH = 32);
ERROR: function array_out(not_existing_type) does not exist
-- Check dependency transfer of opaque functions when creating a new type
CREATE FUNCTION base_fn_in(cstring) RETURNS opaque AS 'boolin'
-- Check dependencies are established when creating a new type
CREATE TYPE base_type;
CREATE FUNCTION base_fn_in(cstring) RETURNS base_type AS 'boolin'
LANGUAGE internal IMMUTABLE STRICT;
CREATE FUNCTION base_fn_out(opaque) RETURNS opaque AS 'boolout'
NOTICE: return type base_type is only a shell
CREATE FUNCTION base_fn_out(base_type) RETURNS cstring AS 'boolout'
LANGUAGE internal IMMUTABLE STRICT;
NOTICE: argument type base_type is only a shell
CREATE TYPE base_type(INPUT = base_fn_in, OUTPUT = base_fn_out);
WARNING: changing argument type of function base_fn_out from "opaque" to base_type
WARNING: changing return type of function base_fn_in from opaque to base_type
WARNING: changing return type of function base_fn_out from opaque to cstring
\set VERBOSITY terse \\ -- suppress cascade details
\set VERBOSITY terse \\ -- YB: suppress cascade details
DROP FUNCTION base_fn_in(cstring); -- error
ERROR: cannot drop function base_fn_in(cstring) because other objects depend on it
DROP FUNCTION base_fn_out(opaque); -- error
ERROR: function base_fn_out(opaque) does not exist
DROP FUNCTION base_fn_out(base_type); -- error
ERROR: cannot drop function base_fn_out(base_type) because other objects depend on it
DROP TYPE base_type; -- error
ERROR: cannot drop type base_type because other objects depend on it
DROP TYPE base_type CASCADE;
NOTICE: drop cascades to 2 other objects
\set VERBOSITY default
\set VERBOSITY default \\ -- YB: unsuppress cascade details
-- Check usage of typmod with a user-defined type
-- (we have borrowed numeric's typmod functions)
CREATE TEMP TABLE mytab (foo widget(42,13,7)); -- should fail
Expand Down Expand Up @@ -255,6 +265,16 @@ CREATE TABLE city (
location box,
budget city_budget
);
INSERT INTO city VALUES
('Podunk', '(1,2),(3,4)', '100,127,1000'),
('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789');
TABLE city ORDER BY name DESC; -- YB-added ordering
name | location | budget
--------+----------------------+-----------------------
Podunk | (3,4),(1,2) | 100,127,1000,0
Gotham | (1100,334),(1000,34) | 123456,127,-1000,6789
(2 rows)

--
-- Test CREATE/ALTER TYPE using a type that's compatible with varchar,
-- so we can re-use those support functions
Expand Down Expand Up @@ -328,29 +348,11 @@ FROM pg_type WHERE typname = '_myvarchardom';
(1 row)

-- ensure dependencies are straight
-- YB note: trivial ordering difference in DETAIL as compared to PG
\set VERBOSITY terse \\ -- YB: suppress cascade details
DROP FUNCTION myvarcharsend(myvarchar); -- fail
ERROR: cannot drop function myvarcharsend(myvarchar) because other objects depend on it
DETAIL: function myvarcharin(cstring,oid,integer) depends on type myvarchar
function myvarcharout(myvarchar) depends on type myvarchar
function myvarcharrecv(internal,oid,integer) depends on type myvarchar
type myvarchar depends on function myvarcharsend(myvarchar)
type myvarchardom depends on function myvarcharsend(myvarchar)
HINT: Use DROP ... CASCADE to drop the dependent objects too.
-- YB note: trivial ordering difference in DETAIL as compared to PG
DROP TYPE myvarchar; -- fail
ERROR: cannot drop type myvarchar because other objects depend on it
DETAIL: function myvarcharin(cstring,oid,integer) depends on type myvarchar
function myvarcharout(myvarchar) depends on type myvarchar
function myvarcharrecv(internal,oid,integer) depends on type myvarchar
function myvarcharsend(myvarchar) depends on type myvarchar
type myvarchardom depends on type myvarchar
HINT: Use DROP ... CASCADE to drop the dependent objects too.
-- YB note: trivial ordering difference in DETAIL as compared to PG
DROP TYPE myvarchar CASCADE;
NOTICE: drop cascades to 5 other objects
DETAIL: drop cascades to function myvarcharin(cstring,oid,integer)
drop cascades to function myvarcharout(myvarchar)
drop cascades to function myvarcharrecv(internal,oid,integer)
drop cascades to function myvarcharsend(myvarchar)
drop cascades to type myvarchardom
\set VERBOSITY default \\ -- YB: unsuppress cascade details
Loading

0 comments on commit b68a24e

Please sign in to comment.