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.
42 lines
933 B
42 lines
933 B
2 years ago
|
AGGREGATION FUNCTION add(a, b){
|
||
|
a+b
|
||
|
}
|
||
|
|
||
|
AGGREGATION FUNCTION covariances2(x, y, w){
|
||
|
xmeans := 0.;
|
||
|
ymeans := 0.;
|
||
|
l := _builtin_len;
|
||
|
|
||
|
if (l > 0)
|
||
|
{
|
||
|
xmeans := x[0];
|
||
|
ymeans := y[0];
|
||
|
_builtin_ret[0] := 0.;
|
||
|
}
|
||
|
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 "test.csv"
|
||
|
INTO TABLE test
|
||
|
FIELDS TERMINATED BY ","
|
||
|
|
||
|
select covariances2(a, b, 4) from test group by c;
|
||
|
|