Skip to content

sql: fix conflicting udf options validation#85922

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
chengxiong-ruan:udf-fix-conflicting-options-error
Aug 18, 2022
Merged

sql: fix conflicting udf options validation#85922
craig[bot] merged 1 commit intocockroachdb:masterfrom
chengxiong-ruan:udf-fix-conflicting-options-error

Conversation

@chengxiong-ruan
Copy link
Copy Markdown
Contributor

@chengxiong-ruan chengxiong-ruan commented Aug 10, 2022

A silly mistake that forgot to add option type to the map :(

Release note: None
Release justification: Fixing a bug that function options can be
conflicting with each other. Also Fixing a bug that leakproof can
be set for non-immutable function with ALTER FUNCTION

@chengxiong-ruan chengxiong-ruan requested a review from a team as a code owner August 10, 2022 19:45
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@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.

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @chengxiong-ruan)


pkg/sql/logictest/testdata/logic_test/udf line 25 at r1 (raw file):


statement error pq: conflicting or redundant options
CREATE FUNCTION f() RETURNS INT IMMUTABLE LANGUAGE SQL LANGUAGE SQL AS $$ SELECT 1 $$;

nit: add test with CALLED ON NULL INPUT/STRICT/RETURNS NULL ON NULL INPUT too


pkg/sql/opt/optbuilder/create_function.go line 72 at r1 (raw file):

	for _, option := range cf.Options {
		optTypeName := reflect.TypeOf(option).Name()
		if _, ok := options[optTypeName]; ok {

It's not a super performance critical code path, but the map and reflection are an anti-pattern. You could define a helper to check for duplicate options that simply stores a bool for each option type.

@chengxiong-ruan
Copy link
Copy Markdown
Contributor Author

pkg/sql/opt/optbuilder/create_function.go line 72 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

It's not a super performance critical code path, but the map and reflection are an anti-pattern. You could define a helper to check for duplicate options that simply stores a bool for each option type.

ah yeah, I agree, I'll make a helper for it. thanks.

@chengxiong-ruan chengxiong-ruan force-pushed the udf-fix-conflicting-options-error branch from b2e63c9 to 0e2dbbb Compare August 11, 2022 22:41
@chengxiong-ruan chengxiong-ruan requested a review from a team August 11, 2022 22:41
Copy link
Copy Markdown
Contributor Author

@chengxiong-ruan chengxiong-ruan left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner)


pkg/sql/logictest/testdata/logic_test/udf line 25 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

nit: add test with CALLED ON NULL INPUT/STRICT/RETURNS NULL ON NULL INPUT too

Added more tests.


pkg/sql/opt/optbuilder/create_function.go line 72 at r1 (raw file):

Previously, chengxiong-ruan (Chengxiong Ruan) wrote…

ah yeah, I agree, I'll make a helper for it. thanks.

changed as suggested, thanks again!

@chengxiong-ruan chengxiong-ruan force-pushed the udf-fix-conflicting-options-error branch 3 times, most recently from f45a15c to eaac80d Compare August 12, 2022 17:19
@chengxiong-ruan chengxiong-ruan force-pushed the udf-fix-conflicting-options-error branch from eaac80d to 7fbb264 Compare August 16, 2022 21:43
@chengxiong-ruan chengxiong-ruan requested a review from a team August 16, 2022 21:43
@chengxiong-ruan chengxiong-ruan force-pushed the udf-fix-conflicting-options-error branch from 7fbb264 to 45b9307 Compare August 16, 2022 21:44
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm: mod nits

Reviewed 8 of 9 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @chengxiong-ruan and @mgartner)


-- commits line 4 at r2:
Can you make this commit message more clear?


pkg/sql/sem/tree/udf_test.go line 76 at r2 (raw file):

	for i, tc := range testCases {
		t.Run(strconv.Itoa(i+1), func(t *testing.T) {

nit: the options do know how to turn themselves into strings. It might make for better subtest names

This commit fixes a bug where function options can be conflicting
with each other because we forgot to add option type names into
the dedupe map. A helper is added to handle the validation.

This commit also fixes another bug in ALTER FUNCTION where leakproof
can be set for a non-immutable function. A helper is also added so
the logic can be reused.

Release note: None
Release justification: Fixing a bug that function options can be
conflicting with each other. Also Fixing a bug that leakproof can
be set for non-immutable function with ALTER FUNCTION
@chengxiong-ruan chengxiong-ruan force-pushed the udf-fix-conflicting-options-error branch from 45b9307 to e0ce0fc Compare August 18, 2022 13:54
Copy link
Copy Markdown
Contributor Author

@chengxiong-ruan chengxiong-ruan left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner and @mgartner)


-- commits line 4 at r2:

Previously, ajwerner wrote…

Can you make this commit message more clear?

oops... fixed.


pkg/sql/sem/tree/udf_test.go line 76 at r2 (raw file):

Previously, ajwerner wrote…

nit: the options do know how to turn themselves into strings. It might make for better subtest names

added test names by hand instead. thanks.

@chengxiong-ruan
Copy link
Copy Markdown
Contributor Author

TFTR! 🙏
bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 18, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 18, 2022

Build succeeded:

@craig craig bot merged commit 1b25703 into cockroachdb:master Aug 18, 2022
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