Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c2main committed Dec 30, 2024
1 parent ba622a7 commit 0a13e9d
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
124 changes: 124 additions & 0 deletions src/test/regress/expected/functions_pushdown.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
create table foo( id int primary key, t text);
select create_distributed_table('foo', 'id');
create_distributed_table
---------------------------------------------------------------------

(1 row)

create table ref_t( id int primary key, f_id int, t text);
select create_reference_table('ref_t');
create_reference_table
---------------------------------------------------------------------

(1 row)

CREATE OR REPLACE FUNCTION ref_func(i_id bigint)
RETURNS bigint LANGUAGE sql AS
$function$
SELECT count(*) FROM ref_t where f_id = i_id;
$function$;
insert into foo values (1, 'a');
insert into foo values (2, 'b');
insert into foo values (3, 'c');
insert into ref_t values (1, 1, 'aa');
insert into ref_t values (2, 2, 'bb');
insert into ref_t values (3, 3, 'cc');
insert into ref_t values (4, 2, 'BB');
select *,ref_func(id) from foo;
id | t | ref_func
---------------------------------------------------------------------
1 | a | 1
3 | c | 1
2 | b | 2
(3 rows)

select *,ref_func(id) from foo where id = 1;
id | t | ref_func
---------------------------------------------------------------------
1 | a | 1
(1 row)

select *,ref_func(id) from foo where id = 2;
id | t | ref_func
---------------------------------------------------------------------
2 | b | 2
(1 row)

select *,ref_func(id) from foo where id = 3;
id | t | ref_func
---------------------------------------------------------------------
3 | c | 1
(1 row)

select ref_func(1);
ref_func
---------------------------------------------------------------------
1
(1 row)

select ref_func(2);
ref_func
---------------------------------------------------------------------
2
(1 row)

select ref_func(3);
ref_func
---------------------------------------------------------------------
1
(1 row)

select * from ref_func(1);
ref_func
---------------------------------------------------------------------
1
(1 row)

select * from ref_func(2);
ref_func
---------------------------------------------------------------------
2
(1 row)

select * from ref_func(3);
ref_func
---------------------------------------------------------------------
1
(1 row)

drop table ref_t;
drop table foo;
drop function ref_func(bigint);
-- https://github.com/citusdata/citus/issues/5887
CREATE SCHEMA table_1;
CREATE TABLE table_1.test(a int);
SELECT create_distributed_table('table_1.test', 'a');
create_distributed_table
---------------------------------------------------------------------

(1 row)

INSERT INTO table_1.test SELECT i FROM generate_series(1,10)i;
CREATE OR REPLACE FUNCTION some_func() RETURNS integer
AS 'select count(*) FROM table_1.test;'
LANGUAGE SQL
VOLATILE
RETURNS NULL ON NULL INPUT;
SELECT some_func() FROM table_1.test;
some_func
---------------------------------------------------------------------
10
10
10
10
10
10
10
10
10
10
(10 rows)

drop table table_1.test;
drop schema table_1;
drop function some_func();
1 change: 1 addition & 0 deletions src/test/regress/multi_1_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ test: distributed_collations_conflict
test: function_propagation
test: view_propagation
test: check_mx
test: functions_pushdown

# ---------
# deparsing logic tests
Expand Down
54 changes: 54 additions & 0 deletions src/test/regress/sql/functions_pushdown.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
create table foo( id int primary key, t text);
select create_distributed_table('foo', 'id');

create table ref_t( id int primary key, f_id int, t text);
select create_reference_table('ref_t');

CREATE OR REPLACE FUNCTION ref_func(i_id bigint)
RETURNS bigint LANGUAGE sql AS
$function$
SELECT count(*) FROM ref_t where f_id = i_id;
$function$;

insert into foo values (1, 'a');
insert into foo values (2, 'b');
insert into foo values (3, 'c');
insert into ref_t values (1, 1, 'aa');
insert into ref_t values (2, 2, 'bb');
insert into ref_t values (3, 3, 'cc');
insert into ref_t values (4, 2, 'BB');

select *,ref_func(id) from foo;
select *,ref_func(id) from foo where id = 1;
select *,ref_func(id) from foo where id = 2;
select *,ref_func(id) from foo where id = 3;

select ref_func(1);
select ref_func(2);
select ref_func(3);

select * from ref_func(1);
select * from ref_func(2);
select * from ref_func(3);

drop table ref_t;
drop table foo;
drop function ref_func(bigint);

-- https://github.com/citusdata/citus/issues/5887
CREATE SCHEMA table_1;
CREATE TABLE table_1.test(a int);
SELECT create_distributed_table('table_1.test', 'a');
INSERT INTO table_1.test SELECT i FROM generate_series(1,10)i;

CREATE OR REPLACE FUNCTION some_func() RETURNS integer
AS 'select count(*) FROM table_1.test;'
LANGUAGE SQL
VOLATILE
RETURNS NULL ON NULL INPUT;

SELECT some_func() FROM table_1.test;

drop table table_1.test;
drop schema table_1;
drop function some_func();

0 comments on commit 0a13e9d

Please sign in to comment.