Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoslot committed Dec 12, 2024
1 parent 58b7029 commit e668fc2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
9 changes: 1 addition & 8 deletions expected/time_interval.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
create extension pg_incremental cascade;
create schema time_range;
set search_path to time_range;
set client_min_messages to warning;
-- create a source table
create table events (
event_id bigint generated always as identity,
Expand Down Expand Up @@ -29,7 +30,6 @@ select incremental.create_time_interval_pipeline('event-aggregation', '1 day',
where event_time >= $1 and event_time < $2
group by 1
$$);
NOTICE: pipeline event-aggregation: processing time range from Fri Dec 31 16:00:00 1999 PST to Fri Dec 06 00:00:00 2024 PST
create_time_interval_pipeline
-------------------------------

Expand All @@ -50,7 +50,6 @@ select sum(event_count) from events_agg;
insert into events (client_id, path, response_time)
select s, '/page-' || (s % 3), random() from generate_series(1,100) s;
call incremental.execute_pipeline('event-aggregation');
NOTICE: pipeline event-aggregation: no rows to process
select count(*) from events;
count
-------
Expand All @@ -65,10 +64,4 @@ select sum(event_count) from events_agg;
(1 row)

drop schema time_range cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table events
drop cascades to table events_agg
drop extension pg_incremental;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to function incremental._drop_extension_trigger()
drop cascades to event trigger incremental_drop_extension_trigger
2 changes: 1 addition & 1 deletion pg_incremental--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ GRANT SELECT ON incremental.processed_files TO public;

CREATE FUNCTION incremental.create_sequence_pipeline(
pipeline_name text,
sequence_name regclass,
source_table_name regclass,
command text,
schedule text default '* * * * *',
execute_immediately bool default true)
Expand Down
1 change: 1 addition & 0 deletions sql/time_interval.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
create extension pg_incremental cascade;
create schema time_range;
set search_path to time_range;
set client_min_messages to warning;

-- create a source table
create table events (
Expand Down
8 changes: 6 additions & 2 deletions src/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ incremental_create_sequence_pipeline(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(0))
ereport(ERROR, (errmsg("pipeline_name cannot be NULL")));
if (PG_ARGISNULL(1))
ereport(ERROR, (errmsg("sequence_name cannot be NULL")));
ereport(ERROR, (errmsg("source_table_name cannot be NULL")));
if (PG_ARGISNULL(2))
ereport(ERROR, (errmsg("command cannot be NULL")));

Expand All @@ -64,14 +64,18 @@ incremental_create_sequence_pipeline(PG_FUNCTION_ARGS)

switch (get_rel_relkind(sequenceId))
{
/*
* We allow source_table_name to be a sequence, and this is
* necessary if there are multiple sequences.
*/
case RELKIND_SEQUENCE:
{
int32 columnNumber = 0;

if (!sequenceIsOwned(sequenceId, DEPENDENCY_AUTO, &sourceRelationId, &columnNumber))
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("enly sequences that are owned by a table are supported")));
errmsg("only sequences that are owned by a table are supported")));
}

break;
Expand Down
8 changes: 3 additions & 5 deletions src/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,15 @@ FindSequenceForRelation(Oid relationId)
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("relation \"%s\" does not have any sequences associated "
"with it",
get_rel_name(relationId)),
errhint("Specify the name of the sequence to use for the "
"pipeline as the argument")));
get_rel_name(relationId))));

if (list_length(sequences) > 1)
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("relation \"%s\" has multiple sequences associated "
"with it",
get_rel_name(relationId)),
errhint("Specify the name of the sequence to use for the "
"pipeline as the argument")));
errhint("Specify the name of the sequence to use instead of "
"the table name")));

return linitial_oid(sequences);
}

0 comments on commit e668fc2

Please sign in to comment.