[Tarantool-patches] [PATCH v3 5/9] box, datetime: messagepack support for datetime

Timur Safin tsafin at tarantool.org
Tue Aug 3 16:38:44 MSK 2021


After discussions with Sergey Petrenko I've realized
that there were several bugs in a way datetime was introduced
to fied_def.c, please see patch below...


> From: Timur Safin <tsafin at tarantool.org>
> Subject: [PATCH v3 5/9] box, datetime: messagepack support for datetime
> 
> Serialize datetime_t as newly introduced MP_EXT type.
> It saves 1 required integer field and upto 2 optional
> unsigned fields in very compact fashion.
> - secs is required field;
> - but nsec, offset are both optional;
> 
> * json, yaml serialization formats, lua output mode
>   supported;
> * exported symbols for datetime messagepack size calculations
>   so they are available for usage on Lua side.
> 
> Part of #5941
> Part of #5946


> 
> diff --git a/src/box/field_def.c b/src/box/field_def.c
> index 51acb8025..6964e3e9f 100644
> --- a/src/box/field_def.c
> +++ b/src/box/field_def.c
> @@ -67,11 +67,12 @@ const uint32_t field_mp_type[] = {
>  	/* [FIELD_TYPE_VARBINARY] =  */ 1U << MP_BIN,
>  	/* [FIELD_TYPE_SCALAR]   =  */ (1U << MP_UINT) | (1U << MP_INT) |
>  		(1U << MP_FLOAT) | (1U << MP_DOUBLE) | (1U << MP_STR) |
> -		(1U << MP_BIN) | (1U << MP_BOOL),
> +		(1U << MP_BIN) | (1U << MP_BOOL) | (1U << MP_DATETIME),
>  	/* [FIELD_TYPE_DECIMAL]  =  */ 0, /* only MP_DECIMAL is supported */
>  	/* [FIELD_TYPE_UUID]     =  */ 0, /* only MP_UUID is supported */
>  	/* [FIELD_TYPE_ARRAY]    =  */ 1U << MP_ARRAY,
>  	/* [FIELD_TYPE_MAP]      =  */ (1U << MP_MAP),
> +	/* [FIELD_TYPE_DATETIME] =  */ 0, /* only MP_DATETIME is supported */
>  };

Here datetime is in the incorrect definition: it's in field_mp_type[]
but should be in field_ext_type[] as bein MP_EXT type.

