Skip to content

Comments

Simplify regexp replace handling#32053

Merged
antiguru merged 4 commits intoMaterializeInc:mainfrom
antiguru:regexpr_replace_lit_error
Apr 7, 2025
Merged

Simplify regexp replace handling#32053
antiguru merged 4 commits intoMaterializeInc:mainfrom
antiguru:regexpr_replace_lit_error

Conversation

@antiguru
Copy link
Member

@antiguru antiguru commented Mar 31, 2025

Simplify regexp replace handling by using a literal error

Instead of encapsulating a result, replace the function call by a literal error. The hope is that this is semantically equivalent to the existing implementation.

Part of MaterializeInc/database-issues#9138

Motivation

Tips for reviewer

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

@antiguru antiguru marked this pull request as ready for review March 31, 2025 13:49
@antiguru antiguru requested a review from a team as a code owner March 31, 2025 13:49
@antiguru antiguru requested a review from ggevay March 31, 2025 13:49
@ggevay
Copy link
Contributor

ggevay commented Mar 31, 2025

Unfortunately, there was a reason for this complication: #27300 (comment)
(which totally should have been recorded in a code comment on the field)

@antiguru antiguru force-pushed the regexpr_replace_lit_error branch from c33a512 to 7007eaf Compare April 3, 2025 07:33
Comment on lines 1244 to 1256
Err(err) => {
let mut exprs = mem::take(exprs);
let source = exprs.swap_remove(0);
let scalar_type = e.typ(column_types).scalar_type;
// We need to return `NULL` on `NULL` input, and error otherwise.
source
.call_is_null()
.if_then_else(
MirScalarExpr::literal_null(scalar_type.clone()),
MirScalarExpr::literal(Err(err), scalar_type),
)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@ggevay I changed the error path to return null on null input, and error otherwise. I think this should match the current behavior!

@antiguru antiguru force-pushed the regexpr_replace_lit_error branch from 7007eaf to d75ea5b Compare April 3, 2025 15:41
Copy link
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Good idea!

let regex = match func::build_regex(pattern, &flags) {
Ok(regex) => Ok((regex, limit)),
Err(err) => Err(err),
*e = match func::build_regex(pattern, &flags) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the above comment. Or you could just remove that comment, since there is also a comment below in the error case.

let mut exprs = mem::take(exprs);
let source = exprs.swap_remove(0);
let scalar_type = e.typ(column_types).scalar_type;
// We need to return `NULL` on `NULL` input, and error otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe extend the comment a bit. Something like:
"We'd like the same behaviors between the regex argument being dynamic or a literal. Therefore, we need to return NULL on NULL input, and error otherwise, because this is what the original, dynamic function does."

antiguru added 4 commits April 7, 2025 16:50
Signed-off-by: Moritz Hoffmann <mh@materialize.com>
Signed-off-by: Moritz Hoffmann <mh@materialize.com>
Signed-off-by: Moritz Hoffmann <mh@materialize.com>
Signed-off-by: Moritz Hoffmann <mh@materialize.com>
@antiguru antiguru force-pushed the regexpr_replace_lit_error branch from d75ea5b to 758ff98 Compare April 7, 2025 14:58
@antiguru
Copy link
Member Author

antiguru commented Apr 7, 2025

Thanks for the review!

@antiguru antiguru enabled auto-merge (squash) April 7, 2025 14:58
@antiguru antiguru merged commit d437817 into MaterializeInc:main Apr 7, 2025
82 checks passed
@antiguru antiguru deleted the regexpr_replace_lit_error branch April 8, 2025 06:51
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.

2 participants