Skip to content

fix pattern handling in regexp_match function#1065

Merged
alamb merged 1 commit intoapache:masterfrom
houqp:qp_regex_fix
Oct 5, 2021
Merged

fix pattern handling in regexp_match function#1065
alamb merged 1 commit intoapache:masterfrom
houqp:qp_regex_fix

Conversation

@houqp
Copy link
Member

@houqp houqp commented Oct 1, 2021

Rationale for this change

We are accessing the pattern flag using the wrong index.

What changes are included in this PR?

Fixed index and added tests. Also refactored code to make it more readable.

Are there any user-facing changes?

no

@houqp houqp added this to the 5.1.0 milestone Oct 1, 2021
@houqp houqp modified the milestones: 5.1.0, arrow2 Oct 1, 2021
@houqp houqp added the bug Something isn't working label Oct 1, 2021
3 => {
let values = downcast_string_arg!(args[0], "string", T);
let regex = downcast_string_arg!(args[1], "pattern", T);
let flags = Some(downcast_string_arg!(args[2], "flags", T));
Copy link
Member Author

Choose a reason for hiding this comment

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

this line is the fix, index was 1 before the fix.

@houqp
Copy link
Member Author

houqp commented Oct 1, 2021

Found this during the arrow2 migration.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks great to me. Nice find @houqp

cc @seddonm1

2 => {
let values = downcast_string_arg!(args[0], "string", T);
let regex = downcast_string_arg!(args[1], "pattern", T);
compute::regexp_match(values, regex, None).map_err(DataFusionError::ArrowError)
Copy link
Contributor

Choose a reason for hiding this comment

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

let mut expected_builder = ListBuilder::new(elem_builder);
expected_builder.values().append_value("a").unwrap();
expected_builder.append(true).unwrap();
expected_builder.values().append_value("a").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

expected_builder.append(true).unwrap();
expected_builder.values().append_value("b").unwrap();
expected_builder.append(true).unwrap();
expected_builder.values().append_value("b").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@alamb alamb merged commit 5cc4e9f into apache:master Oct 5, 2021
@seddonm1
Copy link
Contributor

seddonm1 commented Oct 5, 2021

Thanks @houqp

unkloud pushed a commit to unkloud/datafusion that referenced this pull request Mar 23, 2025
…1065)

* minor: refactor UnaryExpr handling to make more concise

* add documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants