Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Timur Safin <tsafin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 4/4] sql: make type mismatch errors more informative
Date: Tue, 13 Jul 2021 13:17:22 +0300	[thread overview]
Message-ID: <ac63fca9-841b-3b9c-8cab-15adc88eccf8@tarantool.org> (raw)
In-Reply-To: <03f701d777c4$47a28e90$d6e7abb0$@tarantool.org>

Hi! Thank you for the review! My answer below.

On 13.07.2021 11:51, Timur Safin wrote:
> This is so much clearer now!
> LGTM (though there is some minor complain)
>
> : From: imeevma@tarantool.org <imeevma@tarantool.org>
> : Subject: [PATCH v2 4/4] sql: make type mismatch errors more informative
> :
> ...
>
> : diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> : index c4375e1ea..cdb55f858 100644
> : --- a/src/box/sql/mem.c
> : +++ b/src/box/sql/mem.c
> : @@ -78,16 +78,17 @@ mem_str(const struct Mem *mem)
> :  	case MEM_TYPE_NULL:
> :  		return "NULL";
> :  	case MEM_TYPE_STR:
> : -		if (mem->n > STR_VALUE_MAX_LEN)
> : -			return tt_sprintf("'%.*s...", STR_VALUE_MAX_LEN, mem->z);
> : -		return tt_sprintf("'%.*s'", mem->n, mem->z);
> : +		if (mem->n <= STR_VALUE_MAX_LEN)
> : +			return tt_sprintf("string('%.*s')", mem->n, mem->z);
> : +		return tt_sprintf("string('%.*s...)", STR_VALUE_MAX_LEN,
> : +				  mem->z);
>
> Hmm, hmm, see my notice below.
>
> :  	case MEM_TYPE_INT:
> : -		return tt_sprintf("%lld", mem->u.i);
> : +		return tt_sprintf("integer(%lld)", mem->u.i);
> :  	case MEM_TYPE_UINT:
> : -		return tt_sprintf("%llu", mem->u.u);
> : +		return tt_sprintf("integer(%llu)", mem->u.u);
> :  	case MEM_TYPE_DOUBLE:
> :  		sql_snprintf(STR_VALUE_MAX_LEN, buf, "%!.15g", mem->u.r);
> : -		return tt_sprintf("%s", buf);
> : +		return tt_sprintf("double(%s)", buf);
> :  	case MEM_TYPE_BIN: {
> :  		int len = MIN(mem->n, STR_VALUE_MAX_LEN / 2);
> :  		for (int i = 0; i < len; ++i) {
> : @@ -97,22 +98,25 @@ mem_str(const struct Mem *mem)
> :  			buf[2 * i + 1] = n < 10 ? ('0' + n) : ('A' + n - 10);
> :  		}
> :  		if (mem->n > len)
> : -			return tt_sprintf("x'%.*s...", len * 2, buf);
> : -		return tt_sprintf("x'%.*s'", len * 2, buf);
> : +			return tt_sprintf("varbinary(x'%.*s...)", len * 2, buf);
> : +		return tt_sprintf("varbinary(x'%.*s')", len * 2, buf);
>
> As for me it makes no much sense to generate not properly quoted
> literal even if we mean that it's shortened and truncated. IMVHO
>
> Though there is no single proper form, because it's simple message,
> and customer will probably get the reason why it looks so.

My answer from previous review:

I believe that "'" is actually part of value. This way we will get inconsistent
value in case only part of it was printed. This is similar for what we do with
array - in case it is too long we will not close it using "]".


Also, it can be confusing because the quoted value with '...' is actually a
valid STRING, however it may or may not be the same as the original 
value. If we
don't add "" at the end, there will be no misunderstanding.

> :  	}
> :  	case MEM_TYPE_MAP:
> :  	case MEM_TYPE_ARRAY: {
> :  		const char *str = mp_str(mem->z);
> : -		if (strlen(str) <= STR_VALUE_MAX_LEN)
> : -			return str;
> : -		memcpy(buf, str, STR_VALUE_MAX_LEN);
> : -		return tt_sprintf("%.*s...", STR_VALUE_MAX_LEN, buf);
> : +		const char *type = mem_type_to_str(mem);
> : +		uint32_t len = strlen(str);
> : +		uint32_t minlen = MIN(STR_VALUE_MAX_LEN, len);
> : +		memcpy(buf, str, minlen);
> : +		if (len <= STR_VALUE_MAX_LEN)
> : +			return tt_sprintf("%s(%.*s)", type, minlen, buf);
> : +		return tt_sprintf("%s(%.*s...)", type, minlen, buf);
>
>
> :  	}
> :  	case MEM_TYPE_UUID:
> :  		tt_uuid_to_string(&mem->u.uuid, buf);
> : -		return tt_sprintf("'%s'", buf);
> : +		return tt_sprintf("uuid('%s')", buf);
> :  	case MEM_TYPE_BOOL:
> : -		return mem->u.b ? "TRUE" : "FALSE";
> : +		return mem->u.b ? "boolean(TRUE)" : "boolean(FALSE)";
> :  	default:
> :  		return "unknown";
> :  	}
>
> Regards,
> Timur
>

      reply	other threads:[~2021-07-13 10:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13  7:03 [Tarantool-patches] [PATCH v2 0/4] sql: fix description of type mismatch errors Mergen Imeev via Tarantool-patches
2021-07-13  7:03 ` [Tarantool-patches] [PATCH v2 1/4] sql: truncate values in type mismatch error Mergen Imeev via Tarantool-patches
2021-07-13  8:51   ` Timur Safin via Tarantool-patches
2021-07-13  7:03 ` [Tarantool-patches] [PATCH v2 2/4] sql: properly show " Mergen Imeev via Tarantool-patches
2021-07-13  8:51   ` Timur Safin via Tarantool-patches
2021-07-13  7:03 ` [Tarantool-patches] [PATCH v2 3/4] sql: use proper type names in error descriptions Mergen Imeev via Tarantool-patches
2021-07-13  8:51   ` Timur Safin via Tarantool-patches
2021-07-13  7:04 ` [Tarantool-patches] [PATCH v2 4/4] sql: make type mismatch errors more informative Mergen Imeev via Tarantool-patches
2021-07-13  8:51   ` Timur Safin via Tarantool-patches
2021-07-13 10:17     ` Mergen Imeev via Tarantool-patches [this message]

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=ac63fca9-841b-3b9c-8cab-15adc88eccf8@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 4/4] sql: make type mismatch errors more informative' \
    /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