box: introduce Lua persistent functions
Closes #4182 Closes #4219 Needed for #1260 @TarantoolBot document Title: Persistent Lua functions Now Tarantool supports 'persistent' Lua functions. Such functions are stored in snapshot and are available after restart. To create a persistent Lua function, specify a function body in box.schema.func.create call: e.g. body = "function(a, b) return a + b end" A Lua persistent function may be 'sandboxed'. The 'sandboxed' function is executed in isolated environment: a. only limited set of Lua functions and modules are available: -assert -error -pairs -ipairs -next -pcall -xpcall -type -print -select -string -tonumber -tostring -unpack -math -utf8; b. global variables are forbidden Finally, the new 'is_deterministic' flag allows to mark a registered function as deterministic, i.e. the function that can produce only one result for a given list of parameters. The new box.schema.func.create interface is: box.schema.func.create('funcname', <setuid = true|FALSE>, <if_not_exists = true|FALSE>, <language = LUA|c>, <body = string ('')>, <is_deterministic = true|FALSE>, <is_sandboxed = true|FALSE>, <comment = string ('')>) This schema change is also reserves names for sql builtin functions: TRIM, TYPEOF, PRINTF, UNICODE, CHAR, HEX, VERSION, QUOTE, REPLACE, SUBSTR, GROUP_CONCAT, JULIANDAY, DATE, TIME, DATETIME, STRFTIME, CURRENT_TIME, CURRENT_TIMESTAMP, CURRENT_DATE, LENGTH, POSITION, ROUND, UPPER, LOWER, IFNULL, RANDOM, CEIL, CEILING, CHARACTER_LENGTH, CHAR_LENGTH, FLOOR, MOD, OCTET_LENGTH, ROW_COUNT, COUNT, LIKE, ABS, EXP, LN, POWER, SQRT, SUM, TOTAL, AVG, RANDOMBLOB, NULLIF, ZEROBLOB, MIN, MAX, COALESCE, EVERY, EXISTS, EXTRACT, SOME, GREATER, LESSER, SOUNDEX, LIKELIHOOD, LIKELY, UNLIKELY, _sql_stat_get, _sql_stat_push, _sql_stat_init, LUA A new Lua persistent function LUA is introduced to evaluate LUA strings from SQL in future. This names could not be used for user-defined functions. Example: lua_code = [[function(a, b) return a + b end]] box.schema.func.create('summarize', {body = lua_code, is_deterministic = true, is_sandboxed = true}) box.func.summarize --- - aggregate: none returns: any exports: lua: true sql: false id: 60 is_sandboxed: true setuid: false is_deterministic: true body: function(a, b) return a + b end name: summarize language: LUA ... box.func.summarize:call({1, 3}) --- - 4 ... @kostja: fix style, remove unnecessary module dependencies, add comments
Showing
- src/box/alter.cc 142 additions, 14 deletionssrc/box/alter.cc
- src/box/bootstrap. 0 additions, 0 deletionssrc/box/bootstrap.
- src/box/bootstrap.snap 0 additions, 0 deletionssrc/box/bootstrap.snap
- src/box/func.c 50 additions, 4 deletionssrc/box/func.c
- src/box/func_def.c 87 additions, 1 deletionsrc/box/func_def.c
- src/box/func_def.h 60 additions, 3 deletionssrc/box/func_def.h
- src/box/lua/call.c 243 additions, 2 deletionssrc/box/lua/call.c
- src/box/lua/schema.lua 16 additions, 3 deletionssrc/box/lua/schema.lua
- src/box/lua/upgrade.lua 67 additions, 1 deletionsrc/box/lua/upgrade.lua
- src/box/schema_def.h 14 additions, 0 deletionssrc/box/schema_def.h
- test-run 1 addition, 1 deletiontest-run
- test/box-py/bootstrap.result 76 additions, 4 deletionstest/box-py/bootstrap.result
- test/box-py/bootstrap.test.py 1 addition, 1 deletiontest/box-py/bootstrap.test.py
- test/box/access.result 1 addition, 1 deletiontest/box/access.result
- test/box/access.test.lua 1 addition, 1 deletiontest/box/access.test.lua
- test/box/access_bin.result 1 addition, 1 deletiontest/box/access_bin.result
- test/box/access_bin.test.lua 1 addition, 1 deletiontest/box/access_bin.test.lua
- test/box/access_misc.result 139 additions, 2 deletionstest/box/access_misc.result
- test/box/access_sysview.result 4 additions, 4 deletionstest/box/access_sysview.result
- test/box/alter.result 1 addition, 1 deletiontest/box/alter.result
Loading
Please register or sign in to comment