udf.sim 2.9 KB
Newer Older
S
shenglian zhou 已提交
1 2
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
3
system sh/cfg.sh -n dnode1 -c udf -v 1
S
shenglian zhou 已提交
4

5
print ========= start dnode1 as leader
S
shenglian zhou 已提交
6 7 8 9 10 11 12 13 14 15 16 17
system sh/exec.sh -n dnode1 -s start
sql connect

print ======== step1 udf 
system sh/copy_udf.sh
sql create database udf vgroups 3;
sql use udf;
sql show databases;

sql create table t (ts timestamp, f int);
sql insert into t values(now, 1)(now+1s, 2);

wafwerar's avatar
wafwerar 已提交
18 19 20 21 22 23 24 25
system_content printf %OS%
if $system_content == Windows_NT then
  sql create function udf1 as 'C:\\Windows\\Temp\\udf1.dll' outputtype int bufSize 8;
  sql create aggregate function udf2 as 'C:\\Windows\\Temp\\udf2.dll' outputtype double bufSize 8;
else
  sql create function udf1 as '/tmp/udf/libudf1.so' outputtype int bufSize 8;
  sql create aggregate function udf2 as '/tmp/udf/libudf2.so' outputtype double bufSize 8;
endi
S
shenglian zhou 已提交
26
sql show functions;
S
shenglian zhou 已提交
27 28 29
if $rows != 2 then
  return -1
endi
S
shenglian zhou 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42
sql select udf1(f) from t;
if $rows != 2 then
  return -1
endi
if $data00 != 88 then
  return -1
endi
if $data10 != 88 then
  return -1
endi

sql select udf2(f) from t;
if $rows != 1 then
43
  print expect 1, actual $rows
S
shenglian zhou 已提交
44 45 46 47 48 49
  return -1
endi
if $data00 != 2.236067977 then
  return -1
endi

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
sql create table t2 (ts timestamp, f1 int, f2 int);
sql insert into t2 values(now, 0, 0)(now+1s, 1, 1);
sql select udf1(f1, f2) from t2;
if $rows != 2 then
  return -1
endi
if $data00 != 88 then
  return -1
endi
if $data10 != 88 then
  return -1
endi

sql select udf2(f1, f2) from t2;
if $rows != 1 then
  return -1
endi
if $data00 != 1.414213562 then
  return -1
endi

71
sql insert into t2 values(now+2s, 1, null)(now+3s, null, 2);
S
slzhou 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
sql select udf1(f1, f2) from t2;
print $rows , $data00 , $data10 , $data20 , $data30
if $rows != 4 then
  return -1
endi
if $data00 != 88 then
  return -1
endi
if $data10 != 88 then
  return -1
endi

if $data20 != NULL then
  return -1
endi

if $data30 != NULL then
  return -1
endi
91 92 93 94 95 96 97 98 99

sql select udf2(f1, f2) from t2;
print $rows, $data00
if $rows != 1 then
  return -1
endi
if $data00 != 2.645751311 then
  return -1
endi
S
slzhou 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

sql insert into t2 values(now+4s, 4, 8)(now+5s, 5, 9);
sql select udf2(f1-f2), udf2(f1+f2) from t2;
print $rows , $data00 , $data01
if $rows != 1 then
  return -1;
endi
if $data00 != 5.656854249 then
  return -1
endi
if $data01 != 18.547236991 then
  return -1
endi

sql select udf2(udf1(f2-f1)), udf2(udf1(f2/f1)) from t2;
115
print $rows , $data00 , $data01
S
slzhou 已提交
116 117 118 119 120 121 122 123 124
if $rows != 1 then
  return -1
endi
if $data00 != 176.000000000 then
  return -1
endi
if $data01 != 152.420471066 then
  return -1
endi
125 126 127 128 129 130 131 132 133 134 135 136 137

sql select udf2(f2) from udf.t2 group by 1-udf1(f1);
print $rows , $data00 , $data10
if $rows != 2 then
  return -1
endi
if $data00 != 2.000000000 then
  return -1
endi
if $data10 != 12.083045974 then
  return -1
endi

S
slzhou 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151
sql drop function udf1;
sql show functions;
if $rows != 1 then
  return -1
endi
if $data00 != @udf2@ then
  return -1
  endi
sql drop function udf2;
sql show functions;
if $rows != 0 then
  return -1
endi

S
slzhou 已提交
152
system sh/exec.sh -n dnode1 -s stop -x SIGTERM