Skip to content

ARROW-10306: [C++] Add string replacement kernel - #8468

Closed
maartenbreddels wants to merge 3 commits into
apache:masterfrom
maartenbreddels:ARROW-10306
Closed

ARROW-10306: [C++] Add string replacement kernel#8468
maartenbreddels wants to merge 3 commits into
apache:masterfrom
maartenbreddels:ARROW-10306

Conversation

@maartenbreddels

@maartenbreddelsmaartenbreddels commented Oct 15, 2020

Copy link
Copy Markdown
Contributor

Two new kernels

  • replace_substring like Python's str.replace
  • replace_substring_re2 like Python's re.sub

@github-actions

Copy link
Copy Markdown

@pitrou

Copy link
Copy Markdown
Member

You may want to remove the regex variant of this if you want to move this forward without depending on resolving the re2 dependency issue.

@jorisvandenbossche

Copy link
Copy Markdown
Member

@maartenbreddels would it be practical to split this into two PRs? (one for plain replace, other for re2-based replace) Or would you prefer first to have the re2 dependency issue resolved? (ARROW-10541)

@github-actionsgithub-actionsBot added the needs-rebase A PR that needs to be rebased by the author label Nov 25, 2020
@github-actionsgithub-actionsBot removed the needs-rebase A PR that needs to be rebased by the author label Nov 25, 2020
@maartenbreddels

Copy link
Copy Markdown
ContributorAuthor

I'd rather keep this 1 PR, looks like #8756 is working

@maartenbreddels
maartenbreddels marked this pull request as ready for review November 25, 2020 16:12
@maartenbreddels

Copy link
Copy Markdown
ContributorAuthor

@pitrou this is ready for review, failure seems unrelated (minio on windows).

@pitroupitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Neat! See comments below.

Comment threadcpp/src/arrow/compute/api_scalar.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ReplaceString below is basically independent from Type, but using this idiom may compile it twice. Can you find another way to parametrize the kernel?
(hint: perhaps use composition rather than inheritance)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Maybe I misunderstand, but via offset_type we are not independent of Type right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, I don't understand why offset_type is being used here. ValueDataBuilder is basically a TypedBufferBuilder<uint8_t>, it's used for building the string data, it doesn't deal with string offsets.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Ok, yes, I see it now. I'm using offset_type in this class as well, which I shouldn't, I think that's what led me to this. This requires a bit of refactoring.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This pattern occurs more often in the file, I didn't realize this lead to slower compilation and probably larger binary sizes. I think it requires a refactor that is larger than this PR. Also, I won't have the time currently to do this. Can we merge this as is, and I'll open a Jira issue?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, you don't need to refactor other kernels for now, but I suppose this one could easily be adapted, no? :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similarly as above, this looks basically independent from Type.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that the GlobalReplace loop works a bit differently, it calls Match then Rewrite, avoiding the duplicate matching calls. Not sure it's worth optimizing this, though:
https://github.com/google/re2/blob/master/re2/re2.cc#L427

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Good idea, I prefer to keep it as it is, I left a comment in the code so this doesn't get lost.

Comment threaddocs/source/cpp/compute.rst Outdated
Comment threadcpp/src/arrow/compute/kernels/scalar_string_test.cc Outdated
@github-actionsgithub-actionsBot added the needs-rebase A PR that needs to be rebased by the author label Nov 27, 2020
@github-actionsgithub-actionsBot removed the needs-rebase A PR that needs to be rebased by the author label Dec 18, 2020
@pitrou

Copy link
Copy Markdown
Member

@maartenbreddels Is it ready for review again? Feel free to ping me.

@maartenbreddels

Copy link
Copy Markdown
ContributorAuthor

@pitrou Yes, apart from an unanswered question this is ready for review 👍

@maartenbreddels

Copy link
Copy Markdown
ContributorAuthor

@pitrou this is ready for review (assuming you agree with the above plan of doing a refactor later on)

@jorisvandenbossche

Copy link
Copy Markdown
Member

(gentle ping here, would really like to see those PRs merged for 4.0 in April!)

@pitrou

Copy link
Copy Markdown
Member

I'll rebase and update this PR.

@pitrou

Copy link
Copy Markdown
Member

@nealrichardson

Copy link
Copy Markdown
Member

Haven't seen that before, and we've been building with re2 for months now. Maybe this is the first time we're building something that actually uses re2? It's possible that re2 needs a "backport" library built with the rtools3.5 toolchain; an immediate workaround could be to build with -DRE2_SOURCE=BUNDLED here, or to make ARROW_WITH_RE2 conditional on the toolchain (like we do for ARROW_S3 already). Given that we won't have to support the rtools3.5 toolchain after April or May, I'll try just turning it off here.

@nealrichardson

Copy link
Copy Markdown
Member

@github-actions crossbow submit -g r

@github-actions

Copy link
Copy Markdown

Revision: 82bb60d

Submitted crossbow builds: ursacomputing/crossbow @ actions-233

TaskStatus
conda-linux-gcc-py36-cpu-r36Azure
conda-linux-gcc-py37-cpu-r40Azure
conda-osx-clang-py36-r36Azure
conda-osx-clang-py37-r40Azure
conda-win-vs2017-py36-r36Azure
conda-win-vs2017-py37-r40Azure
homebrew-r-autobrewGithub Actions
test-r-install-localGithub Actions
test-r-linux-as-cranGithub Actions
test-r-minimal-buildAzure
test-r-rhub-ubuntu-gcc-releaseAzure
test-r-rocker-r-base-latestAzure
test-r-rstudio-r-base-3.6-bionicAzure
test-r-rstudio-r-base-3.6-centos7-devtoolset-8Azure
test-r-rstudio-r-base-3.6-centos8Azure
test-r-rstudio-r-base-3.6-opensuse15Azure
test-r-rstudio-r-base-3.6-opensuse42Azure
test-r-version-compatibilityGithub Actions
test-r-versionsGithub Actions
test-ubuntu-18.04-r-sanitizerAzure

@nealrichardson

Copy link
Copy Markdown
Member

The as-cran failure is legit: https://github.com/ursacomputing/crossbow/runs/2197449739?check_suite_focus=true#step:7:210

It's a weird build setup that uses clang and -stdlib=libc++; unfortunately we have to support it because it's one of CRAN's checks. But I'll deal with this in a followup.

@nealrichardson

Copy link
Copy Markdown
Member

I made ARROW-12094 for fixing that build. Merging now.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@maartenbreddels@pitrou@jorisvandenbossche@nealrichardson