Tarantool development patches archive
 help / color / mirror / Atom feed
From: Stanislav Zudin <szudin@tarantool.org>
To: tarantool-patches@freelists.org, kostja@tarantool.org
Cc: Stanislav Zudin <szudin@tarantool.org>
Subject: [tarantool-patches] [PATCH] Feature request for a new collation
Date: Fri, 22 Feb 2019 14:49:39 +0300	[thread overview]
Message-ID: <20190222114939.21764-1-szudin@tarantool.org> (raw)

Adds a new default collation 'unicode_s2' to support the difference 
between Cyrillic letters 'Е' and 'Ё'. The standard case insensitive 
collation ('unicode_ci') doesn't distinguish these letters.

Closes #4007
---
Branch: https://github.com/tarantool/tarantool/tree/stanztt/gh-4007-new-default-collation
Issue: https://github.com/tarantool/tarantool/issues/4007

 src/box/bootstrap.snap      | Bin 1527 -> 1561 bytes
 src/box/lua/upgrade.lua     |   6 ++
 test/box/collation.result   | 160 ++++++++++++++++++++++++++++++++++++
 test/box/collation.test.lua |  49 +++++++++++
 4 files changed, 215 insertions(+)
 create mode 100644 test/box/collation.result
 create mode 100644 test/box/collation.test.lua

diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap
index ba2af079571bab8f073d56223a4028e34068c3f6..190eb63d57990a95e0d1d8b3b588c02ad98ff1bc 100644
GIT binary patch
delta 1524
zcmV<Q1q=H33z-a%9Dg<~XJ#>GW-wwkFgFTGZgX^DZewLSAT~5JGB;&5WGyl@Vlyo?
zG&eUbIXE*jEj2MVWHn|nWjHf7HVRflY;R+0Iv{&}3JMAe3JMAe)w&D1%>|eM&V=|9
zZ>0bL0000ewJ-euP<<=__Po<a;Mk}DFbosKFvEnw+!zrV%YVYz*tSA4=C!uVU@)Qb
zUu0!Ula`WLm+t*Vn)Fnz*E(8<>$Uw#zBO|*OD$y@m6g|-Ba$hly8yTV#Q?M&o*^@b
zx4u>0*0a2AYt$vc)%unXik+8vgR<}Q3h&%)FS_{b!}h%^ZritRp6w8!AGTr-^~$C*
z9}HPRybIpko_|01pZ#9zSN&%}SH`1#LMinz(uDwgIrM(tY<AeLOAwoD;p!w^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z44+zMu1O2@TDf
z;>caHiAY41EK&qhO`ub0Bg=lfS@jbMWc2jfd!)h1CYa-6#H#C$7ZF!>?{suhjo?2`
zlSc*6T18TPZujtg(fdc-3x-%1l)NJ%#`7ywSL8WgPth-eS~$=7+7#WeRDV$pTFz}D
z+(I0qANIj)A&4g-6&;Y~mJYA8Wu$^EJJR21B|<d(D72GuwAH~*qIQknEdHw607z%L
z7puS6;%Ga`^J~VL?KV7f#`Dh^i8COyynLr=c!r$T`uXH);R1Jxbb#aqH=)Q|f(ynY
z%=BMKhBwV@Zn%OfhcWH+U1l8Jt0|piV3)j!t;dZ|mR5>+Bf5)E8gn%>CDE?$4y%lV
zFwK^Nv^i0lN!ndxKa}aX)~fwx#qyR)`Qn7hl7agmJSqM*n0X#G=x1R~353;u(Ck9c
T3OaEP#UVJ^Tm1GN)ex=iFYwYr

diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
index ab705e978..a28b93ada 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -998,9 +998,15 @@ local function create_vinyl_deferred_delete_space()
                   'blackhole', 0, {group_id = 1}, format}
 end
 
+local function create_default_collation_s2()
+    log.info("create predefined collation")
+    box.space._collation:replace{3, "unicode_s2", ADMIN, "ICU", "ru_RU", {strength='secondary'}}
+end
+
 local function upgrade_to_1_10_2()
     upgrade_priv_to_1_10_2()
     create_vinyl_deferred_delete_space()
+    create_default_collation_s2()
 end
 
 local function get_version()
diff --git a/test/box/collation.result b/test/box/collation.result
new file mode 100644
index 000000000..2dbb43c31
--- /dev/null
+++ b/test/box/collation.result
@@ -0,0 +1,160 @@
+env = require('test_run')
+---
+...
+test_run = env.new()
+---
+...
+--
+-- gh-4007 Feature request for a new collation
+--
+-- Ensure all default collations exist
+box.space._collation.index.name:get{'unicode'};
+---
+- [1, 'unicode', 1, 'ICU', '', {}]
+...
+box.space._collation.index.name:get{'unicode_ci'};
+---
+- [2, 'unicode_ci', 1, 'ICU', '', {'strength': 'primary'}]
+...
+box.space._collation.index.name:get{'unicode_s2'};
+---
+- [3, 'unicode_s2', 1, 'ICU', 'ru_RU', {'strength': 'secondary'}]
+...
+-- Default unicode collation deals with russian letters
+s = box.schema.space.create('t1');
+---
+...
+s:format({{name='s1', type='string', collation = 'unicode'}});
+---
+...
+s:create_index('pk', {unique = true, type='tree', parts={{'s1', collation = 'unicode'}}});
+---
+- unique: true
+  parts:
+  - type: string
+    is_nullable: false
+    collation: unicode
+    fieldno: 1
+  id: 0
+  space_id: 512
+  name: pk
+  type: TREE
+...
+s:insert{'Ё'};
+---
+- ['Ё']
+...
+s:insert{'Е'};
+---
+- ['Е']
+...
+s:insert{'ё'};
+---
+- ['ё']
+...
+s:insert{'е'};
+---
+- ['е']
+...
+-- all 4 letters are in the table
+s:select{};
+---
+- - ['е']
+  - ['Е']
+  - ['ё']
+  - ['Ё']
+...
+s:drop();
+---
+...
+-- unicode_ci collation doesn't distinguish russian letters 'Е' and 'Ё'
+s = box.schema.space.create('t1');
+---
+...
+s:format({{name='s1', type='string', collation = 'unicode_ci'}});
+---
+...
+s:create_index('pk', {unique = true, type='tree', parts={{'s1', collation = 'unicode_ci'}}});
+---
+- unique: true
+  parts:
+  - type: string
+    is_nullable: false
+    collation: unicode_ci
+    fieldno: 1
+  id: 0
+  space_id: 513
+  name: pk
+  type: TREE
+...
+s:insert{'Ё'};
+---
+- ['Ё']
+...
+-- the following calls should fail
+s:insert{'е'};
+---
+- error: Duplicate key exists in unique index 'pk' in space 't1'
+...
+s:insert{'Е'};
+---
+- error: Duplicate key exists in unique index 'pk' in space 't1'
+...
+s:insert{'ё'};
+---
+- error: Duplicate key exists in unique index 'pk' in space 't1'
+...
+-- return single 'Ё'
+s:select{};
+---
+- - ['Ё']
+...
+s:drop();
+---
+...
+-- unicode_s2 collation does distinguish russian letters 'Е' and 'Ё'
+s = box.schema.space.create('t1');
+---
+...
+s:format({{name='s1', type='string', collation = 'unicode_s2'}});
+---
+...
+s:create_index('pk', {unique = true, type='tree', parts={{'s1', collation = 'unicode_s2'}}});
+---
+- unique: true
+  parts:
+  - type: string
+    is_nullable: false
+    collation: unicode_s2
+    fieldno: 1
+  id: 0
+  space_id: 514
+  name: pk
+  type: TREE
+...
+s:insert{'Ё'};
+---
+- ['Ё']
+...
+s:insert{'е'};
+---
+- ['е']
+...
+-- the following calls should fail
+s:insert{'Е'};
+---
+- error: Duplicate key exists in unique index 'pk' in space 't1'
+...
+s:insert{'ё'};
+---
+- error: Duplicate key exists in unique index 'pk' in space 't1'
+...
+-- return two: 'Ё' and 'е'
+s:select{};
+---
+- - ['е']
+  - ['Ё']
+...
+s:drop();
+---
+...
diff --git a/test/box/collation.test.lua b/test/box/collation.test.lua
new file mode 100644
index 000000000..4cd24e64c
--- /dev/null
+++ b/test/box/collation.test.lua
@@ -0,0 +1,49 @@
+env = require('test_run')
+test_run = env.new()
+
+--
+-- gh-4007 Feature request for a new collation
+--
+-- Ensure all default collations exist
+box.space._collation.index.name:get{'unicode'};
+box.space._collation.index.name:get{'unicode_ci'};
+box.space._collation.index.name:get{'unicode_s2'};
+
+-- Default unicode collation deals with russian letters
+s = box.schema.space.create('t1');
+s:format({{name='s1', type='string', collation = 'unicode'}});
+s:create_index('pk', {unique = true, type='tree', parts={{'s1', collation = 'unicode'}}});
+s:insert{'Ё'};
+s:insert{'Е'};
+s:insert{'ё'};
+s:insert{'е'};
+-- all 4 letters are in the table
+s:select{};
+s:drop();
+
+-- unicode_ci collation doesn't distinguish russian letters 'Е' and 'Ё'
+s = box.schema.space.create('t1');
+s:format({{name='s1', type='string', collation = 'unicode_ci'}});
+s:create_index('pk', {unique = true, type='tree', parts={{'s1', collation = 'unicode_ci'}}});
+s:insert{'Ё'};
+-- the following calls should fail
+s:insert{'е'};
+s:insert{'Е'};
+s:insert{'ё'};
+-- return single 'Ё'
+s:select{};
+s:drop();
+
+-- unicode_s2 collation does distinguish russian letters 'Е' and 'Ё'
+s = box.schema.space.create('t1');
+s:format({{name='s1', type='string', collation = 'unicode_s2'}});
+s:create_index('pk', {unique = true, type='tree', parts={{'s1', collation = 'unicode_s2'}}});
+s:insert{'Ё'};
+s:insert{'е'};
+-- the following calls should fail
+s:insert{'Е'};
+s:insert{'ё'};
+-- return two: 'Ё' and 'е'
+s:select{};
+s:drop();
+
-- 
2.17.1

             reply	other threads:[~2019-02-22 11:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 11:49 Stanislav Zudin [this message]
2019-02-25 11:59 ` Vladimir Davydov
2019-02-25 12:07 ` Vladimir Davydov
2019-02-25 16:16   ` Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190222114939.21764-1-szudin@tarantool.org \
    --to=szudin@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] Feature request for a new collation' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox