Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Roman Khabibov <roman.habibov@tarantool.org>,
	tarantool-patches@freelists.org,
	"n.pettik" <korablev@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 2/2] sql: allow <COLLATE> only for string-like args
Date: Tue, 4 Jun 2019 21:49:07 +0200	[thread overview]
Message-ID: <545e9807-0558-8ce2-cacf-b96eac63e0d1@tarantool.org> (raw)
In-Reply-To: <B0FB2003-4CB7-4514-9AF7-7B97C36A77F3@tarantool.org>

Hi!

tarantool> box.execute('SELECT TRUE AND TRUE COLLATE "binary";')
---
- metadata:
  - name: TRUE AND TRUE COLLATE "binary"
    type: boolean
  rows:
  - [true]
...

Your previous solution was correct, you should check collation
in CodeTemp. But somewhy you decided to remove it and keep only
in 'TK_NOT' and 'TK_COLLATE'. Obviously, you can't add the check
to each 'case' in that 'switch', and you need to check the collation
for every token.

Besides, Nikita, please, help us with the next comment.

On 04/06/2019 17:27, Roman Khabibov wrote:
> Hello, thanks for the review.
> 
>> On Jun 2, 2019, at 8:09 PM, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
>>
>> Thanks for the fixes! See 8 comments below.
>>
>>>>> diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
>>>>> index ba7eea59d..29e3386fa 100644
>>>>> --- a/src/box/sql/expr.c
>>>>> +++ b/src/box/sql/expr.c
>>>>> @@ -4215,6 +4215,22 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
>>>>> 		}
>>>>> 	case TK_SPAN:
>>>>> 	case TK_COLLATE:{
>>>>> +			enum field_type type;
>>>>> +			struct Expr *left = pExpr->pLeft;
>>>>> +			if (left->op == TK_COLUMN) {
>>>>> +				int col_num = left->iColumn;
>>>>> +				type = left->space_def->fields[col_num].type;
>>>>> +			} else
>>>>> +				type = left->type;
>>>>> +			if (left->op != TK_CONCAT &&
>>>>
>>>> Why do you check for TK_CONCAT? Its type should be FIELD_TYPE_STRING.
>>> Concatenations are rejected without this check.
>>
>> 1. It is not a good answer, when you can't explain, why you need
>> a line of code, but a program does not work without it. Please, investigate
>> and explain, why do you check for both 'type == STRING' and 'op == CONCAT'.
>> If an op is CONCAT, then type is already STRING, so the additional check
>> for 'op' should not be necessary.
> @@ -1060,6 +1094,8 @@ sqlPExpr(Parse * pParse,	/* Parsing context */
>  		if (p) {
>  			memset(p, 0, sizeof(Expr));
>  			p->op = op & TKFLG_MASK;
> +			if (op == TK_CONCAT)
> +				p->type = FIELD_TYPE_STRING;
>  			p->iAgg = -1;
>  		}
>  		sqlExprAttachSubtrees(pParse->db, p, pLeft, pRight);
> 

I am 100% sure, that it is not a place for types setting. This
function, and its comment says, only allocates. For complex types
we have sql_expr_type(), we can use Expr.type for basic types
located in tree lists only.

Nikita knows more about typing, he can help better.

  reply	other threads:[~2019-06-04 19:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 11:29 [tarantool-patches] [PATCH 0/2] " Roman Khabibov
2019-05-08 11:29 ` [tarantool-patches] [PATCH 1/2] sql: fix collation node duplication in AST Roman Khabibov
2019-05-12 16:32   ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-28 14:10     ` Roman Khabibov
2019-06-02 17:09       ` Vladislav Shpilevoy
2019-06-04 14:00         ` Roman Khabibov
2019-05-08 11:29 ` [tarantool-patches] [PATCH 2/2] sql: allow <COLLATE> only for string-like args Roman Khabibov
2019-05-12 16:32   ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-28 14:08     ` Roman Khabibov
2019-06-02 17:09       ` Vladislav Shpilevoy
2019-06-04 14:27         ` Roman Khabibov
2019-06-04 19:49           ` Vladislav Shpilevoy [this message]
2019-06-07 15:01             ` Roman Khabibov
2019-06-09 16:55               ` Vladislav Shpilevoy

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=545e9807-0558-8ce2-cacf-b96eac63e0d1@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 2/2] sql: allow <COLLATE> only for string-like args' \
    /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