You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
878 B
41 lines
878 B
|
|
|
|
AGGREGATION FUNCTION covariances2(x, y, win){
|
|
xmeans := 0.;
|
|
ymeans := 0.;
|
|
l := _builtin_len;
|
|
|
|
if (l > 0)
|
|
{
|
|
xmeans := x[0];
|
|
ymeans := y[0];
|
|
_builtin_ret[0] := 0.;
|
|
}
|
|
w := win;
|
|
if (w > l)
|
|
w := l;
|
|
for (i := 1, j:= 0; i < w; i := i+1) {
|
|
xmeans += x[i];
|
|
ymeans += y[i];
|
|
_builtin_ret[i] := avg (( x(0, i) - xmeans/i ) * (y(0, i) - ymeans/i ));
|
|
}
|
|
xmeans /= w;
|
|
ymeans /= w;
|
|
for (i := w; i < l; i += 1)
|
|
{
|
|
xmeans += (x[i] - x[i - w]) / w;
|
|
ymeans += (y[i] - y[i - w]) / w;
|
|
_builtin_ret[i] := avg (( x(i-w, i) - xmeans ) * (y(i - w, i) - ymeans ));
|
|
}
|
|
Null
|
|
}
|
|
|
|
CREATE TABLE test(a INT, b INT, c INT, d INT)
|
|
|
|
LOAD DATA INFILE "data/test2.csv"
|
|
INTO TABLE test
|
|
FIELDS TERMINATED BY ","
|
|
|
|
select covariances2(a, b, 4), a+b from test group by c;
|
|
|