[Tarantool-patches] [PATCH 1/1] box: make UUID part of SCALAR

imeevma at tarantool.org imeevma at tarantool.org
Fri Apr 23 14:40:42 MSK 2021


Prior to this patch, UUID was not part of SCALAR. However, this should
be changed to comply with the RFC "Consistent Lua/SQL types".

Closes #6042

@TarantoolBot document
Title: UUID is now part of SCALAR

The UUID field type is now part of the SCALAR field type. This means
that now values of type UUID can be inserted into the SCALAR field, and
these values can participate in the sorting of the SCALAR fields. The
order is as follows: boolean < number < string < varbinary < uuid.
---
https://github.com/tarantool/tarantool/issues/6042
https://github.com/tarantool/tarantool/tree/imeevma/gh-6042-make-uuid-part-of-scalar

 .../unreleased/make-uuid-part-of-scalar.md    |  3 ++
 src/box/field_def.c                           |  2 +-
 src/box/tuple_compare.cc                      |  2 +
 test/app/uuid.result                          | 46 +++++++++++++++++++
 test/app/uuid.test.lua                        | 18 ++++++++
 test/engine/ddl.result                        |  4 +-
 test/engine/ddl.test.lua                      |  2 +-
 7 files changed, 72 insertions(+), 5 deletions(-)
 create mode 100644 changelogs/unreleased/make-uuid-part-of-scalar.md

diff --git a/changelogs/unreleased/make-uuid-part-of-scalar.md b/changelogs/unreleased/make-uuid-part-of-scalar.md
new file mode 100644
index 000000000..eeead4ffb
--- /dev/null
+++ b/changelogs/unreleased/make-uuid-part-of-scalar.md
@@ -0,0 +1,3 @@
+## feature/core
+
+ * Field type UUID is now part of field type SCALAR (gh-6042).
diff --git a/src/box/field_def.c b/src/box/field_def.c
index 213e91699..51acb8025 100644
--- a/src/box/field_def.c
+++ b/src/box/field_def.c
@@ -83,7 +83,7 @@ const uint32_t field_ext_type[] = {
 	/* [FIELD_TYPE_INTEGER]   = */ 0,
 	/* [FIELD_TYPE_BOOLEAN]   = */ 0,
 	/* [FIELD_TYPE_VARBINARY] = */ 0,
-	/* [FIELD_TYPE_SCALAR]    = */ 1U << MP_DECIMAL,
+	/* [FIELD_TYPE_SCALAR]    = */ (1U << MP_DECIMAL) | (1U << MP_UUID),
 	/* [FIELD_TYPE_DECIMAL]   = */ 1U << MP_DECIMAL,
 	/* [FIELD_TYPE_UUID]      = */ 1U << MP_UUID,
 	/* [FIELD_TYPE_ARRAY]     = */ 0,
diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc
index 0946d77f8..3ae1dcc8f 100644
--- a/src/box/tuple_compare.cc
+++ b/src/box/tuple_compare.cc
@@ -1790,6 +1790,8 @@ field_hint_scalar(const char *field, struct coll *coll)
 			decimal_t dec;
 			return hint_decimal(decimal_unpack(&field, len, &dec));
 		}
+		case MP_UUID:
+			return hint_uuid_raw(field);
 		default:
 			unreachable();
 		}
diff --git a/test/app/uuid.result b/test/app/uuid.result
index b4870302e..6b22b1d2c 100644
--- a/test/app/uuid.result
+++ b/test/app/uuid.result
@@ -443,6 +443,52 @@ u1_str = nil
 u2_str = nil
 ---
 ...
+--
+-- gh-6042: add UUID to SCALAR.
+--
+s = box.schema.space.create('s', {format={{'s', 'scalar'}}})
+---
+...
+_ = s:create_index('i')
+---
+...
+s:insert({1})
+---
+- [1]
+...
+s:insert({'1'})
+---
+- ['1']
+...
+s:insert({uuid.fromstr('11111111-1111-1111-1111-111111111111')})
+---
+- [11111111-1111-1111-1111-111111111111]
+...
+s:insert({uuid.fromstr('11111111-1111-2222-1111-111111111111')})
+---
+- [11111111-1111-2222-1111-111111111111]
+...
+--
+-- Make sure that comparison in right. Comparison in SCALAR field:
+-- bool < number < string < varbinary < uuid.
+--
+s:select()
+---
+- - [1]
+  - ['1']
+  - [11111111-1111-1111-1111-111111111111]
+  - [11111111-1111-2222-1111-111111111111]
+...
+s:select({}, {iterator='LE'})
+---
+- - [11111111-1111-2222-1111-111111111111]
+  - [11111111-1111-1111-1111-111111111111]
+  - ['1']
+  - [1]
+...
+s:drop()
+---
+...
 uuid = nil
 ---
 ...
diff --git a/test/app/uuid.test.lua b/test/app/uuid.test.lua
index 867bbd832..7c0942fd6 100644
--- a/test/app/uuid.test.lua
+++ b/test/app/uuid.test.lua
@@ -164,6 +164,24 @@ u1 = nil
 u1_str = nil
 u2_str = nil
 
+--
+-- gh-6042: add UUID to SCALAR.
+--
+s = box.schema.space.create('s', {format={{'s', 'scalar'}}})
+_ = s:create_index('i')
+s:insert({1})
+s:insert({'1'})
+s:insert({uuid.fromstr('11111111-1111-1111-1111-111111111111')})
+s:insert({uuid.fromstr('11111111-1111-2222-1111-111111111111')})
+
+--
+-- Make sure that comparison in right. Comparison in SCALAR field:
+-- bool < number < string < varbinary < uuid.
+--
+s:select()
+s:select({}, {iterator='LE'})
+s:drop()
+
 uuid = nil
 
 test_run:cmd("clear filter")
diff --git a/test/engine/ddl.result b/test/engine/ddl.result
index 08ad1a57b..e044bc094 100644
--- a/test/engine/ddl.result
+++ b/test/engine/ddl.result
@@ -1429,10 +1429,8 @@ fail_format_change(12, 'number')
   number, got extension'
 ...
 -- uuid --X--> scalar
-fail_format_change(12, 'scalar')
+ok_format_change(12, 'scalar')
 ---
-- 'Tuple field 12 (field12) type does not match one required by operation: expected
-  scalar, got extension'
 ...
 -- uuid --X--> string
 fail_format_change(12, 'string')
diff --git a/test/engine/ddl.test.lua b/test/engine/ddl.test.lua
index 5ba80e075..0cf25aa46 100644
--- a/test/engine/ddl.test.lua
+++ b/test/engine/ddl.test.lua
@@ -523,7 +523,7 @@ ok_format_change(12, 'any')
 -- uuid --X--> number
 fail_format_change(12, 'number')
 -- uuid --X--> scalar
-fail_format_change(12, 'scalar')
+ok_format_change(12, 'scalar')
 -- uuid --X--> string
 fail_format_change(12, 'string')
 -- uuid --X--> integer
-- 
2.25.1



More information about the Tarantool-patches mailing list