Skip to content

feat(query): support SYSTEM$STREAM_HAS_DATA as scalar function#19713

Open
dantengsky wants to merge 2 commits intodatabendlabs:mainfrom
dantengsky:feat/system-stream-has-data
Open

feat(query): support SYSTEM$STREAM_HAS_DATA as scalar function#19713
dantengsky wants to merge 2 commits intodatabendlabs:mainfrom
dantengsky:feat/system-stream-has-data

Conversation

@dantengsky
Copy link
Copy Markdown
Member

@dantengsky dantengsky commented Apr 14, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Add support for SYSTEM$STREAM_HAS_DATA('stream_name') and stream_has_data('stream_name') as scalar functions.

Previously, stream_has_data was registered in the sugar function list but had no rewrite implementation, causing "unknown function" errors at runtime. The only way to check stream status was via the stream_status table function in a FROM clause, which could not be used as a scalar expression.

This PR rewrites both function names as sugar functions that expand to a scalar subquery:

(SELECT has_data FROM stream_status('stream_name'))

This allows SYSTEM$STREAM_HAS_DATA to be used in any scalar expression context, such as SELECT statements and boolean expressions. Supports unqualified, two-part (db.stream), and three-part (catalog.db.stream) stream name references.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions Bot added the pr-feature this PR introduces a new feature to the codebase label Apr 14, 2026
@dantengsky dantengsky force-pushed the feat/system-stream-has-data branch from 1da84a6 to 11e7daf Compare April 14, 2026 11:03
Rewrite system$stream_has_data(name) and stream_has_data(name)
as sugar functions that expand to a scalar subquery:
  (SELECT has_data FROM stream_status(name))

This provides Snowflake-compatible syntax for use in task WHEN conditions:
  CREATE TASK my_task
    WHEN SYSTEM$STREAM_HAS_DATA(my_stream)
    AS ...

Stream name validation is delegated to the existing stream_status
table function, avoiding any duplicated logic.
@dantengsky dantengsky force-pushed the feat/system-stream-has-data branch from 11e7daf to b12cc18 Compare April 14, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants