From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 726552DB7E for ; Mon, 3 Dec 2018 17:02:24 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9KN415Pw7xqm for ; Mon, 3 Dec 2018 17:02:24 -0500 (EST) Received: from smtp1.mail.ru (smtp1.mail.ru [94.100.179.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 2B7E02DB7D for ; Mon, 3 Dec 2018 17:02:24 -0500 (EST) From: Nikita Pettik Subject: [tarantool-patches] [PATCH] sql: set name for expressions in the list in form of VALUES(...) Date: Tue, 4 Dec 2018 01:02:14 +0300 Message-Id: <20181203220214.81783-1-korablev@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Nikita Pettik If VIEW contains constant fields (e.g. CREATE VIEW v AS SELECT 1, 'k';) it uses string representation of literal as a field name. In the example above it would be '1' and 'k'. However, if VIEW is created using AS VALUES syntax, then expressions representing constant literals lack of names (since span-expression is not assigned in this case). Lets patch parser to avoid such defect. Closes #3849 --- Note that this is first variant of fixing #3849 isssue. The second one is going to be send as a separate patch as well. They are both equal and fixing problem. Branch: https://github.com/tarantool/tarantool/commits/np/gh-3849-view-constant-value-v1 Issue: https://github.com/tarantool/tarantool/issues/3849 src/box/sql/parse.y | 12 ++++++++---- test/sql/view.result | 26 ++++++++++++++++++++++++++ test/sql/view.test.lua | 12 ++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index 6dfc81f70..bca2daf03 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -1194,10 +1194,14 @@ case_operand(A) ::= . {A = 0;} exprlist(A) ::= nexprlist(A). exprlist(A) ::= . {A = 0;} -nexprlist(A) ::= nexprlist(A) COMMA expr(Y). - {A = sql_expr_list_append(pParse->db,A,Y.pExpr);} -nexprlist(A) ::= expr(Y). - {A = sql_expr_list_append(pParse->db,NULL,Y.pExpr); /*A-overwrites-Y*/} +nexprlist(A) ::= nexprlist(A) COMMA expr(Y). { + A = sql_expr_list_append(pParse->db,A,Y.pExpr); + sqlite3ExprListSetSpan(pParse, A, &Y); +} +nexprlist(A) ::= expr(Y). { + A = sql_expr_list_append(pParse->db,NULL,Y.pExpr); + sqlite3ExprListSetSpan(pParse, A, &Y); +} /* A paren_exprlist is an optional expression list contained inside ** of parenthesis */ diff --git a/test/sql/view.result b/test/sql/view.result index b211bcb2e..818227741 100644 --- a/test/sql/view.result +++ b/test/sql/view.result @@ -148,6 +148,32 @@ box.sql.execute("DROP VIEW v2;"); box.sql.execute("DROP TABLE t2;"); --- ... +-- gh-3849: failed to create VIEW in form of AS VALUES (const); +-- +box.sql.execute("CREATE VIEW cv AS VALUES(1);") +--- +... +box.sql.execute("CREATE VIEW cv1 AS VALUES('k', 1);") +--- +... +box.sql.execute("CREATE VIEW cv2 AS VALUES((VALUES((SELECT 1))));") +--- +... +box.sql.execute("CREATE VIEW cv3 AS VALUES(1+2, 1+2);") +--- +... +box.sql.execute("DROP VIEW cv;") +--- +... +box.sql.execute("DROP VIEW cv1;") +--- +... +box.sql.execute("DROP VIEW cv2;") +--- +... +box.sql.execute("DROP VIEW cv3;") +--- +... -- Cleanup box.sql.execute("DROP VIEW v1;"); --- diff --git a/test/sql/view.test.lua b/test/sql/view.test.lua index a6269a1bf..3b6f2aebe 100644 --- a/test/sql/view.test.lua +++ b/test/sql/view.test.lua @@ -65,6 +65,18 @@ box.sql.execute("DROP TABLE t2;"); box.sql.execute("DROP VIEW v2;"); box.sql.execute("DROP TABLE t2;"); +-- gh-3849: failed to create VIEW in form of AS VALUES (const); +-- +box.sql.execute("CREATE VIEW cv AS VALUES(1);") +box.sql.execute("CREATE VIEW cv1 AS VALUES('k', 1);") +box.sql.execute("CREATE VIEW cv2 AS VALUES((VALUES((SELECT 1))));") +box.sql.execute("CREATE VIEW cv3 AS VALUES(1+2, 1+2);") + +box.sql.execute("DROP VIEW cv;") +box.sql.execute("DROP VIEW cv1;") +box.sql.execute("DROP VIEW cv2;") +box.sql.execute("DROP VIEW cv3;") + -- Cleanup box.sql.execute("DROP VIEW v1;"); box.sql.execute("DROP TABLE t1;"); -- 2.15.1