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

Introduce METADATA and WATERMARK syntax #837

Merged
merged 4 commits into from
Feb 28, 2025
Merged

Introduce METADATA and WATERMARK syntax #837

merged 4 commits into from
Feb 28, 2025

Conversation

mwylde
Copy link
Member

@mwylde mwylde commented Feb 28, 2025

This PR introduces two new syntax elements to improve our SQL UX, and also makes the meaningless STORED keyword optional for generated fields. The sqlparser side of these changes is in ArroyoSystems/sqlparser-rs#1.

WATERMARK FOR

Allows users to configure the event-time column and watermark generation expression without needing to create and then reference virtual fields:

WATERMARK FOR fieldname [AS watermark_expr]

for example,

CREATE TABLE logs (
  timestamp TIMESTAMP NOT NULL,
  id INT,
  WATERMARK FOR timestamp AS timestamp - INTERVAL '5 seconds'
) WITH (
  ...
)

Previously, this would have been written

CREATE TABLE logs (
  timestamp TIMESTAMP NOT NULL,
  id INT,
  watermark TIMESTAMP GENERATED ALWAYS AS (timestamp - INTERVAL '5 seconds') STORED
) WITH (
  event_time_field = timestamp,
  watermark_field = watermark
)

METADATA FROM

Allow users to configure a column to have metadata injected from the source:

field_name TYPE METADATA FROM 'key'

example:

CREATE TABLE logs (
    id TEXT,
    kafka_topic TEXT METADATA FROM 'topic',
    log TEXT
)

Previous, this would have been written using a special function

CREATE TABLE logs (
    id TEXT,
    kafka_topic TEXT GENERATED ALWAYS AS (metadata('topic')) STORED,
    log TEXT
)

Breaking changes

Existing syntax for both features is still supported, but are deprecated and will be removed in 0.15. However, as WATERMARK is now a keyword, unquoted fields named watermark will now produce an error.

@mwylde mwylde enabled auto-merge (squash) February 28, 2025 20:00
@mwylde mwylde merged commit caf673e into master Feb 28, 2025
6 checks passed
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.

1 participant