Skip to content

feat: implement Tabular SQL UDFs #18511

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

KKould
Copy link
Member

@KKould KKould commented Aug 10, 2025

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

Summary

close: #5731

This UDTF feature encapsulates SQL as a table function, allowing it to be used in a similar way to a View.

create table t1 (c1 int);

create function udtf_t1 () RETURNS TABLE (c1 int) as $$ select * from t1 $$;

select * from udtf_t1();

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - TODO

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 Aug 10, 2025
@KKould KKould marked this pull request as ready for review August 11, 2025 10:43
@KKould KKould requested a review from drmingdrmer as a code owner August 11, 2025 10:43
@KKould KKould requested a review from sundy-li August 11, 2025 10:43
@KKould KKould self-assigned this Aug 11, 2025
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 16 files at r1, all commit messages.
Reviewable status: 4 of 16 files reviewed, 5 unresolved discussions (waiting on @sundy-li)


src/meta/app/src/principal/user_defined_function.rs line 59 at r1 (raw file):

    pub return_types: Vec<(String, DataType)>,
    pub sql: String,
}

add doc comment to important struct, and its field. The code itself does not show what the 'String' is.

Code quote:

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UDTF {
    pub arg_types: Vec<(String, DataType)>,
    pub return_types: Vec<(String, DataType)>,
    pub sql: String,
}

src/meta/protos/proto/udf.proto line 74 at r1 (raw file):

message UDTFArg {
  string name = 1;
  DataType type = 2;

avoid using rust keyword


src/meta/proto-conv/src/udf_from_to_protobuf_impl.rs line 295 at r1 (raw file):

                Incompatible::new("UDTF.arg_types.ty can not be None".to_string())
            })?)?)
                .into();

Avoid put more than one action into one line.
Do each thing in a separate line.

Code quote:

            let ty = (&TableDataType::from_pb(arg_ty.r#type.ok_or_else(|| {
                Incompatible::new("UDTF.arg_types.ty can not be None".to_string())
            })?)?)
                .into();

src/meta/proto-conv/src/udf_from_to_protobuf_impl.rs line 327 at r1 (raw file):

                    ))
                })?
                .to_pb()?;

too large expression

Code quote:

            let arg_type = infer_schema_type(arg_type)
                .map_err(|e| {
                    Incompatible::new(format!(
                        "Convert DataType to TableDataType failed: {}",
                        e.message()
                    ))
                })?
                .to_pb()?;

src/meta/proto-conv/tests/it/v142_udtf.rs line 49 at r1 (raw file):

        definition: UDFDefinition::UDTF(UDTF {
            arg_types: vec![],
            return_types: vec![],

testing empty vector? it does not test anything at all

Code quote:

            arg_types: vec![],
            return_types: vec![],

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.

Tabular SQL UDFs (UDTFs)
3 participants