You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@arrow.apache.org by Niranda Perera <ni...@gmail.com> on 2021/05/17 14:28:54 UTC
String reverse kernel
Hi all,
This is RE: [1] & [2] String reverse kernel. Even though it is a seemingly
trivial exercise, I would like to clarify a few things.
In the current PR [1], there are 2 reverse kernels, ASCII and UTF8. I'd
like to get some feedback for the following points.
1. For ASCII reverse, I am throwing an error if a non-ascii char is
encountered. Should we throw this error? or return a garbage output (ex:
a\xD1b --> b\x1D\a)
2. For UTF8 reverse, I am returning some garbage output when malformed utf8
buffers are present but the algorithm guarantees that it would return the
same buffer sizes as the input. IMO, the current algorithm works
efficiently for valid UTF8 chars.
#1 and #2 are inconsistent and I'd like to know what is the best way to
handle malformed/ invalid chars
3. As @DavidLi pointed out in the PR, UTF8 chars can go beyond 4 bytes (ex:
emojis, utf-8 pairs, etc). and currently these are not handled.
Look forward to hearing from you.
Best
[1] https://github.com/apache/arrow/pull/10317
[2] https://issues.apache.org/jira/browse/ARROW-12713
--
Niranda Perera
https://niranda.dev/
@n1r44 <https://twitter.com/N1R44>
Re: String reverse kernel
Posted by David Li <li...@apache.org>.
Sure, that is a fair point. But in this case Unicode defines both codepoint and (extended) grapheme cluster, so I felt it might be worth including a quick note about which one is being reversed (though to be fair, nearly every language picks codepoint except maybe Swift, IIUC).
In either case it's not something I feel very strongly about.
-David
On 2021/05/17 15:20:57, Antoine Pitrou <an...@python.org> wrote:
>
> Le 17/05/2021 à 17:17, David Li a écrit :
> > A little clarification on my point: it's not that a single codepoint
> > gets encoded with more than four bytes, it's that a grapheme
> > cluster/human-delimited 'character' might be multiple codepoints, so
> > reversing the individual codepoints may produce an unexpected
> > result. For instance a flag emoji is actually two codepoints (two
> > special 'letter' codepoints that represent the country code), so
> > reversing a US flag naively will give you an odd '[SU]' instead.
>
> This sounds like saying that reversing a valid French word does not
> produce a valid French word (well, in most cases). The kernel
> documentation can't contain an entire tutorial about Unicode characters
> and what to expect from them, IMHO.
>
> Regards
>
> Antoine.
>
Re: String reverse kernel
Posted by Niranda Perera <ni...@gmail.com>.
Thank you very much for your inputs, guys. So, based on the discussion, I
will make the following changes.
1. ASCII reverse would throw an error when a non-ASCII (valid/ invalid
utf8) byte is oThank you @antoinebserved (no change)
2. UTF8 kernel would return a garbage output when an invalid utf8 char is
observed but (no change)
Thank you @antoine for the clarification.
3. Edit documentation to clarify that the kernel works on code-point level
On Mon, May 17, 2021 at 11:31 AM Antoine Pitrou <an...@python.org> wrote:
>
> I'm fine with pointing out that the function operates on codepoints.
>
> Linking to the Unicode documentation for emojis sounds entirely like a
> distraction, though.
>
> Regards
>
> Antoine.
>
>
> Le 17/05/2021 à 17:28, Ian Cook a écrit :
> > +1 for clarifying this in the kernel documentation, referring to these
> > multi-emoji glyphs as "emoji ZWJ sequences," and linking to
> > https://unicode.org/emoji/charts/emoji-zwj-sequences.html
> >
> > Ian
> >
> >
> > On Mon, May 17, 2021 at 11:21 AM Antoine Pitrou <an...@python.org>
> wrote:
> >>
> >>
> >> Le 17/05/2021 à 17:17, David Li a écrit :
> >>> A little clarification on my point: it's not that a single codepoint
> >>> gets encoded with more than four bytes, it's that a grapheme
> >>> cluster/human-delimited 'character' might be multiple codepoints, so
> >>> reversing the individual codepoints may produce an unexpected
> >>> result. For instance a flag emoji is actually two codepoints (two
> >>> special 'letter' codepoints that represent the country code), so
> >>> reversing a US flag naively will give you an odd '[SU]' instead.
> >>
> >> This sounds like saying that reversing a valid French word does not
> >> produce a valid French word (well, in most cases). The kernel
> >> documentation can't contain an entire tutorial about Unicode characters
> >> and what to expect from them, IMHO.
> >>
> >> Regards
> >>
> >> Antoine.
>
--
Niranda Perera
https://niranda.dev/
@n1r44 <https://twitter.com/N1R44>
Re: String reverse kernel
Posted by Jonathan Keane <jo...@ursacomputing.com>.
Yeah, piggybacking on what Weston said: is the line that we want to draw is
code point, combining character sequences, or graphemes [1]. IME, most
people would want/assume that combining characters would stay combined in
reversals (using Weston's example: "tréma" becoming "aḿert" (though this
specific character "é" has a combining version e+U+0300 and a single code
point é, and for many diacritics from different writing systems there is
only the combining version).
But whatever division we choose, documentation + links to explanations are
great.
[1]
https://mathias.gaunard.com/unicode/doc/html/unicode/introduction_to_unicode.html#unicode.introduction_to_unicode.notion_of_character
there's also discussion at https://unicode.org/reports/tr29/, though the
first link I found much clearer.
On Mon, May 17, 2021 at 10:46 AM Weston Pace <we...@gmail.com> wrote:
> FWIW, combining marks were not actually added to support emojis. Emojis
> are just one of the more popular uses of the feature. Combining marks is a
> standard Unicode feature necessary to represent single “characters” in some
> complex situations (e.g. when it is necessary to distinguish between tréma
> and umlaut, or to represent certain characters in Navajo).
>
> That being said I agree with the conclusions. It’s ok to leave out for now
> and no need to link to any docs.
>
> On Mon, May 17, 2021 at 5:31 AM Antoine Pitrou <an...@python.org> wrote:
>
> >
> > I'm fine with pointing out that the function operates on codepoints.
> >
> > Linking to the Unicode documentation for emojis sounds entirely like a
> > distraction, though.
> >
> > Regards
> >
> > Antoine.
> >
> >
> > Le 17/05/2021 à 17:28, Ian Cook a écrit :
> > > +1 for clarifying this in the kernel documentation, referring to these
> > > multi-emoji glyphs as "emoji ZWJ sequences," and linking to
> > > https://unicode.org/emoji/charts/emoji-zwj-sequences.html
> > >
> > > Ian
> > >
> > >
> > > On Mon, May 17, 2021 at 11:21 AM Antoine Pitrou <an...@python.org>
> > wrote:
> > >>
> > >>
> > >> Le 17/05/2021 à 17:17, David Li a écrit :
> > >>> A little clarification on my point: it's not that a single codepoint
> > >>> gets encoded with more than four bytes, it's that a grapheme
> > >>> cluster/human-delimited 'character' might be multiple codepoints, so
> > >>> reversing the individual codepoints may produce an unexpected
> > >>> result. For instance a flag emoji is actually two codepoints (two
> > >>> special 'letter' codepoints that represent the country code), so
> > >>> reversing a US flag naively will give you an odd '[SU]' instead.
> > >>
> > >> This sounds like saying that reversing a valid French word does not
> > >> produce a valid French word (well, in most cases). The kernel
> > >> documentation can't contain an entire tutorial about Unicode
> characters
> > >> and what to expect from them, IMHO.
> > >>
> > >> Regards
> > >>
> > >> Antoine.
> >
>
Re: String reverse kernel
Posted by Weston Pace <we...@gmail.com>.
FWIW, combining marks were not actually added to support emojis. Emojis
are just one of the more popular uses of the feature. Combining marks is a
standard Unicode feature necessary to represent single “characters” in some
complex situations (e.g. when it is necessary to distinguish between tréma
and umlaut, or to represent certain characters in Navajo).
That being said I agree with the conclusions. It’s ok to leave out for now
and no need to link to any docs.
On Mon, May 17, 2021 at 5:31 AM Antoine Pitrou <an...@python.org> wrote:
>
> I'm fine with pointing out that the function operates on codepoints.
>
> Linking to the Unicode documentation for emojis sounds entirely like a
> distraction, though.
>
> Regards
>
> Antoine.
>
>
> Le 17/05/2021 à 17:28, Ian Cook a écrit :
> > +1 for clarifying this in the kernel documentation, referring to these
> > multi-emoji glyphs as "emoji ZWJ sequences," and linking to
> > https://unicode.org/emoji/charts/emoji-zwj-sequences.html
> >
> > Ian
> >
> >
> > On Mon, May 17, 2021 at 11:21 AM Antoine Pitrou <an...@python.org>
> wrote:
> >>
> >>
> >> Le 17/05/2021 à 17:17, David Li a écrit :
> >>> A little clarification on my point: it's not that a single codepoint
> >>> gets encoded with more than four bytes, it's that a grapheme
> >>> cluster/human-delimited 'character' might be multiple codepoints, so
> >>> reversing the individual codepoints may produce an unexpected
> >>> result. For instance a flag emoji is actually two codepoints (two
> >>> special 'letter' codepoints that represent the country code), so
> >>> reversing a US flag naively will give you an odd '[SU]' instead.
> >>
> >> This sounds like saying that reversing a valid French word does not
> >> produce a valid French word (well, in most cases). The kernel
> >> documentation can't contain an entire tutorial about Unicode characters
> >> and what to expect from them, IMHO.
> >>
> >> Regards
> >>
> >> Antoine.
>
Re: String reverse kernel
Posted by Antoine Pitrou <an...@python.org>.
I'm fine with pointing out that the function operates on codepoints.
Linking to the Unicode documentation for emojis sounds entirely like a
distraction, though.
Regards
Antoine.
Le 17/05/2021 à 17:28, Ian Cook a écrit :
> +1 for clarifying this in the kernel documentation, referring to these
> multi-emoji glyphs as "emoji ZWJ sequences," and linking to
> https://unicode.org/emoji/charts/emoji-zwj-sequences.html
>
> Ian
>
>
> On Mon, May 17, 2021 at 11:21 AM Antoine Pitrou <an...@python.org> wrote:
>>
>>
>> Le 17/05/2021 à 17:17, David Li a écrit :
>>> A little clarification on my point: it's not that a single codepoint
>>> gets encoded with more than four bytes, it's that a grapheme
>>> cluster/human-delimited 'character' might be multiple codepoints, so
>>> reversing the individual codepoints may produce an unexpected
>>> result. For instance a flag emoji is actually two codepoints (two
>>> special 'letter' codepoints that represent the country code), so
>>> reversing a US flag naively will give you an odd '[SU]' instead.
>>
>> This sounds like saying that reversing a valid French word does not
>> produce a valid French word (well, in most cases). The kernel
>> documentation can't contain an entire tutorial about Unicode characters
>> and what to expect from them, IMHO.
>>
>> Regards
>>
>> Antoine.
Re: String reverse kernel
Posted by Ian Cook <ia...@ursacomputing.com>.
+1 for clarifying this in the kernel documentation, referring to these
multi-emoji glyphs as "emoji ZWJ sequences," and linking to
https://unicode.org/emoji/charts/emoji-zwj-sequences.html
Ian
On Mon, May 17, 2021 at 11:21 AM Antoine Pitrou <an...@python.org> wrote:
>
>
> Le 17/05/2021 à 17:17, David Li a écrit :
> > A little clarification on my point: it's not that a single codepoint
> > gets encoded with more than four bytes, it's that a grapheme
> > cluster/human-delimited 'character' might be multiple codepoints, so
> > reversing the individual codepoints may produce an unexpected
> > result. For instance a flag emoji is actually two codepoints (two
> > special 'letter' codepoints that represent the country code), so
> > reversing a US flag naively will give you an odd '[SU]' instead.
>
> This sounds like saying that reversing a valid French word does not
> produce a valid French word (well, in most cases). The kernel
> documentation can't contain an entire tutorial about Unicode characters
> and what to expect from them, IMHO.
>
> Regards
>
> Antoine.
Re: String reverse kernel
Posted by Antoine Pitrou <an...@python.org>.
Le 17/05/2021 à 17:17, David Li a écrit :
> A little clarification on my point: it's not that a single codepoint
> gets encoded with more than four bytes, it's that a grapheme
> cluster/human-delimited 'character' might be multiple codepoints, so
> reversing the individual codepoints may produce an unexpected
> result. For instance a flag emoji is actually two codepoints (two
> special 'letter' codepoints that represent the country code), so
> reversing a US flag naively will give you an odd '[SU]' instead.
This sounds like saying that reversing a valid French word does not
produce a valid French word (well, in most cases). The kernel
documentation can't contain an entire tutorial about Unicode characters
and what to expect from them, IMHO.
Regards
Antoine.
Re: String reverse kernel
Posted by David Li <li...@apache.org>.
A little clarification on my point: it's not that a single codepoint
gets encoded with more than four bytes, it's that a grapheme
cluster/human-delimited 'character' might be multiple codepoints, so
reversing the individual codepoints may produce an unexpected
result. For instance a flag emoji is actually two codepoints (two
special 'letter' codepoints that represent the country code), so
reversing a US flag naively will give you an odd '[SU]' instead.
Not that this needs to be handled per se right now - but we should
perhaps point it out in the kernel documentation so people know what
to expect.
-David
On 2021/05/17 14:48:52, Antoine Pitrou <an...@python.org> wrote:
>
> Le 17/05/2021 à 16:28, Niranda Perera a écrit :
> > Hi all,
> >
> > This is RE: [1] & [2] String reverse kernel. Even though it is a seemingly
> > trivial exercise, I would like to clarify a few things.
> >
> > In the current PR [1], there are 2 reverse kernels, ASCII and UTF8. I'd
> > like to get some feedback for the following points.
> >
> > 1. For ASCII reverse, I am throwing an error if a non-ascii char is
> > encountered. Should we throw this error? or return a garbage output (ex:
> > a\xD1b --> b\x1D\a)
>
> Since this is taking valid UTF8 input, it should not produce invalid
> output, so an error should be emitted (IMHO).
>
> > 2. For UTF8 reverse, I am returning some garbage output when malformed utf8
> > buffers are present but the algorithm guarantees that it would return the
> > same buffer sizes as the input. IMO, the current algorithm works
> > efficiently for valid UTF8 chars.
>
> Since this is taking invalid UTF8 input, we don't care that the output
> is invalid as well.
>
> > 3. As @DavidLi pointed out in the PR, UTF8 chars can go beyond 4 bytes (ex:
> > emojis, utf-8 pairs, etc). and currently these are not handled.
>
> I'm not aware of that. Encodings beyond 4 bytes are invalid.
> See for example the IETF RFC for UTF-8:
> https://datatracker.ietf.org/doc/html/rfc3629#section-4
> or the Unicode standard (chapter 3, p. 124, Table 3-7. Well-Formed UTF-8
> Byte Sequences):
> https://www.unicode.org/versions/Unicode13.0.0/ch03.pdf
>
> Regards
>
> Antoine.
>
Re: String reverse kernel
Posted by Antoine Pitrou <an...@python.org>.
Le 17/05/2021 à 16:28, Niranda Perera a écrit :
> Hi all,
>
> This is RE: [1] & [2] String reverse kernel. Even though it is a seemingly
> trivial exercise, I would like to clarify a few things.
>
> In the current PR [1], there are 2 reverse kernels, ASCII and UTF8. I'd
> like to get some feedback for the following points.
>
> 1. For ASCII reverse, I am throwing an error if a non-ascii char is
> encountered. Should we throw this error? or return a garbage output (ex:
> a\xD1b --> b\x1D\a)
Since this is taking valid UTF8 input, it should not produce invalid
output, so an error should be emitted (IMHO).
> 2. For UTF8 reverse, I am returning some garbage output when malformed utf8
> buffers are present but the algorithm guarantees that it would return the
> same buffer sizes as the input. IMO, the current algorithm works
> efficiently for valid UTF8 chars.
Since this is taking invalid UTF8 input, we don't care that the output
is invalid as well.
> 3. As @DavidLi pointed out in the PR, UTF8 chars can go beyond 4 bytes (ex:
> emojis, utf-8 pairs, etc). and currently these are not handled.
I'm not aware of that. Encodings beyond 4 bytes are invalid.
See for example the IETF RFC for UTF-8:
https://datatracker.ietf.org/doc/html/rfc3629#section-4
or the Unicode standard (chapter 3, p. 124, Table 3-7. Well-Formed UTF-8
Byte Sequences):
https://www.unicode.org/versions/Unicode13.0.0/ch03.pdf
Regards
Antoine.