From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp41.i.mail.ru (smtp41.i.mail.ru [94.100.177.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 8C56A469710 for ; Wed, 25 Nov 2020 01:06:15 +0300 (MSK) From: "Timur Safin" References: <0b1d01d6b9a4$aecaf500$0c60df00$@tarantool.org> In-Reply-To: <0b1d01d6b9a4$aecaf500$0c60df00$@tarantool.org> Date: Wed, 25 Nov 2020 01:06:13 +0300 Message-ID: <07e101d6c2ae$0607c980$12175c80$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Content-Language: ru Subject: Re: [Tarantool-discussions] RFC - distributed SQL, step #1 - AST List-Id: Tarantool development process List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mons@tarantool.org, 'Kirill Yukhin' , 'korablev' , 'Vladislav Shpilevoy' , 'Sergey Ostanevich' , Alexander Turenko Cc: m.semkin@corp.mail.ru, tarantool-discussions@dev.tarantool.org First I need to update those who was not involved in our internal=20 discussions - idea to serialize to SQL for sending commands to=20 data nodes have been rejected, and we go full steam with normal AST way: - create AST for SQL query; - serialize it/deserialize once we are about to transfer it elsewhere; - There were doubts about complexities of implementing AST for=20 statements beyond currently implemented SELECT/VIEW and triggers. But more experienced colleagues believe that it will be easy to create AST for them also, so we will try to implement it also. Also, Mons wanted to look into code examples how AST manipulations will look like, so please see additional appendix created.=20 Exporting AST as cdata is easy to do, but in this case it will be=20 inconvenient to manipulate AST nodes, before sending to cluster nodes. So there is 2nd, more idiomatic approach suggested - to convert AST to nested Lua object/tables. Which should simplify some massaging and provide natural way to serialization to msgpack. Appendix B - programmatic interfaces ------------------------------------ SYNOPSIS ~~~~~~~~ .. code-block:: lua local sql =3D require `sqlparser` -- parse, return ast, pass it back unmodified for execution local ast =3D sql.parse [[ select * from "table" where id > 10 limit = 10 ]] assert(type(ast) =3D=3D 'cdata') local ok =3D sql.execute(ast) -- free allocated memory, like box.unprepare but for ast sql.unparse(ast) -- raw access to cdata structures local cdata =3D ast.as_cdata() if cdata.ast_type =3D=3D ffi.C.AST_TYPE_SELECT handle_select_stmt(cdata.select) end -- Lua access to structurs as Lua tables local tree =3D ast.as_table() if tree.type =3D=3D AST_TYPE_SELECT handle_columns_list(tree.select.columns) handle_where_clause(tree.select.where) limit =3D tree.select.limit end -- massaging with tree data -- serialization local msgpack =3D require 'msgpack' local to_wire =3D msgpack.encode(tree) -- networking magics ... -- ... deserialization local table =3D msgpack.decode(from_wire) ast.set_tree(tree) sql.execute(ast) Regards, Timur P.S. Sorry for top-post... : From: Tarantool-discussions