[Tarantool-patches] [PATCH v1 2/2] sql: introduce syntax for MAP values

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Dec 1 01:04:47 MSK 2021


Thanks for the fixes!

On 25.11.2021 09:55, Mergen Imeev wrote:
> Thank you for the review! My answers, diff and new patch below. Also, I added
> changelog and tests to show that it is possible to create an empty MAP and a
> map with more than 1000 key-value pairs.
> 
> On Sat, Nov 20, 2021 at 01:46:57AM +0100, Vladislav Shpilevoy wrote:
>> Thanks for the patch!
>>
>> See 7 comments below.
>>
>>> diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
>>> index 74a98c550..789d8906c 100644
>>> --- a/src/box/sql/expr.c
>>> +++ b/src/box/sql/expr.c
>>> @@ -3432,6 +3432,35 @@ expr_code_array(struct Parse *parser, struct Expr *expr, int reg)
>>>  	sqlVdbeAddOp3(vdbe, OP_Array, count, reg, values_reg);
>>>  }
>>>  
>>> +static void
>>> +expr_code_map(struct Parse *parser, struct Expr *expr, int reg)
>>
>> 1. I thought the policy was that we name functions, generating VDBE code,
>> using 'emit' suffix. For instance, `vdbe_emit_map()` or `sql_emit_map()`.
>> Don't know about prefix though. I see both vdbe_ and sql_ are used.
>>
> This is usually true, but this function is actually part of sqlExprCodeTarget().
> I believe these functions were created to make sqlExprCodeTarget() more
> readable. All such functions are named sqlExprCode*(), code*() or
> expr_code _*(), for example: sqlExprCodeGetColumn(), codeReal(),
> expr_code_int().
> 
> Since all these functions are static, I think we should drop "expr_" prefix for
> them. Not in this patch, though.

If functions take Expr as an argument like these do, they could be
considered methods of Expr. In that case dropping the expr_ prefix would
violate our naming convention. It is not about static or global here.

As an alternative they could be considered as methods of Parse, but
then they would need to have parse_ prefix.

For 'code' vs 'emit' - 'code' is fine by me as long as it is static. But
if it goes public, then either 'code' or 'emit' must be chosen as one
correct suffix. Not a mix.

See 2 comments below.

> diff --git a/changelogs/unreleased/gh-4763-introduce-map-to-sql.md b/changelogs/unreleased/gh-4763-introduce-map-to-sql.md
> new file mode 100644
> index 000000000..013ec8f67
> --- /dev/null
> +++ b/changelogs/unreleased/gh-4763-introduce-map-to-sql.md
> @@ -0,0 +1,4 @@
> +## feature/core

1. I noticed just now - it should be feature/sql, not core. In
other patches, which are not yet submitted, too. If there are
any similar mistakes.

> +
> + * Field type MAP is now available in SQL. The syntax has also been implemented
> +   to allow the creation of MAP values (gh-4763).> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 32b8825bc..7411b8f67 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -3070,6 +3070,47 @@ mem_encode_array(const struct Mem *mems, uint32_t count, uint32_t *size,
>  	return array;
>  }
>  
> +char *
> +mem_encode_map(const struct Mem *mems, uint32_t count, uint32_t *size,
> +	       struct region *region)
> +{
> +	assert(count % 2 == 0);
> +	size_t used = region_used(region);
> +	bool is_error = false;
> +	struct mpstream stream;
> +	mpstream_init(&stream, region, region_reserve_cb, region_alloc_cb,
> +		      set_encode_error, &is_error);
> +	mpstream_encode_map(&stream, (count + 1) / 2);
> +	for (uint32_t i = 0; i < count / 2; ++i) {
> +		const struct Mem *key = &mems[2 * i];
> +		const struct Mem *value = &mems[2 * i + 1];
> +		if (mem_is_metatype(key) ||
> +		    (key->type & (MEM_TYPE_UINT | MEM_TYPE_INT | MEM_TYPE_UUID |
> +				  MEM_TYPE_STR)) == 0) {

2. Missed region truncate here. Looks like it would be easier to
add an 'error:' label in the end of the function to do the truncate
and return NULL.

> +			diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
> +				 mem_str(key), "integer, string or uuid");
> +			return NULL;
> +		}


More information about the Tarantool-patches mailing list