Skip to content

[C++] String repeat kernel #18661

Closed
Closed

Description

@asfimport

Like SQL replicate or Python 'string' * n

Reporter: Ian Cook / @ianmcook
Assignee: Eduardo Ponce / @edponce

Related issues:

PRs and other links:

Note: This issue was originally created as ARROW-12712. Please see the migration documentation for further details.

Activity

  1. asfimport commented on May 11, 2021

    @asfimport
    Author
  2. asfimport commented on Aug 29, 2021

    @asfimport
    Author

    Eduardo Ponce / @edponce:
    There are several variants of string repeats across languages:

    1. Python, SQL - support a single integer value for number of repeats. All strings are replicated the same number of times.
    2. Support a sequence of integers where each value is the number of repeats for the string corresponding to that same index. This may have its complexities in Arrow if operating on unordered batches of data.
    3. Pandas, R - support (1) and (2).
    4. R - allow different number of input strings and repeat values.

    Below are examples of each languages API and supported variants for string repeat.

    Based on this, I consider having the string repeat in Arrow C++ support case (3) and for the case (2) consider invalid if number of strings and number of repeats differ in length.

    Python:

    >>> 'a' * 2  # 'aa'
    >>> 'b' * 3  # 'bbb'

    Pandas has str.repeat function:

    >>> s =pd.Series(['a', 'b'])
    >>> s.str.repeat(2)          # ['aa', 'bb']
    >>> s.str.repeat([2, 3])     # ['aa', 'bbb']
    >>> s.str.repeat([2, 3, 4])  # Error: different length arrays
    >>> s.str.repeat([2])        # Error: different length arrays

    SQL has replicate function:

    SELECT REPLICATE('a', 2);  -- 'aa'
    SELECT REPLICATE('b', 3);  -- 'bbb'

    R has strrep function:

    > strrep(c('a', 'b'), 2)             # 'aa', 'bb'
    > strrep(c('a', 'b'), c(2, 3))       # 'aa', 'bbb'
    # R cycles strings/repeats if length of sequences differ
    > strrep(c('a', 'b'), c(2, 3, 4))    # 'aa', 'bbb', 'aaaa'
    > strrep(c('a', 'b', 'c'), c(2, 3))  # 'aa', 'bbb', 'cc'
  3. asfimport commented on Nov 4, 2021

    @asfimport
    Author

    David Li / @lidavidm:
    Issue resolved by pull request 11023
    #11023

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions