udf.sim 3.4 KB
Newer Older
S
shenglian zhou 已提交
1 2 3 4 5 6 7 8 9 10
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
S
slzhou 已提交
11 12 13
sql alter user root pass 'taosdata2'
system sh/exec.sh -n dnode1 -s stop
system sh/exec.sh -n dnode1 -s start
S
shenglian zhou 已提交
14

15
print ======== step1 udf
S
shenglian zhou 已提交
16 17 18
system sh/compile_udf.sh
sql create database udf vgroups 3;
sql use udf;
X
Xiaoyu Wang 已提交
19
sql select * from information_schema.ins_databases;
S
shenglian zhou 已提交
20 21 22 23 24 25 26 27 28

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 已提交
29
  sql create function bit_and as 'C:\\Windows\\Temp\\bitand.dll' outputtype int;
S
shenglian zhou 已提交
30
  sql create aggregate function l2norm as 'C:\\Windows\\Temp\\l2norm.dll' outputtype double bufSize 8;
S
shenglian zhou 已提交
31
else
X
Xiaoyu Wang 已提交
32
  sql create function bit_and as '/tmp/udf/libbitand.so' outputtype int;
S
shenglian zhou 已提交
33
  sql create aggregate function l2norm as '/tmp/udf/libl2norm.so' outputtype double bufSize 8;
S
shenglian zhou 已提交
34
endi
35 36 37

sql_error create function bit_and as '/tmp/udf/libbitand.so' oputtype json;

S
shenglian zhou 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
sql show functions;
if $rows != 2 then
  return -1
endi
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

S
shenglian zhou 已提交
53
sql select l2norm(f) from t;
S
shenglian zhou 已提交
54 55 56 57 58 59 60 61 62 63
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);
S
shenglian zhou 已提交
64
sql select bit_and(f1, f2) from t2;
S
shenglian zhou 已提交
65 66 67 68 69 70 71 72 73 74
if $rows != 2 then
  return -1
endi
if $data00 != 0 then
  return -1
endi
if $data10 != 1 then
  return -1
endi

S
shenglian zhou 已提交
75
sql select l2norm(f1, f2) from t2;
S
shenglian zhou 已提交
76 77 78 79 80 81 82 83
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);
S
shenglian zhou 已提交
84
sql select bit_and(f1, f2) from t2;
S
shenglian zhou 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
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

S
shenglian zhou 已提交
104
sql select l2norm(f1, f2) from t2;
S
shenglian zhou 已提交
105 106 107 108 109 110 111 112 113
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);
S
shenglian zhou 已提交
114
sql select l2norm(f1-f2), l2norm(f1+f2) from t2;
S
shenglian zhou 已提交
115 116 117 118 119 120 121 122 123 124 125
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

S
shenglian zhou 已提交
126
sql select l2norm(bit_and(f2, f1)), l2norm(bit_and(f1, f2)) from t2;
S
shenglian zhou 已提交
127 128 129 130
print $rows , $data00 , $data01
if $rows != 1 then
  return -1
endi
131
if $data00 != 1.414213562 then
S
shenglian zhou 已提交
132 133
  return -1
endi
134
if $data01 != 1.414213562 then
S
shenglian zhou 已提交
135 136 137
  return -1
endi

S
shenglian zhou 已提交
138
sql select l2norm(f2) from udf.t2 group by 1-bit_and(f1, f2) order by 1-bit_and(f1,f2);
139 140
print $rows , $data00 , $data10 , $data20
if $rows != 3 then
S
shenglian zhou 已提交
141 142 143 144 145
  return -1
endi
if $data00 != 2.000000000 then
  return -1
endi
146 147 148 149
if $data10 != 9.055385138 then
  return -1
endi
if $data20 != 8.000000000 then
S
shenglian zhou 已提交
150 151 152
  return -1
endi

153 154 155 156 157 158 159 160 161 162 163 164 165
#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
S
shenglian zhou 已提交
166 167

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