-
Notifications
You must be signed in to change notification settings - Fork 5
chore: bump version to 0.2.9 #18
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0c33b5d
feat: improve error message and sql generation for udfs
BohuTANG 6528c6d
fix: resolve lint errors in test_sql_generation.py
BohuTANG 52f30ee
fix: remove unused import in test_sql_generation.py
BohuTANG 0ea59ae
fix: remove unused logging import
BohuTANG 7acede8
style: format code with ruff
BohuTANG 4b1c8a2
fix: resolve module name collision in tests
BohuTANG 1a625bd
test: use caplog fixture instead of mocking logger
BohuTANG f1c3696
style: format code with ruff
BohuTANG cceacbe
chore: bump version to 0.2.9
BohuTANG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import logging | ||
| import pyarrow as pa | ||
| from prometheus_client import REGISTRY | ||
| from databend_udf import udf, StageLocation, UDFServer | ||
|
|
||
|
|
||
| @udf(input_types=["INT"], result_type="INT") | ||
| def scalar_func(x: int) -> int: | ||
| return x | ||
|
|
||
|
|
||
| @udf(stage_refs=["stage_loc"], input_types=["INT"], result_type="INT") | ||
| def stage_func(stage_loc: StageLocation, x: int) -> int: | ||
| return x | ||
|
|
||
|
|
||
| @udf(input_types=["INT"], result_type=["INT"], batch_mode=True) | ||
| def table_func(x: int): | ||
| yield pa.RecordBatch.from_arrays([pa.array([x])], names=["res"]) | ||
|
|
||
|
|
||
| def setup_function(): | ||
| for collector in list(REGISTRY._collector_to_names): | ||
| REGISTRY.unregister(collector) | ||
|
|
||
|
|
||
| def test_scalar_sql(caplog): | ||
| with caplog.at_level(logging.INFO): | ||
| server = UDFServer("0.0.0.0:0") | ||
| server.add_function(scalar_func) | ||
|
|
||
| assert "CREATE OR REPLACE FUNCTION scalar_func (x INT)" in caplog.text | ||
| assert "RETURNS INT LANGUAGE python" in caplog.text | ||
|
|
||
|
|
||
| def test_stage_sql(caplog): | ||
| with caplog.at_level(logging.INFO): | ||
| server = UDFServer("0.0.0.0:0") | ||
| server.add_function(stage_func) | ||
|
|
||
| assert ( | ||
| "CREATE OR REPLACE FUNCTION stage_func (stage_loc STAGE_LOCATION, x INT)" | ||
| in caplog.text | ||
| ) | ||
| assert "RETURNS INT LANGUAGE python" in caplog.text | ||
|
|
||
|
|
||
| def test_table_sql(caplog): | ||
| with caplog.at_level(logging.INFO): | ||
| server = UDFServer("0.0.0.0:0") | ||
| server.add_function(table_func) | ||
|
|
||
| assert "CREATE OR REPLACE FUNCTION table_func (x INT)" in caplog.text | ||
| assert "RETURNS TABLE (col0 INT) LANGUAGE python" in caplog.text |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Table-valued UDFs with nullable result columns are now emitted without an explicit
NULLmarker:_inner_field_to_stringreturns only the type whenfield.nullableis true even though the comment notes inner fields default to NOT NULL in Databend. That causesRETURNS TABLE (...)definitions to register nullable columns as NOT NULL, so UDFs that actually return nulls will have a mismatched signature and can fail at runtime. Please keep emittingNULLwhen a result field is nullable.Useful? React with 👍 / 👎.