> 
>  const uint32_t field_ext_type[] = {
> @@ -88,6 +89,7 @@ const uint32_t field_ext_type[] = {
>  	/* [FIELD_TYPE_UUID]      = */ 1U << MP_UUID,
>  	/* [FIELD_TYPE_ARRAY]     = */ 0,
>  	/* [FIELD_TYPE_MAP]       = */ 0,
> +	/* [FIELD_TYPE_DATETIME]  = */ 1U << MP_DATETIME,
>  };
> 
>  const char *field_type_strs[] = {
> @@ -104,6 +106,7 @@ const char *field_type_strs[] = {
>  	/* [FIELD_TYPE_UUID]     = */ "uuid",
>  	/* [FIELD_TYPE_ARRAY]    = */ "array",
>  	/* [FIELD_TYPE_MAP]      = */ "map",
> +	/* [FIELD_TYPE_DATETIME] = */ "datetime",
>  };
> 
>  const char *on_conflict_action_strs[] = {
> @@ -128,20 +131,21 @@ field_type_by_name_wrapper(const char *str, uint32_t
> len)
>   * values can be stored in the j type.
>   */
>  static const bool field_type_compatibility[] = {
> -	   /*   ANY   UNSIGNED  STRING   NUMBER  DOUBLE  INTEGER  BOOLEAN
> VARBINARY SCALAR  DECIMAL   UUID    ARRAY    MAP  */
> -/*   ANY    */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  false,   false,   false,
> -/* UNSIGNED */ true,   true,    false,   true,    false,   true,    false,
> false,  true,   false,  false,   false,   false,
> -/*  STRING  */ true,   false,   true,    false,   false,   false,   false,
> false,  true,   false,  false,   false,   false,
> -/*  NUMBER  */ true,   false,   false,   true,    false,   false,   false,
> false,  true,   false,  false,   false,   false,
> -/*  DOUBLE  */ true,   false,   false,   true,    true,    false,   false,
> false,  true,   false,  false,   false,   false,
> -/*  INTEGER */ true,   false,   false,   true,    false,   true,    false,
> false,  true,   false,  false,   false,   false,
> -/*  BOOLEAN */ true,   false,   false,   false,   false,   false,   true,
> false,  true,   false,  false,   false,   false,
> -/* VARBINARY*/ true,   false,   false,   false,   false,   false,   false,
> true,   true,   false,  false,   false,   false,
> -/*  SCALAR  */ true,   false,   false,   false,   false,   false,   false,
> false,  true,   false,  false,   false,   false,
> -/*  DECIMAL */ true,   false,   false,   true,    false,   false,   false,
> false,  true,   true,   false,   false,   false,
> -/*   UUID   */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  true,    false,   false,
> -/*   ARRAY  */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  false,   true,    false,
> -/*    MAP   */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  false,   false,   true,
> +	   /*   ANY   UNSIGNED  STRING   NUMBER  DOUBLE  INTEGER  BOOLEAN
> VARBINARY SCALAR  DECIMAL   UUID    ARRAY    MAP     DATETIME */
> +/*   ANY    */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  false,   false,   false,   false,
> +/* UNSIGNED */ true,   true,    false,   true,    false,   true,    false,
> false,  true,   false,  false,   false,   false,   false,
> +/*  STRING  */ true,   false,   true,    false,   false,   false,   false,
> false,  true,   false,  false,   false,   false,   false,
> +/*  NUMBER  */ true,   false,   false,   true,    false,   false,   false,
> false,  true,   false,  false,   false,   false,   false,
> +/*  DOUBLE  */ true,   false,   false,   true,    true,    false,   false,
> false,  true,   false,  false,   false,   false,   false,
> +/*  INTEGER */ true,   false,   false,   true,    false,   true,    false,
> false,  true,   false,  false,   false,   false,   false,
> +/*  BOOLEAN */ true,   false,   false,   false,   false,   false,   true,
> false,  true,   false,  false,   false,   false,   false,
> +/* VARBINARY*/ true,   false,   false,   false,   false,   false,   false,
> true,   true,   false,  false,   false,   false,   false,
> +/*  SCALAR  */ true,   false,   false,   false,   false,   false,   false,
> false,  true,   false,  false,   false,   false,   false,
> +/*  DECIMAL */ true,   false,   false,   true,    false,   false,   false,
> false,  true,   true,   false,   false,   false,   false,
> +/*   UUID   */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  true,    false,   false,   false,
> +/*   ARRAY  */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  false,   true,    false,   false,
> +/*    MAP   */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  false,   false,   true,    false,
> +/* DATETIME */ true,   false,   false,   false,   false,   false,   false,
> false,  false,  false,  false,   false,   false,   true,
>  };

Also here we did not put datetime to the scalar column, while as 
being scalar type it should be possible to assign datetime values
to the scalar field. [Also we may pay attention to the fact that
uuid has the same problem - it will be investigated separately]

Here are changes we need to introduce to the code in patch:

------------------------------------------
diff --git a/src/box/field_def.c b/src/box/field_def.c
index 6964e3e9f..2682a42ee 100644
--- a/src/box/field_def.c
+++ b/src/box/field_def.c
@@ -67,7 +67,7 @@ const uint32_t field_mp_type[] = {
        /* [FIELD_TYPE_VARBINARY] =  */ 1U << MP_BIN,
        /* [FIELD_TYPE_SCALAR]   =  */ (1U << MP_UINT) | (1U << MP_INT) |
                (1U << MP_FLOAT) | (1U << MP_DOUBLE) | (1U << MP_STR) |
-               (1U << MP_BIN) | (1U << MP_BOOL) | (1U << MP_DATETIME),
+               (1U << MP_BIN) | (1U << MP_BOOL),
        /* [FIELD_TYPE_DECIMAL]  =  */ 0, /* only MP_DECIMAL is supported */
        /* [FIELD_TYPE_UUID]     =  */ 0, /* only MP_UUID is supported */
        /* [FIELD_TYPE_ARRAY]    =  */ 1U << MP_ARRAY,
@@ -84,7 +84,8 @@ const uint32_t field_ext_type[] = {
        /* [FIELD_TYPE_INTEGER]   = */ 0,
        /* [FIELD_TYPE_BOOLEAN]   = */ 0,
        /* [FIELD_TYPE_VARBINARY] = */ 0,
-       /* [FIELD_TYPE_SCALAR]    = */ (1U << MP_DECIMAL) | (1U << MP_UUID),
+       /* [FIELD_TYPE_SCALAR]    = */ (1U << MP_DECIMAL) | (1U << MP_UUID) |
+               (1U << MP_DATETIME),
        /* [FIELD_TYPE_DECIMAL]   = */ 1U << MP_DECIMAL,
        /* [FIELD_TYPE_UUID]      = */ 1U << MP_UUID,
        /* [FIELD_TYPE_ARRAY]     = */ 0,
@@ -145,7 +146,7 @@ static const bool field_type_compatibility[] = {
 /*   UUID   */ true,   false,   false,   false,   false,   false,   false,   false,  false,  false,  true,    false,   false,   false,
 /*   ARRAY  */ true,   false,   false,   false,   false,   false,   false,   false,  false,  false,  false,   true,    false,   false,
 /*    MAP   */ true,   false,   false,   false,   false,   false,   false,   false,  false,  false,  false,   false,   true,    false,
-/* DATETIME */ true,   false,   false,   false,   false,   false,   false,   false,  false,  false,  false,   false,   false,   true,
+/* DATETIME */ true,   false,   false,   false,   false,   false,   false,   false,  true,   false,  false,   false,   false,   true,
 };

 Bool
------------------------------------------

Will update patch to push it very soon.

Regards,
Timur



More information about the Tarantool-patches mailing list