1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
|
build_path = os.getenv("BUILDDIR")
---
...
package.cpath = build_path..'/test/box/?.so;'..build_path..'/test/box/?.dylib;'..package.cpath
---
...
log = require('log')
---
...
net = require('net.box')
---
...
c = net.connect(os.getenv("LISTEN"))
---
...
box.schema.func.create('function1', {language = "C"})
---
...
id = box.func["function1"].id
---
...
function setmap(tab) return setmetatable(tab, { __serialize = 'map' }) end
---
...
datetime = os.date("%Y-%m-%d %H:%M:%S")
---
...
box.space._func:replace{id, 1, 'function1', 0, 'LUA', '', 'procedure', {}, 'any', 'none', 'none', false, false, true, {"LUA"}, setmap({}), '', datetime, datetime}
---
- error: 'Failed to create function ''function1'': unsupported routine_type value'
...
box.space._func:replace{id, 1, 'function1', 0, 'LUA', '', 'function', {}, 'any', 'none', 'reads', false, false, true, {"LUA"}, setmap({}), '', datetime, datetime}
---
- error: 'Failed to create function ''function1'': unsupported sql_data_access value'
...
box.space._func:replace{id, 1, 'function1', 0, 'LUA', '', 'function', {}, 'any', 'none', 'none', false, false, false, {"LUA"}, setmap({}), '', datetime, datetime}
---
- error: 'Failed to create function ''function1'': unsupported is_null_call value'
...
box.space._func:replace{id, 1, 'function1', 0, 'LUA', '', 'function', {}, 'data', 'none', 'none', false, false, true, {"LUA"}, setmap({}), '', datetime, datetime}
---
- error: 'Failed to create function ''function1'': invalid returns value'
...
box.space._func:replace{id, 1, 'function1', 0, 'LUA', '', 'function', {}, 'any', 'none', 'none', false, false, true, {"LUA", "C"}, setmap({}), '', datetime, datetime}
---
- error: 'Failed to create function ''function1'': invalid exports value'
...
box.space._func:replace{id, 1, 'function1', 0, 'LUA', '', 'function', {}, 'any', 'aggregate', 'none', false, false, true, {"LUA"}, setmap({}), '', datetime, datetime}
---
- error: 'Failed to create function ''function1'': invalid aggregate value'
...
box.space._func:replace{id, 1, 'function1', 0, 'LUA', '', 'function', {}, 'any', 'none', 'none', false, false, true, {"LUA"}, setmap({}), '', datetime, datetime}
---
- error: function does not support alter
...
box.schema.user.grant('guest', 'execute', 'function', 'function1')
---
...
_ = box.schema.space.create('test')
---
...
_ = box.space.test:create_index('primary')
---
...
box.schema.user.grant('guest', 'read,write', 'space', 'test')
---
...
c:call('function1')
---
- []
...
box.schema.func.drop("function1")
---
...
box.schema.func.create('function1.args', {language = "C"})
---
...
box.schema.user.grant('guest', 'execute', 'function', 'function1.args')
---
...
c:call('function1.args')
---
- error: invalid argument count
...
c:call('function1.args', { "xx" })
---
- error: first tuple field must be uint
...
c:call('function1.args', { 15 })
---
- [[15, 'hello']]
...
box.func["function1.args"]
---
- aggregate: none
returns: any
exports:
lua: true
sql: false
id: 68
setuid: false
is_multikey: false
is_deterministic: false
name: function1.args
language: C
...
box.func["function1.args"]:call()
---
- error: invalid argument count
...
box.func["function1.args"]:call({ "xx" })
---
- error: first tuple field must be uint
...
box.func["function1.args"]:call({ 15 })
---
- [15, 'hello']
...
box.schema.func.drop("function1.args")
---
...
box.func["function1.args"]
---
- null
...
box.schema.func.create('function1.multi_inc', {language = "C"})
---
...
box.schema.user.grant('guest', 'execute', 'function', 'function1.multi_inc')
---
...
c:call('function1.multi_inc')
---
- []
...
box.space.test:select{}
---
- []
...
c:call('function1.multi_inc', { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
---
- []
...
box.space.test:select{}
---
- - [1, 0]
- [2, 0]
- [3, 0]
- [4, 0]
- [5, 0]
- [6, 0]
- [7, 0]
- [8, 0]
- [9, 0]
- [10, 0]
...
c:call('function1.multi_inc', { 2, 4, 6, 8, 10 })
---
- []
...
box.space.test:select{}
---
- - [1, 0]
- [2, 1]
- [3, 0]
- [4, 1]
- [5, 0]
- [6, 1]
- [7, 0]
- [8, 1]
- [9, 0]
- [10, 1]
...
c:call('function1.multi_inc', { 0, 2, 4 })
---
- []
...
box.space.test:select{}
---
- - [0, 0]
- [1, 0]
- [2, 2]
- [3, 0]
- [4, 2]
- [5, 0]
- [6, 1]
- [7, 0]
- [8, 1]
- [9, 0]
- [10, 1]
...
box.schema.func.drop("function1.multi_inc")
---
...
box.schema.func.create('function1.errors', {language = "C"})
---
...
box.schema.user.grant('guest', 'execute', 'function', 'function1.errors')
---
...
c:call('function1.errors')
---
- error: unknown error
...
box.schema.func.drop("function1.errors")
---
...
box.schema.func.create('xxx', {language = 'invalid'})
---
- error: Unsupported language 'INVALID' specified for function 'xxx'
...
-- language normalization
function func_lang(name) return (box.space._func.index[2]:select{name}[1] or {})[5] end
---
...
box.schema.func.create('f11'), func_lang('f11')
---
- null
- LUA
...
box.schema.func.create('f12', {language = 'Lua'}), func_lang('f12')
---
- null
- LUA
...
box.schema.func.create('f13', {language = 'lua'}), func_lang('f13')
---
- null
- LUA
...
box.schema.func.create('f14', {language = 'lUa'}), func_lang('f14')
---
- null
- LUA
...
box.schema.func.create('f15', {language = 'c'}), func_lang('f15')
---
- null
- C
...
box.schema.func.create('f16', {language = 'C'}), func_lang('f16')
---
- null
- C
...
box.schema.func.drop("f11")
---
...
box.schema.func.drop("f12")
---
...
box.schema.func.drop("f13")
---
...
box.schema.func.drop("f14")
---
...
box.schema.func.drop("f15")
---
...
box.schema.func.drop("f16")
---
...
box.space.test:drop()
---
...
-- Missing shared library
name = 'unkownmod.unknownfunc'
---
...
box.schema.func.create(name, {language = 'C'})
---
...
box.schema.user.grant('guest', 'execute', 'function', name)
---
...
c:call(name)
---
- error: 'Failed to dynamically load module ''unkownmod'': module not found'
...
box.schema.func.drop(name)
---
...
-- Drop function while executing gh-910
box.schema.func.create('function1.test_yield', {language = "C"})
---
...
box.schema.user.grant('guest', 'execute', 'function', 'function1.test_yield')
---
...
s = box.schema.space.create('test_yield')
---
...
_ = s:create_index('pk')
---
...
box.schema.user.grant('guest', 'read,write', 'space', 'test_yield')
---
...
fiber = require('fiber')
---
...
ch = fiber.channel(1)
---
...
_ = fiber.create(function() c:call('function1.test_yield') ch:put(true) end)
---
...
while s:get({1}) == nil do fiber.yield(0.0001) end
---
...
box.schema.func.drop('function1.test_yield')
---
...
ch:get()
---
- true
...
s:drop()
---
...
-- gh-2914: check identifier constraints.
test_run = require('test_run').new()
---
...
test_run:cmd("push filter '(.builtin/.*.lua):[0-9]+' to '\\1'")
---
- true
...
identifier = require("identifier")
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
--
-- '.' in func name is used to point out path therefore '.' in name
-- itself is prohibited
--
--
identifier.run_test(
function (identifier)
if identifier == "." then return end
box.schema.func.create(identifier, {language = "lua"})
box.schema.user.grant('guest', 'execute', 'function', identifier)
rawset(_G, identifier, function () return 1 end)
local res = pcall(c.call, c, identifier)
if c:call(identifier) ~= 1 then
error("Should not fire")
end
rawset(_G, identifier, nil)
end,
function (identifier)
if identifier == "." then return end
box.schema.func.drop(identifier)
end
);
---
- All tests passed
...
test_run:cmd("setopt delimiter ''");
---
- true
...
c:close()
---
...
--
-- gh-2233: Invoke Lua functions created outside SQL.
--
box.schema.func.create('WAITFOR', {language = 'SQL_BUILTIN', \
param_list = {'integer'}, returns = 'integer',exports = {'SQL'}})
---
- error: 'Failed to create function ''WAITFOR'': given built-in is not predefined'
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
box.schema.func.create("function1.divide", {language = 'C', returns = 'number',
is_deterministic = true,
exports = {'LUA'}})
test_run:cmd("setopt delimiter ''");
---
...
box.execute('SELECT "function1.divide"()')
---
- null
- function function1.divide() is not available in SQL
...
box.func["function1.divide"]:drop()
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
box.schema.func.create("function1.divide", {language = 'C', returns = 'number',
is_deterministic = true,
exports = {'LUA', 'SQL'}})
test_run:cmd("setopt delimiter ''");
---
...
box.execute('SELECT "function1.divide"()')
---
- null
- invalid argument
...
box.execute('SELECT "function1.divide"(6)')
---
- null
- 'Wrong number of arguments is passed to function1.divide(): expected 0, got 1'
...
box.execute('SELECT "function1.divide"(6, 3)')
---
- null
- 'Wrong number of arguments is passed to function1.divide(): expected 0, got 2'
...
box.func["function1.divide"]:drop()
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
box.schema.func.create("function1.divide", {language = 'C', returns = 'number',
param_list = {'number', 'number'},
is_deterministic = true,
exports = {'LUA', 'SQL'}})
test_run:cmd("setopt delimiter ''");
---
...
box.execute('SELECT "function1.divide"()')
---
- null
- 'Wrong number of arguments is passed to function1.divide(): expected 2, got 0'
...
box.execute('SELECT "function1.divide"(6)')
---
- null
- 'Wrong number of arguments is passed to function1.divide(): expected 2, got 1'
...
box.execute('SELECT "function1.divide"(6, 3, 3)')
---
- null
- 'Wrong number of arguments is passed to function1.divide(): expected 2, got 3'
...
box.execute('SELECT "function1.divide"(6, 3)')
---
- metadata:
- name: COLUMN_1
type: number
rows:
- [2]
...
box.execute('SELECT "function1.divide"(5, 2)')
---
- metadata:
- name: COLUMN_1
type: number
rows:
- [2.5]
...
box.func["function1.divide"]:drop()
---
...
function SUMMARIZE(a, b) return a + b end
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
box.schema.func.create("SUMMARIZE", {language = 'LUA', returns = 'number',
is_deterministic = true,
param_list = {'number', 'number'},
exports = {'LUA', 'SQL'}})
test_run:cmd("setopt delimiter ''");
---
...
box.execute('SELECT summarize(1, 2)')
---
- metadata:
- name: COLUMN_1
type: number
rows:
- [3]
...
box.func.SUMMARIZE:drop()
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
box.schema.func.create("SUMMARIZE", {language = 'LUA', returns = 'number',
body = 'function (a, b) return a + b end',
is_deterministic = true,
param_list = {'number', 'number'},
exports = {'LUA', 'SQL'}})
test_run:cmd("setopt delimiter ''");
---
...
box.execute('SELECT summarize(1, 2)')
---
- metadata:
- name: COLUMN_1
type: number
rows:
- [3]
...
box.func.SUMMARIZE:drop()
---
...
--
-- gh-4113: Valid method to use Lua from SQL
--
box.execute('SELECT lua(\'return 1 + 1\')')
---
- metadata:
- name: COLUMN_1
type: any
rows:
- [2]
...
box.execute('SELECT lua(\'return box.cfg\')')
---
- null
- 'Failed to execute SQL statement: Unsupported type passed from Lua'
...
box.execute('SELECT lua(\'return box.cfg()\')')
---
- null
- SQL expects exactly one argument returned from Lua, got 0
...
box.execute('SELECT lua(\'return box.cfg.memtx_memory\')')
---
- metadata:
- name: COLUMN_1
type: any
rows:
- [107374182]
...
-- Test registered functions interface.
function divide(a, b) return a / b end
---
...
box.schema.func.create("divide", {comment = 'Divide two values'})
---
...
func = box.func.divide
---
...
func.call({4, 2})
---
- error: 'builtin/box/schema.lua: Use func:call(...) instead of func.call(...)'
...
func:call(4, 2)
---
- error: 'builtin/box/schema.lua: Use func:call(table)'
...
func:call()
---
- error: '[string "function divide(a, b) return a / b end "]:1: attempt to perform
arithmetic on local ''a'' (a nil value)'
...
func:call({})
---
- error: '[string "function divide(a, b) return a / b end "]:1: attempt to perform
arithmetic on local ''a'' (a nil value)'
...
func:call({4})
---
- error: '[string "function divide(a, b) return a / b end "]:1: attempt to perform
arithmetic on local ''b'' (a nil value)'
...
func:call({4, 2})
---
- 2
...
func:call({4, 2, 1})
---
- 2
...
func:drop()
---
...
func
---
- aggregate: none
returns: any
exports:
lua: true
sql: false
id: 68
setuid: false
is_multikey: false
is_deterministic: false
comment: Divide two values
name: divide
language: LUA
...
func.drop()
---
- error: 'builtin/box/schema.lua: Use func:drop(...) instead of func.drop(...)'
...
box.func.divide
---
- null
...
func:drop()
---
- error: Function 'divide' does not exist
...
func:call({4, 2})
---
- error: Function 'divide' does not exist
...
box.internal.func_call('divide', 4, 2)
---
- error: Function 'divide' does not exist
...
box.schema.func.create("function1.divide", {language = 'C'})
---
...
func = box.func["function1.divide"]
---
...
func:call(4, 2)
---
- error: 'builtin/box/schema.lua: Use func:call(table)'
...
func:call()
---
- error: invalid argument
...
func:call({})
---
- error: invalid argument
...
func:call({4})
---
- error: invalid argument
...
func:call({4, 2})
---
- [2]
...
func:call({4, 2, 1})
---
- [2]
...
func:drop()
---
...
box.func["function1.divide"]
---
- null
...
func
---
- aggregate: none
returns: any
exports:
lua: true
sql: false
id: 68
setuid: false
is_multikey: false
is_deterministic: false
name: function1.divide
language: C
...
func:drop()
---
- error: Function 'function1.divide' does not exist
...
func:call({4, 2})
---
- error: Function 'function1.divide' does not exist
...
box.internal.func_call('function1.divide', 4, 2)
---
- error: Function 'function1.divide' does not exist
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
function minmax(array)
local min = 999
local max = -1
for _, v in pairs(array) do
min = math.min(min, v)
max = math.max(max, v)
end
return min, max
end
test_run:cmd("setopt delimiter ''");
---
...
box.schema.func.create("minmax")
---
...
func = box.func.minmax
---
...
func:call({{1, 2, 99, 3, -1}})
---
- -1
- 99
...
func:drop()
---
...
box.func.minmax
---
- null
...
-- Test access checks for registered functions.
function secret() return 1 end
---
...
box.schema.func.create("secret")
---
...
box.func.secret:call({})
---
- 1
...
function secret_leak() return box.func.secret:call() end
---
...
box.schema.func.create('secret_leak')
---
...
box.schema.user.grant('guest', 'execute', 'function', 'secret_leak')
---
...
conn = net.connect(box.cfg.listen)
---
...
conn:call('secret_leak')
---
- error: Execute access to function 'secret' is denied for user 'guest'
...
conn:close()
---
...
box.schema.user.revoke('guest', 'execute', 'function', 'secret_leak')
---
...
box.schema.func.drop('secret_leak')
---
...
box.schema.func.drop('secret')
---
...
-- UDF corner cases for SQL: no value returned, too many values returned
box.execute("SELECT LUA('a = 1 + 1')")
---
- null
- SQL expects exactly one argument returned from Lua, got 0
...
box.execute("SELECT LUA('return 1, 2')")
---
- null
- SQL expects exactly one argument returned from Lua, got 2
...
box.schema.func.create('function1', {language = "C", exports = {'LUA', 'SQL'}})
---
...
box.execute("SELECT \"function1\"()")
---
- null
- SQL expects exactly one argument returned from C, got 0
...
box.schema.func.drop("function1")
---
...
box.schema.func.create('function1.multireturn', {language = "C", exports = {'LUA', 'SQL'}})
---
...
box.execute("SELECT \"function1.multireturn\"()")
---
- null
- SQL expects exactly one argument returned from C, got 2
...
box.schema.func.drop("function1.multireturn")
---
...
--
-- gh-4641: box_return_mp() C API to return arbitrary MessagePack
-- from C functions.
--
name = 'function1.test_return_mp'
---
...
box.schema.func.create(name, {language = "C", exports = {'LUA'}})
---
...
box.func[name]:call()
---
- 1
- -1
- 18446744073709551615
- '123456789101112131415'
- [2]
...
box.schema.user.grant('guest', 'super')
---
...
-- Netbox:call() returns not the same as local call for C
-- functions, see #4799.
net:connect(box.cfg.listen):call(name)
---
- [1, -1, 18446744073709551615, '123456789101112131415', [2]]
...
box.schema.user.revoke('guest', 'super')
---
...
box.schema.func.drop(name)
---
...
--
-- gh-4182: Introduce persistent Lua functions.
--
test_run:cmd("setopt delimiter ';'")
---
- true
...
body = [[function(tuple)
if type(tuple.address) ~= 'string' then
return nil, 'Invalid field type'
end
local t = tuple.address:upper():split()
for k,v in pairs(t) do t[k] = v end
return t
end
]]
test_run:cmd("setopt delimiter ''");
---
...
box.schema.func.create('addrsplit', {body = body, language = "C"})
---
- error: 'Failed to create function ''addrsplit'': body and is_sandboxed options are
not compatible with C language'
...
box.schema.func.create('addrsplit', {is_sandboxed = true, language = "C"})
---
- error: 'Failed to create function ''addrsplit'': body and is_sandboxed options are
not compatible with C language'
...
box.schema.func.create('addrsplit', {is_sandboxed = true})
---
- error: 'Failed to create function ''addrsplit'': is_sandboxed option may be set
only for a persistent Lua function (one with a non-empty body)'
...
box.schema.func.create('invalid', {body = "function(tuple) ret tuple"})
---
- error: 'Failed to dynamically load function ''invalid'': [string "return function(tuple)
ret tuple"]:1: ''='' expected near ''tuple'''
...
box.schema.func.create('addrsplit', {body = body, is_deterministic = true})
---
...
box.schema.user.grant('guest', 'execute', 'function', 'addrsplit')
---
...
conn = net.connect(box.cfg.listen)
---
...
conn:call('addrsplit', {{address = "Moscow Dolgoprudny"}})
---
- ['MOSCOW', 'DOLGOPRUDNY']
...
box.func.addrsplit:call({{address = "Moscow Dolgoprudny"}})
---
- - MOSCOW
- DOLGOPRUDNY
...
conn:close()
---
...
box.snapshot()
---
- ok
...
test_run:cmd("restart server default")
test_run = require('test_run').new()
---
...
test_run:cmd("push filter '(.builtin/.*.lua):[0-9]+' to '\\1'")
---
- true
...
net = require('net.box')
---
...
conn = net.connect(box.cfg.listen)
---
...
conn:call('addrsplit', {{address = "Moscow Dolgoprudny"}})
---
- ['MOSCOW', 'DOLGOPRUDNY']
...
box.func.addrsplit:call({{address = "Moscow Dolgoprudny"}})
---
- - MOSCOW
- DOLGOPRUDNY
...
conn:close()
---
...
box.schema.user.revoke('guest', 'execute', 'function', 'addrsplit')
---
...
box.func.addrsplit:drop()
---
...
-- Test sandboxed functions.
test_run:cmd("setopt delimiter ';'")
---
- true
...
body = [[function(number)
math.abs = math.log
return math.abs(number)
end]]
test_run:cmd("setopt delimiter ''");
---
...
box.schema.func.create('monkey', {body = body, is_sandboxed = true})
---
...
box.func.monkey:call({1})
---
- 0
...
math.abs(1)
---
- 1
...
box.func.monkey:drop()
---
...
sum = 0
---
...
function inc_g(val) sum = sum + val end
---
...
box.schema.func.create('call_inc_g', {body = "function(val) inc_g(val) end"})
---
...
box.func.call_inc_g:call({1})
---
...
assert(sum == 1)
---
- true
...
box.schema.func.create('call_inc_g_safe', {body = "function(val) inc_g(val) end", is_sandboxed = true})
---
...
box.func.call_inc_g_safe:call({1})
---
- error: '[string "return function(val) inc_g(val) end"]:1: attempt to call global
''inc_g'' (a nil value)'
...
assert(sum == 1)
---
- true
...
box.func.call_inc_g:drop()
---
...
box.func.call_inc_g_safe:drop()
---
...
-- Test persistent function assemble corner cases
box.schema.func.create('compiletime_tablef', {body = "{}"})
---
- error: 'Failed to dynamically load function ''compiletime_tablef'': given body doesn''t
define a function'
...
box.schema.func.create('compiletime_call_inc_g', {body = "inc_g()"})
---
- error: 'Failed to dynamically load function ''compiletime_call_inc_g'': [string
"return inc_g()"]:1: attempt to call global ''inc_g'' (a nil value)'
...
assert(sum == 1)
---
- true
...
test_run:cmd("clear filter")
---
- true
...
--
-- Check that function cache is updated synchronously with _func changes.
--
box.begin() box.schema.func.create('test') f = box.func.test box.rollback()
---
...
f ~= nil
---
- true
...
box.func.test == nil
---
- true
...
box.schema.func.create('test')
---
...
f = box.func.test
---
...
box.begin() box.space._func:delete{f.id} f = box.func.test box.rollback()
---
...
f == nil
---
- true
...
box.func.test ~= nil
---
- true
...
box.func.test:drop()
---
...
-- Check SQL builtins
test_run:cmd("setopt delimiter ';'")
---
- true
...
sql_builtin_list = {
"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", "GREATEST", "LEAST"
}
test_run:cmd("setopt delimiter ''");
---
...
ok = true
---
...
for _, v in pairs(sql_builtin_list) do ok = ok and (box.space._func.index.name:get(v) ~= nil) end
---
...
ok == true
---
- true
...
box.func.LUA:call({"return 1 + 1"})
---
- 2
...
box.schema.user.grant('guest', 'execute', 'function', 'SUM')
---
...
c = net.connect(box.cfg.listen)
---
...
c:call("SUM")
---
- error: sql builtin function does not support Lua frontend
...
c:close()
---
...
box.schema.user.revoke('guest', 'execute', 'function', 'SUM')
---
...
box.schema.func.drop("SUM")
---
- error: 'Can''t drop function 1: function is SQL built-in'
...
-- Introduce function options
box.schema.func.create('test', {body = "function(tuple) return tuple end", is_deterministic = true, opts = {is_multikey = true}})
---
...
box.func['test'].is_multikey == true
---
- true
...
box.func['test']:drop()
---
...
|