feat(query): support SYSTEM$STREAM_HAS_DATA as scalar function#19713
Open
dantengsky wants to merge 2 commits intodatabendlabs:mainfrom
Open
feat(query): support SYSTEM$STREAM_HAS_DATA as scalar function#19713dantengsky wants to merge 2 commits intodatabendlabs:mainfrom
dantengsky wants to merge 2 commits intodatabendlabs:mainfrom
Conversation
1da84a6 to
11e7daf
Compare
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.
11e7daf to
b12cc18
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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')andstream_has_data('stream_name')as scalar functions.Previously,
stream_has_datawas 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 thestream_statustable function in aFROMclause, which could not be used as a scalar expression.This PR rewrites both function names as sugar functions that expand to a scalar subquery:
This allows
SYSTEM$STREAM_HAS_DATAto be used in any scalar expression context, such asSELECTstatements and boolean expressions. Supports unqualified, two-part (db.stream), and three-part (catalog.db.stream) stream name references.Tests
Type of change
This change is