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

changefeedccl: Add changefeed_creation_timestamp function #95179

Merged
merged 1 commit into from
Jan 31, 2023

Conversation

miretskiy
Copy link
Contributor

Add changefeed_create_timestamp function, which returns changefeed creation timestamp.

Changefeed transformations restrict access to some of the standard functions, including now().
Without such function, it is difficult to express
changefeeds that want to emit events restricted
by time. This function makes it possible to do
this. For example, to create a changefeed that
emits events from the accounts table that
last_withdrawal happen starting 12 hours ago,
one could do:

CREATE CHANGEFEED ... AS
SELECT * FROM accounts WHERE last_withdrawal >
changefeed_create_timestamp() - interval '12 hours'

Epic: CRDB-17161

Release note (enterprise change): Changefeed expressions support changefeed_create_timestamp function.

@miretskiy miretskiy requested review from a team as code owners January 12, 2023 22:04
@miretskiy miretskiy requested review from jayshrivastava and DrewKimball and removed request for a team January 12, 2023 22:04
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@miretskiy miretskiy removed the request for review from DrewKimball January 12, 2023 22:04
@shermanCRL
Copy link
Contributor

Bikeshed, I think create sounds like a verb/command. Maybe created or creation?

@yuzefovich yuzefovich removed the request for review from a team January 12, 2023 22:21
@miretskiy miretskiy force-pushed the create_time branch 2 times, most recently from 203040f to 5052438 Compare January 12, 2023 22:25
@miretskiy
Copy link
Contributor Author

Bikeshed, I think create sounds like a verb/command. Maybe created or creation?

easy enough to change -- done.

@miretskiy miretskiy changed the title changefeedccl: Add changefeed_create_timestamp function changefeedccl: Add changefeed_creation_timestamp function Jan 13, 2023
Add `changefeed_creation_timestamp` function, which returns
changefeed creation timestamp.

Changefeed transformations restrict access to some
of the standard functions, including `now()`.
Without such function, it is difficult to express
changefeeds that want to emit events restricted
by time.  This function makes it possible to do
this.  For example, to create a changefeed that
emits events from the `accounts` table that
`last_withdrawal` happen starting 12 hours ago,
one could do:

```
CREATE CHANGEFEED ... AS
SELECT * FROM accounts WHERE last_withdrawal >
changefeed_creation_timestamp() - interval '12 hours'
```

Epic: CRDB-17161

Release note (enterprise change): Changefeed expressions support
`changefeed_created_timestamp` function.
Copy link
Contributor

@jayshrivastava jayshrivastava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe cdc_now_timestamp() or cdc_now() aligns better with the other cdc internal thing we have (cdc_prev). Also, using now somewhere in the name aligns more with the standard now() fn.

Reviewed 5 of 6 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @miretskiy)


pkg/ccl/changefeedccl/cdceval/expr_eval.go line 115 at r1 (raw file):

		rowCh: make(chan tree.Datums, 1),
	}
	e.rowEvalCtx.startTime = statementTS

It would be a neater to make a constructor for rowEvalCtx which does this.


pkg/ccl/changefeedccl/cdceval/expr_eval.go line 452 at r1 (raw file):

func (e *familyEvaluator) setupContextForRow(ctx context.Context, updated cdcevent.Row) error {
	e.rowEvalCtx.ctx = ctx
	e.rowEvalCtx.updatedRow = updated

Consider putting these lines in a function func (rec *rowEvalContext) updateForRow(ctx context.Context, updated cdcevent.Row).

Code quote:

	e.rowEvalCtx.ctx = ctx
	e.rowEvalCtx.updatedRow = updated

pkg/ccl/changefeedccl/cdceval/functions.go line 133 at r1 (raw file):

	"changefeed_creation_timestamp": cdcTimestampBuiltin(
		"changefeed_creation_timestamp",
		"Returns changefeed creation time",

nit: transaction timestamp or timestamp would be more clear.

Code quote:

eturns changefeed creation time

@miretskiy
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 31, 2023

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants