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

sql: allow anonymous args and numeric arg references in UDFs #86005

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Aug 12, 2022

It is now possible to create UDFs with anonymous arguments that can be
referenced like a placeholder in a prepared statement. For example:

CREATE FUNCTION add(INT, INT) RETURNS INT LANGUAGE SQL AS $$
  SELECT $1 + $2;
$$

Named arguments can also be referenced by numeric placeholders. For
example:

CREATE FUNCTION add(x INT, y INT) RETURNS INT LANGUAGE SQL AS $$
  SELECT x + $2;
$$

Release note: None

Release justification: Adds critical functionality to a new feature.

@mgartner mgartner requested review from msirek and michae2 August 12, 2022 02:02
@mgartner mgartner requested review from a team as code owners August 12, 2022 02:02
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@mgartner
Copy link
Collaborator Author

All commits except for the last are from #85786. I'll rebase this PR when that one is merged.

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner, @michae2, and @msirek)


pkg/sql/opt/optbuilder/create_function.go line 98 at r5 (raw file):

	// named arguments to the scope so that references to them in the body can
	// be resolved.
	// TODO(mgartner): Support numeric argument references, like $1. We should

[nit] this comment is outdated


pkg/sql/opt/optbuilder/scalar.go line 628 at r5 (raw file):

	// can be resolved.
	//
	// TODO(mgartner): Support anonymous arguments and placeholder-like syntax

[nit] ditto

@mgartner mgartner force-pushed the udf-anon-args branch 2 times, most recently from 4a72155 to b6b5485 Compare August 12, 2022 13:32
Copy link
Collaborator Author

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

TFTR!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball, @michae2, and @msirek)


pkg/sql/opt/optbuilder/create_function.go line 98 at r5 (raw file):

Previously, DrewKimball (Drew Kimball) wrote…

[nit] this comment is outdated

Good catch. Done.


pkg/sql/opt/optbuilder/scalar.go line 628 at r5 (raw file):

Previously, DrewKimball (Drew Kimball) wrote…

[nit] ditto

Done.

Copy link
Contributor

@msirek msirek left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 7 files at r5, 16 of 16 files at r6, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball and @michae2)

@mgartner mgartner force-pushed the udf-anon-args branch 3 times, most recently from bd8e565 to 2cc5e79 Compare August 14, 2022 16:09
@mgartner
Copy link
Collaborator Author

This is going to be difficult to merge until we move the execution subtest section to the end of the udf test file: #86383.

It is now possible to create UDFs with anonymous arguments that can be
referenced like a placeholder in a prepared statement. For example:

    CREATE FUNCTION add(INT, INT) RETURNS INT LANGUAGE SQL AS $$
      SELECT $1 + $2;
    $$

Named arguments can also be referenced by numeric placeholders. For
example:

    CREATE FUNCTION add(x INT, y INT) RETURNS INT LANGUAGE SQL AS $$
      SELECT x + $2;
    $$

Release note: None
@mgartner mgartner requested a review from a team August 18, 2022 21:00
@mgartner
Copy link
Collaborator Author

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 19, 2022

Build succeeded:

@craig craig bot merged commit 513fae1 into cockroachdb:master Aug 19, 2022
@mgartner mgartner deleted the udf-anon-args branch August 19, 2022 13:08
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.

4 participants