You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is part of a more general "we don't support Unicode" issue. Changing this is kinda hard (we could special-case .split(''), but making split work with Unicode in general would be hard).
(Note that we have to be careful that the result of split doesn't depend on the locale or the version of ICU installed on the machine (unless we provide our own static version), because otherwise it will no longer be deterministic and writes might diverge.)
It's actually very easy to do this by hand (UTF-8 is a self synchronizing format, and it's very easy to know when you're past a code point). I can actually do it if you think it valuable, but I think it would be better to use ICU's version when/if we include ICU into the rest of the system.
You'll still have a different issue, which is that we will split combining characters away from their root code point. This is a much bigger issue to handle—you basically need a lookup table telling you whether the character in question is in the "M" category (most are Mn, some Indic scripts have Mcs, and then there's weird things like U+20DD for making 2⃝). This isn't difficult—the Unicode consortium have done all the intellectual spadework, which is represented in UnicodeData.txt and SpecialCasing.txt—but it would be better to use somebody else's library for this (probably ICU).
If you want an example of what this looks like, consider the following query: r.expr("\u006f\u0301a va").split('o') which yields
For what it's worth I don't care which version of Unicode we standardize on (a decision effectively determined by the version of ICU we decide to use). Unicode 7 added things like Mende Kikakui, which is used by less than 500 people. While I think it would be tragic if one of them tried to use our database and couldn't, I doubt it's worth worrying about.
Incidentally I checked other implementations for consistency on this. Python does not appear to support split(''). Ruby and node.js give the following results (here U+00E9 is é and U+0301 is the combining character for that accent):
I am of the opinion that this is simply wrong. Whatever you are using split('') for, it is not well served by it handing you an accented quotation mark. I asked a friend of mine who doesn't have any particular interest in Unicode about it, and she agrees that, no matter what the actual codepoints look like, '́ is a crime against God and Man alike.
If there is interest, we could probably add a decompose function that would actually split based on codepoints instead of semantically. I expect that almost no one would use it, however.
@danielmewes -- do you think we need to support the old behavior and force people to upgrade their indexes, or should we just assume nobody's depending on the old incorrect split behavior in an sindex function?
We should definitely bump the index ReQL version. (Maybe at some point we should think about scanning sindex functions for whether certain terms are used to decide whether an index is outdated, but let's not do that now.)
We should only provide a backwards-compatible implementation for older indexes if it isn't much work.
#2950 comes to mind. There's the upcase/downcase thing, which is unicode unawares but not unicode-breaking. r.js needs to be inspected, but I'm not especially concerned because JS strings are supposed to be UTF-8 anyway. I will probably need to give r.match a once over to be sure.
We just don't have very many string operations at present.
Activity
mlucy commentedon Jun 7, 2014
This is part of a more general "we don't support Unicode" issue. Changing this is kinda hard (we could special-case
.split(''), but makingsplitwork with Unicode in general would be hard).neumino commentedon Jun 7, 2014
Moving in backlog for now then.
AtnNn commentedon Jun 9, 2014
RethinkDB already bundles RE2 and ICU. Either of those could be used to help implement
split('')for utf-8.mlucy commentedon Jun 9, 2014
Ah, if we already have ICU it shouldn't be that hard.
mlucy commentedon Jun 9, 2014
(Note that we have to be careful that the result of
splitdoesn't depend on the locale or the version of ICU installed on the machine (unless we provide our own static version), because otherwise it will no longer be deterministic and writes might diverge.)gchpaco commentedon Dec 13, 2014
It's actually very easy to do this by hand (UTF-8 is a self synchronizing format, and it's very easy to know when you're past a code point). I can actually do it if you think it valuable, but I think it would be better to use ICU's version when/if we include ICU into the rest of the system.
You'll still have a different issue, which is that we will split combining characters away from their root code point. This is a much bigger issue to handle—you basically need a lookup table telling you whether the character in question is in the "M" category (most are Mn, some Indic scripts have Mcs, and then there's weird things like U+20DD for making 2⃝). This isn't difficult—the Unicode consortium have done all the intellectual spadework, which is represented in UnicodeData.txt and SpecialCasing.txt—but it would be better to use somebody else's library for this (probably ICU).
If you want an example of what this looks like, consider the following query:
r.expr("\u006f\u0301a va").split('o')which yieldsand yes, that is an accented quotation mark.
gchpaco commentedon Dec 13, 2014
For what it's worth I don't care which version of Unicode we standardize on (a decision effectively determined by the version of ICU we decide to use). Unicode 7 added things like Mende Kikakui, which is used by less than 500 people. While I think it would be tragic if one of them tried to use our database and couldn't, I doubt it's worth worrying about.
gchpaco commentedon Dec 15, 2014
Incidentally I checked other implementations for consistency on this. Python does not appear to support
split(''). Ruby and node.js give the following results (here U+00E9 is é and U+0301 is the combining character for that accent):and for node
I am of the opinion that this is simply wrong. Whatever you are using
split('')for, it is not well served by it handing you an accented quotation mark. I asked a friend of mine who doesn't have any particular interest in Unicode about it, and she agrees that, no matter what the actual codepoints look like, '́ is a crime against God and Man alike.If there is interest, we could probably add a
decomposefunction that would actually split based on codepoints instead of semantically. I expect that almost no one would use it, however.danielmewes commentedon Dec 15, 2014
I agree that
splitshould handle composed characters, and we should do it right even if Ruby and node.js don't.I don't think we need a
decomposefunction. At least not until someone asks for it.3 remaining items
gchpaco commentedon Mar 28, 2015
CR 2754.
mlucy commentedon Mar 30, 2015
@danielmewes -- do you think we need to support the old behavior and force people to upgrade their indexes, or should we just assume nobody's depending on the old incorrect
splitbehavior in an sindex function?danielmewes commentedon Mar 30, 2015
We should definitely bump the index ReQL version. (Maybe at some point we should think about scanning sindex functions for whether certain terms are used to decide whether an index is outdated, but let's not do that now.)
We should only provide a backwards-compatible implementation for older indexes if it isn't much work.
mlucy commentedon Mar 30, 2015
It should be pretty easy; the old code doesn't need to be changed, we just need to branch and call it.
mlucy commentedon Mar 31, 2015
@gchpaco -- +1
Do you know off the top of your head what other unicode-unaware operations we have lying around, if any? (Aside from lexicographic ordering, that is.)
gchpaco commentedon Apr 1, 2015
#2950 comes to mind. There's the upcase/downcase thing, which is unicode unawares but not unicode-breaking.
r.jsneeds to be inspected, but I'm not especially concerned because JS strings are supposed to be UTF-8 anyway. I will probably need to giver.matcha once over to be sure.We just don't have very many string operations at present.
Merge branch 'gchpaco_utf8' into next