Skip to content

Conversation

@DaveCTurner
Copy link
Contributor

An issue with Strings#collectionToDelimitedStringWithLimit is that you
need to collect all the items together up front first, even if you're
going to throw most of them away. This commit introduces
BoundedDelimitedStringCollector which allows to accumulate the items
one-at-a-time instead.

An issue with `Strings#collectionToDelimitedStringWithLimit` is that you
need to collect all the items together up front first, even if you're
going to throw most of them away. This commit introduces
`BoundedDelimitedStringCollector` which allows to accumulate the items
one-at-a-time instead.
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Mar 7, 2025

if (state != batchExecutionContext.initialState()) {
var reason = new StringBuilder();
Strings.collectionToDelimitedStringWithLimit(results, ",", "lazy bulk rollover [", "]", 1024, reason);
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized the prefix and suffix params don't work as I thought they would. They're added to every item, whereas I thought they would only be added once at the start and once at the end respectively. I see that the two usages in rollover and lazy rollover are the only usages that specify a (non-empty) prefix and suffix, and it looks to me like it doesn't really make sense to wrap every result with the string with lazy bulk rollover [...]; it would make more sense to wrap all the results with the string lazy bulk rollover [result1, result2].

Assuming that we'd fix those two use cases, there are no use cases of Strings.collectionToDelimitedStringWithLimit that pass non-empty strings for the prefix and suffix, so I think we can just remove those two parameters. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ha yeah that caught me out when re-implementing it here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me open a PR to do that first, it'll be noisy here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DaveCTurner DaveCTurner requested a review from nielsbauman March 7, 2025 18:35
Copy link
Contributor

@nielsbauman nielsbauman left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the iterations, David :)

@DaveCTurner DaveCTurner added auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) auto-backport Automatically create backport pull requests when merged labels Mar 7, 2025
@elasticsearchmachine elasticsearchmachine merged commit 2fbce4b into elastic:main Mar 7, 2025
17 checks passed
@DaveCTurner DaveCTurner deleted the 2025/03/07/limit-string-collection-length-util branch March 7, 2025 21:05
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 124303

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Mar 7, 2025
An issue with `Strings#collectionToDelimitedStringWithLimit` is that you
need to collect all the items together up front first, even if you're
going to throw most of them away. This commit introduces
`BoundedDelimitedStringCollector` which allows to accumulate the items
one-at-a-time instead.

Backport of elastic#124303 to `8.x`
@DaveCTurner
Copy link
Contributor Author

backport is #124382

elasticsearchmachine pushed a commit that referenced this pull request Mar 7, 2025
An issue with `Strings#collectionToDelimitedStringWithLimit` is that you
need to collect all the items together up front first, even if you're
going to throw most of them away. This commit introduces
`BoundedDelimitedStringCollector` which allows to accumulate the items
one-at-a-time instead.

Backport of #124303 to `8.x`
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Mar 11, 2025
An issue with `Strings#collectionToDelimitedStringWithLimit` is that you
need to collect all the items together up front first, even if you're
going to throw most of them away. This commit introduces
`BoundedDelimitedStringCollector` which allows to accumulate the items
one-at-a-time instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants