Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] sql: set names for constant fields within VIEW
@ 2018-12-03 22:03 Nikita Pettik
       [not found] ` <2d3f83eb-b9db-23c8-b57e-cd79c954cae2@tarantool.org>
  2018-12-14  5:15 ` Kirill Yukhin
  0 siblings, 2 replies; 4+ messages in thread
From: Nikita Pettik @ 2018-12-03 22:03 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, 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 generate names for all fields which lack names for VIEW.

Closes #3849
---
Branch: https://github.com/tarantool/tarantool/commits/np/gh-3849-view-constant-value-v2
Issue: https://github.com/tarantool/tarantool/issues/3849

 src/box/sql/select.c   |  4 ++--
 test/sql/view.result   | 26 ++++++++++++++++++++++++++
 test/sql/view.test.lua | 11 +++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index ca709b44f..839224131 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1871,6 +1871,8 @@ sqlite3ColumnsFromExprList(Parse * parse, ExprList * expr_list, Table *table)
 				zName = expr_list->a[i].zSpan;
 			}
 		}
+		if (zName == NULL)
+			zName = "__auto-fld";
 		zName = sqlite3MPrintf(db, "%s", zName);
 
 		/* Make sure the column name is unique.  If the name is not unique,
@@ -1888,8 +1890,6 @@ sqlite3ColumnsFromExprList(Parse * parse, ExprList * expr_list, Table *table)
 			}
 			zName =
 			    sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
-			if (cnt > 3)
-				sqlite3_randomness(sizeof(cnt), &cnt);
 		}
 		size_t name_len = strlen(zName);
 		void *field = &table->def->fields[i];
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..489eb4862 100644
--- a/test/sql/view.test.lua
+++ b/test/sql/view.test.lua
@@ -65,6 +65,17 @@ 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-14  5:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 22:03 [tarantool-patches] [PATCH] sql: set names for constant fields within VIEW Nikita Pettik
     [not found] ` <2d3f83eb-b9db-23c8-b57e-cd79c954cae2@tarantool.org>
2018-12-07 15:02   ` [tarantool-patches] " n.pettik
2018-12-08 12:18     ` Vladislav Shpilevoy
2018-12-14  5:15 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox