udfpy.sim 6.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
system_content printf %OS%
if $system_content == Windows_NT then
  return 0;
endi

system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c udf -v 1
system sh/exec.sh -n dnode1 -s start
sql connect

print ======== step1 udf
system sh/compile_udf.sh
S
slzhou 已提交
14
system sh/prepare_pyudf.sh
15 16 17
system mkdir -p /tmp/pyudf
system cp sh/pybitand.py /tmp/pyudf/
system cp sh/pyl2norm.py /tmp/pyudf/
S
shenglian zhou 已提交
18
system cp sh/pycumsum.py /tmp/pyudf/
19 20 21 22 23 24 25 26 27 28 29 30 31 32
system ls /tmp/pyudf

sql create database udf vgroups 3;
sql use udf;
sql select * from information_schema.ins_databases;

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

system_content printf %OS%
if $system_content == Windows_NT then
  return 0;
endi
if $system_content == Windows_NT then
X
Xiaoyu Wang 已提交
33
  sql create function bit_and as 'C:\\Windows\\Temp\\bitand.dll' outputtype int;
34 35
  sql create aggregate function l2norm as 'C:\\Windows\\Temp\\l2norm.dll' outputtype double bufSize 8;
else
X
Xiaoyu Wang 已提交
36
  sql create function bit_and as '/tmp/udf/libbitand.so' outputtype int;
37 38 39 40 41 42 43 44 45
  sql create aggregate function l2norm as '/tmp/udf/libl2norm.so' outputtype double bufSize 8;
endi
sql create function pybitand as '/tmp/pyudf/pybitand.py' outputtype int language 'python';
sql create aggregate function pyl2norm as '/tmp/pyudf/pyl2norm.py' outputtype double bufSize 128 language 'python';

sql show functions;
if $rows != 4 then
  return -1
endi
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

sql select func_language, func_body,name from information_schema.ins_functions order by name
if $rows != 4 then
  return -1
endi

if $data00 != @C@ then 
  return -1
endi
if $data10 != @C@ then 
  return -1
endi
if $data20 != @Python@ then 
  return -1
endi
if $data30 != @Python@ then 
  return -1
endi

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
sql select bit_and(f, f) from t;
if $rows != 2 then
  return -1
endi
if $data00 != 1 then
  return -1
endi
if $data10 != 2 then
  return -1
endi

sql select pybitand(f, f) from t;
if $rows != 2 then
  return -1
endi
if $data00 != 1 then
  return -1
endi
if $data10 != 2 then
  return -1
endi

sql select l2norm(f) from t;
if $rows != 1 then
  print expect 1, actual $rows
  return -1
endi
if $data00 != 2.236067977 then
  return -1
endi

sql select pyl2norm(f) from t;
if $rows != 1 then
  print expect 1, actual $rows
  return -1
endi
if $data00 != 2.236067977 then
  return -1
endi

sql create table t2 (ts timestamp, f1 int, f2 int);
sql insert into t2 values(now, 0, 0)(now+1s, 1, 1);
sql select bit_and(f1, f2) from t2;
if $rows != 2 then
  return -1
endi
if $data00 != 0 then
  return -1
endi
if $data10 != 1 then
  return -1
endi

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

sql select pybitand(f1, f2) from t2;
if $rows != 2 then
  return -1
endi
if $data00 != 0 then
  return -1
endi
if $data10 != 1 then
  return -1
endi

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

sql insert into t2 values(now+2s, 1, null)(now+3s, null, 2);
sql select bit_and(f1, f2) from t2;
print $rows , $data00 , $data10 , $data20 , $data30
if $rows != 4 then
  return -1
endi
if $data00 != 0 then
  return -1
endi
if $data10 != 1 then
  return -1
endi

if $data20 != NULL then
  return -1
endi

if $data30 != NULL then
  return -1
endi

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

sql select pybitand(f1, f2) from t2;
print $rows , $data00 , $data10 , $data20 , $data30
if $rows != 4 then
  return -1
endi
if $data00 != 0 then
  return -1
endi
if $data10 != 1 then
  return -1
endi

if $data20 != NULL then
  return -1
endi

if $data30 != NULL then
  return -1
endi

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


sql insert into t2 values(now+4s, 4, 8)(now+5s, 5, 9);
sql select l2norm(f1-f2), l2norm(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 l2norm(bit_and(f2, f1)), l2norm(bit_and(f1, f2)) from t2;
print $rows , $data00 , $data01
if $rows != 1 then
  return -1
endi
if $data00 != 1.414213562 then
  return -1
endi
if $data01 != 1.414213562 then
  return -1
endi

sql select l2norm(f2) from udf.t2 group by 1-bit_and(f1, f2) order by 1-bit_and(f1,f2);
print $rows , $data00 , $data10 , $data20
if $rows != 3 then
  return -1
endi
if $data00 != 2.000000000 then
  return -1
endi
if $data10 != 9.055385138 then
  return -1
endi
if $data20 != 8.000000000 then
  return -1
endi

sql select pyl2norm(f1-f2), pyl2norm(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 pyl2norm(pybitand(f2, f1)), pyl2norm(pybitand(f1, f2)) from t2;
print $rows , $data00 , $data01
if $rows != 1 then
  return -1
endi
if $data00 != 1.414213562 then
  return -1
endi
if $data01 != 1.414213562 then
  return -1
endi

sql select pyl2norm(f2) from udf.t2 group by 1-pybitand(f1, f2) order by 1-pybitand(f1,f2);
print $rows , $data00 , $data10 , $data20
if $rows != 3 then
  return -1
endi
if $data00 != 2.000000000 then
  return -1
endi
if $data10 != 9.055385138 then
  return -1
endi
if $data20 != 8.000000000 then
  return -1
endi

S
slzhou 已提交
284 285 286 287 288 289 290 291 292 293 294
#sql create aggregate function pycumsum as '/tmp/pyudf/pycumsum.py' outputtype double bufSize 128 language 'python';
#sql select pycumsum(f2) from udf.t2
#print ======= pycumsum
#print $rows $data00
#if $rows != 1 then
#  return -1
#endi
#if $data00 != 20.000000000 then
#  return -1
#endi
#sql drop function pycumsum
S
shenglian zhou 已提交
295

296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
sql create or replace function bit_and as '/tmp/udf/libbitand.so' outputtype int
sql select func_version from information_schema.ins_functions where name='bit_and'
if $data00 != 1 then
  return -1
endi
sql select bit_and(f1, f2) from t2;
print $rows , $data00 , $data10 , $data20 , $data30 , $data40 , $data50
if $rows != 6 then
  return -1
endi
if $data00 != 0 then
  return -1
endi
if $data10 != 1 then
  return -1
endi
312

313 314 315 316 317 318 319 320 321 322 323 324 325 326
if $data20 != NULL then
  return -1
endi

if $data30 != NULL then
  return -1
endi

if $data40 != 0 then
  return -1
endi
if $data50 != 1 then
  return -1
endi
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
#sql drop function bit_and;
#sql show functions;
#if $rows != 1 then
#  return -1
#endi
#if $data00 != @l2norm@ then
#  return -1
#  endi
#sql drop function l2norm;
#sql show functions;
#if $rows != 0 then
#  return -1
#endi

system sh/exec.sh -n dnode1 -s stop -x SIGINT