Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change log tvf #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions rfcs/00xx-changelog-tvf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
feature: changelog_tvf
authors:
- "st1page"
start_date: "2023/08/24"
---

#

Please feel free to add or remove sections.

## Summary

Introduce a new TVF
```
changelog(table/mv name) -> Append only stream(
original schema |
op: varchar,
event_time: TIMESTAMPTZ,
_row_id(hidden): Serial,
old_value: STRUCT<original schema>)
```
And users can get a append-only stream and express more flexible behavior.
```SQL
CREATE SOURCE events_source(
id: int,
msg: varchar,
status: varchar,
event_time timestamptz,
proc_time timestampz AS proctime()
);

CREATE MATERIALIZED VIEW events as
SELECT * FROM events_source
WHERE proc_time > NOW() - INTERVAL '7 days'
ORDER BY event_time;

CREATE MATERIALIZED VIEW windowed_result as
SELECT
window_start,
count(*) as all_count,
count(*) filter(where status = 'error') as error_count
FROM TUMBLE (events, event_time, INTERVAL '1 MINUTES')
GROUP BY window_start;

CREATE MATERIALIZED VIEW error_minutes as
SELECT
distinct on window_start,
window_start,
FROM changelog(windowed_result)
WHERE error_count > all_count * 0.9 AND op = "insert";

CREATE MATERIALIZED VIEW detailed_msg_in_error_minutes as
SELECT events.*
FROM error_minutes
JOIN events FOR SYSTEM_TIME AS OF PROCTIME()
ON events.event_time between window_start AND window_start + INTERVAL '1 MINUTES';
```



## Motivation

Why are you want to introduce the feature?

## Design

Explain the feature in detail.

## Unresolved questions

* Are there some questions that haven't been resolved in the RFC?
* Can they be resolved in some future RFCs?
* Move some meaningful comments to here.

## Alternatives

What other designs have been considered and what is the rationale for not choosing them?

## Future possibilities

Some potential extensions or optimizations can be done in the future based on the RFC.