Skip to content

Commit

Permalink
Merge #57583
Browse files Browse the repository at this point in the history
57583: builtins: implement regr_avgy r=yuzefovich a=mneverov

builtins: implement regr_avgy

Fixes: #41274

Release note (sql change): implement regr_avgy aggregation function.

Co-authored-by: Max Neverov <[email protected]>
  • Loading branch information
craig[bot] and mneverov committed Dec 8, 2020
2 parents b7ef888 + 8459e44 commit 557bc72
Show file tree
Hide file tree
Showing 14 changed files with 561 additions and 243 deletions.
18 changes: 18 additions & 0 deletions docs/generated/sql/aggregates.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@
</span></td></tr>
<tr><td><a name="regr_avgx"></a><code>regr_avgx(arg1: <a href="int.html">int</a>, arg2: <a href="int.html">int</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the independent variable (sum(X)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="decimal.html">decimal</a>, arg2: <a href="decimal.html">decimal</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="decimal.html">decimal</a>, arg2: <a href="float.html">float</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="decimal.html">decimal</a>, arg2: <a href="int.html">int</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="float.html">float</a>, arg2: <a href="decimal.html">decimal</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="float.html">float</a>, arg2: <a href="float.html">float</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="float.html">float</a>, arg2: <a href="int.html">int</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="int.html">int</a>, arg2: <a href="decimal.html">decimal</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="int.html">int</a>, arg2: <a href="float.html">float</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_avgy"></a><code>regr_avgy(arg1: <a href="int.html">int</a>, arg2: <a href="int.html">int</a>) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Calculates the average of the dependent variable (sum(Y)/N).</p>
</span></td></tr>
<tr><td><a name="regr_count"></a><code>regr_count(arg1: <a href="decimal.html">decimal</a>, arg2: <a href="decimal.html">decimal</a>) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>Calculates number of input rows in which both expressions are nonnull.</p>
</span></td></tr>
<tr><td><a name="regr_count"></a><code>regr_count(arg1: <a href="decimal.html">decimal</a>, arg2: <a href="float.html">float</a>) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>Calculates number of input rows in which both expressions are nonnull.</p>
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/distsql/columnar_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var aggregateFuncToNumArguments = map[execinfrapb.AggregatorSpec_Func]int{
execinfrapb.AggregatorSpec_REGR_SYY: 2,
execinfrapb.AggregatorSpec_REGR_COUNT: 2,
execinfrapb.AggregatorSpec_REGR_AVGX: 2,
execinfrapb.AggregatorSpec_REGR_AVGY: 2,
}

// TestAggregateFuncToNumArguments ensures that all aggregate functions are
Expand Down
427 changes: 215 additions & 212 deletions pkg/sql/execinfrapb/processors_sql.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/sql/execinfrapb/processors_sql.proto
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ message AggregatorSpec {
REGR_SXY = 42;
REGR_COUNT = 43;
REGR_AVGX = 44;
REGR_AVGY = 45;
}

enum Type {
Expand Down
113 changes: 104 additions & 9 deletions pkg/sql/logictest/testdata/logic_test/aggregate
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ CREATE TABLE kv (
)

# Aggregate functions return NULL if there are no rows.
query IIIIRRRRRRRRBBTIIRRRRRRRRRRIR
query IIIIRRRRRRRRBBTIIRRRRRRRRRRIRR
SELECT min(1), max(1), count(1), sum_int(1), avg(1), sum(1), stddev(1), stddev_samp(1), stddev_pop(1),
var_samp(1), variance(1), var_pop(1), bool_and(true), bool_and(false), xor_agg(b'\x01'), bit_and(1), bit_or(1),
corr(1, 1), covar_pop(1, 1), covar_samp(1, 1), sqrdiff(1), regr_intercept(1, 1), regr_r2(1, 1), regr_slope(1, 1),
regr_sxx(1, 1), regr_sxy(1, 1), regr_syy(1, 1), regr_count(1, 1), regr_avgx(1, 1)
regr_sxx(1, 1), regr_sxy(1, 1), regr_syy(1, 1), regr_count(1, 1), regr_avgx(1, 1), regr_avgy(1, 1)
FROM kv
----
NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 0 NULL
NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 0 NULL NULL

# Regression test for #29695
query T
Expand Down Expand Up @@ -46,14 +46,14 @@ SELECT min(i), avg(i), max(i), sum(i) FROM kv
----
NULL NULL NULL NULL

query IIIIRRRRRRRBBTRRRRRRRRRRIR
query IIIIRRRRRRRBBTRRRRRRRRRRIRR
SELECT min(v), max(v), count(v), sum_int(1), avg(v), sum(v), stddev(v), stddev_pop(v), variance(v), var_pop(v), var_samp(v),
bool_and(v = 1), bool_and(v = 1), xor_agg(s::bytes), corr(v,k), sqrdiff(v), covar_pop(v, k), covar_samp(v, k),
regr_intercept(v, k), regr_r2(v, k), regr_slope(v, k), regr_sxx(v, k), regr_sxy(v, k), regr_syy(v, k), regr_count(v, k),
regr_avgx(v, k)
regr_avgx(v, k), regr_avgy(v, k)
FROM kv
----
NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 0 NULL
NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 0 NULL NULL

query T
SELECT array_agg(v) FROM kv
Expand All @@ -71,13 +71,13 @@ SELECT jsonb_agg(v) FROM kv
NULL

# Aggregate functions triggers aggregation and computation when there is no source.
query IIIIRRRRRRRBBTRRRRRRRRRRIR
query IIIIRRRRRRRBBTRRRRRRRRRRIRR
SELECT min(1), count(1), max(1), sum_int(1), avg(1)::float, sum(1), stddev_samp(1), stddev_pop(1), variance(1),
var_pop(1), var_samp(1), bool_and(true), bool_or(true), to_hex(xor_agg(b'\x01')), corr(1, 2), sqrdiff(1),
covar_pop(1, 2), covar_samp(1, 2), regr_intercept(1, 2), regr_r2(1, 2), regr_slope(1, 2), regr_sxx(1, 1), regr_sxy(1, 1),
regr_syy(1, 1), regr_count(1, 1), regr_avgx(1, 1)
regr_syy(1, 1), regr_count(1, 1), regr_avgx(1, 1), regr_avgy(1, 1)
----
1 1 1 1 1 1 NULL 0 NULL 0 NULL true true 01 NULL 0 0 NULL NULL NULL NULL 0 0 0 1 1
1 1 1 1 1 1 NULL 0 NULL 0 NULL true true 01 NULL 0 0 NULL NULL NULL NULL 0 0 0 1 1 1

# Aggregate functions triggers aggregation and computation when there is no source.
query T
Expand Down Expand Up @@ -2302,6 +2302,101 @@ SELECT regr_avgx(y, x) FROM statistics_agg_test
----
NULL

subtest regr_avgy

statement OK
INSERT INTO statistics_agg_test (y, x, int_y, int_x, dy, dx)
VALUES (0.0, 0.09561, 1, 10, 0.0, 0.09561),
(42.0, 324.78, 2, 25, 42.0, 324.78),
(42.0, 324.78, 2, 25, 42.0, 324.78),
(56.0, 7.8, 3, 40, 56.0, 7.8),
(56.0, 7.8, 3, 40, 56.0, 7.8),
(56.0, 7.8, 3, 40, 56.0, 7.8),
(100.0, 99.097, 4, 100, 100.0, 99.097),
(100.0, 99.097, 4, 100, 100.0, 99.097),
(100.0, 99.097, 4, 100, 100.0, 99.097),
(100.0, 99.097, 4, 100, 100.0, 99.097),
(NULL, NULL, NULL, NULL, NULL, NULL);

query FFFFF
SELECT regr_avgy(y, x), regr_avgy(int_y, int_x), regr_avgy(y, int_x), regr_avgy(int_y, x), regr_avgy(dy, dx)
FROM statistics_agg_test
----
65.2 3 65.2 3 65.2

query FFFF
SELECT regr_avgy(y, dx), regr_avgy(int_y, dx), regr_avgy(dy, int_x), regr_avgy(dy, x)
FROM statistics_agg_test
----
65.2 3 65.2 65.2

query F
SELECT regr_avgy(DISTINCT y, x)
FROM statistics_agg_test
----
49.5

query F
SELECT CAST(regr_avgy(DISTINCT y, x) FILTER (WHERE x > 3 AND y < 100) AS decimal)
FROM statistics_agg_test
----
49

query error pq: unknown signature: regr_avgy\(string, string\)
SELECT regr_avgy(y::string, x::string) FROM statistics_agg_test

statement OK
INSERT INTO statistics_agg_test (y, x, int_y, int_x) VALUES
(1.797693134862315708145274237317043567981e+308, 0, 0, 0)

query error float out of range
SELECT regr_avgy(y, x), regr_avgy(int_y, int_x) FROM statistics_agg_test

statement OK
TRUNCATE statistics_agg_test

statement OK
INSERT INTO statistics_agg_test (y, x, int_y, int_x, dy, dx) VALUES
(1.0, 10.0, 1, 10, 1.0, 10.0),
(2.0, 20.0, 2, 20, 2.0, 20.0)

query FFF
SELECT regr_avgy(y, x), regr_avgy(int_y, int_x), regr_avgy(dy, dx)
FROM statistics_agg_test
----
1.5 1.5 1.5

statement OK
TRUNCATE statistics_agg_test

statement OK
INSERT INTO statistics_agg_test (y, x, int_y, int_x, dy, dx) VALUES
(1.0, 10.0, 1, 10, 1.0, 10.0),
(2.0, -20.0, 2, -20, 2.0, -20.0)

query FFF
SELECT regr_avgy(y, x), regr_avgy(int_y, int_x), regr_avgy(dy, dx)
FROM statistics_agg_test
----
1.5 1.5 1.5

statement OK
TRUNCATE statistics_agg_test

statement OK
INSERT INTO statistics_agg_test (y, x, int_y, int_x, dy, dx) VALUES
(1.0, -1.0, 1, -1, 1.0, -1.0),
(1.0, 1.0, 1, 1, 1.0, 1.0)

query FFF
SELECT regr_avgy(y, x), regr_avgy(int_y, int_x), regr_avgy(dy, dx)
FROM statistics_agg_test
----
1 1 1

statement OK
TRUNCATE statistics_agg_test

subtest string_agg

statement OK
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/distsql_agg
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ SELECT regr_count(y, x) FROM statistics_agg_test
----
100

query FF
SELECT regr_avgx(y, x), regr_avgy(y, x) FROM statistics_agg_test
----
4.5 50.5

# Regression test for #37211 (incorrect ordering between aggregator stages).
statement ok
CREATE TABLE uv (u INT PRIMARY KEY, v INT);
Expand Down
22 changes: 15 additions & 7 deletions pkg/sql/opt/exec/execbuilder/testdata/aggregate
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ query T
EXPLAIN (TYPES) SELECT min(1), max(1), count(NULL), sum_int(1), avg(1), sum(1), stddev(1), variance(1),
bool_and(true), bool_or(false), xor_agg(b'\x01'), corr(1, 1), covar_pop(1, 1), covar_samp(1, 1), sqrdiff(1),
regr_intercept(1, 1), regr_r2(1, 1), regr_slope(1, 1), regr_sxx(1, 1), regr_sxy(1, 1), regr_syy(1, 1),
regr_count(1, 1)
regr_count(1, 1), regr_avgx(1, 1), regr_avgy(1, 1)
FROM kv
----
distribution: local
vectorized: true
·
• group (scalar)
│ columns: (min int, max int, count int, sum_int int, avg decimal, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, xor_agg bytes, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, regr_count int)
│ columns: (min int, max int, count int, sum_int int, avg decimal, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, xor_agg bytes, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, regr_count int, regr_avgx float, regr_avgy float)
│ estimated row count: 1 (missing stats)
│ aggregate 0: min(column7)
│ aggregate 1: max(column7)
Expand All @@ -43,6 +43,8 @@ vectorized: true
│ aggregate 19: regr_sxy(column7, column7)
│ aggregate 20: regr_syy(column7, column7)
│ aggregate 21: count_rows()
│ aggregate 22: regr_avgx(column7, column7)
│ aggregate 23: regr_avgy(column7, column7)
└── • render
│ columns: (column7 int, column10 unknown, column17 bool, column19 bool, column21 bytes)
Expand All @@ -63,14 +65,14 @@ query T
EXPLAIN (TYPES) SELECT min(v), max(v), count(v), sum_int(1), avg(v), sum(v), stddev(v), variance(v),
bool_and(v = 1), bool_or(v = 1), xor_agg(s::bytes), corr(v, k), covar_pop(v, k), covar_samp(v, k), sqrdiff(v),
regr_intercept(1, 1), regr_r2(1, 1), regr_slope(1, 1), regr_sxx(1, 1), regr_sxy(1, 1), regr_syy(1, 1),
regr_count(1, 1)
regr_count(1, 1), regr_avgx(1, 1), regr_avgy(1, 1)
FROM kv
----
distribution: local
vectorized: true
·
• group (scalar)
│ columns: (min int, max int, count int, sum_int int, avg decimal, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, xor_agg bytes, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, regr_count int)
│ columns: (min int, max int, count int, sum_int int, avg decimal, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, xor_agg bytes, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, regr_count int, regr_avgx float, regr_avgy float)
│ estimated row count: 1 (missing stats)
│ aggregate 0: min(v)
│ aggregate 1: max(v)
Expand All @@ -94,6 +96,8 @@ vectorized: true
│ aggregate 19: regr_sxy(column10, column10)
│ aggregate 20: regr_syy(column10, column10)
│ aggregate 21: count_rows()
│ aggregate 22: regr_avgx(column10, column10)
│ aggregate 23: regr_avgy(column10, column10)
└── • render
│ columns: (column10 int, column16 bool, column19 bytes, k int, v int)
Expand All @@ -115,13 +119,13 @@ query T
EXPLAIN (TYPES) SELECT min(1), count(NULL), max(1), sum_int(1), avg(1)::float, sum(1), stddev(1), variance(1),
bool_and(true), bool_or(true), to_hex(xor_agg(b'\x01')), corr(1, 1), covar_pop(1, 1), covar_samp(1, 1), sqrdiff(1),
regr_intercept(1, 1), regr_r2(1, 1), regr_slope(1, 1), regr_sxx(1, 1), regr_sxy(1, 1), regr_syy(1, 1),
regr_count(1, 1)
regr_count(1, 1), regr_avgx(1, 1), regr_avgy(1, 1)
----
distribution: local
vectorized: false
·
• render
│ columns: (min int, count int, max int, sum_int int, avg float, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, to_hex string, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, regr_count int)
│ columns: (min int, count int, max int, sum_int int, avg float, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, to_hex string, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, regr_count int, regr_avgx float, regr_avgy float)
│ estimated row count: 1
│ render 0: ((avg)[decimal]::FLOAT8)[float]
│ render 1: (to_hex((xor_agg)[bytes]))[string]
Expand All @@ -145,9 +149,11 @@ vectorized: false
│ render 19: (regr_sxy)[float]
│ render 20: (regr_syy)[float]
│ render 21: (count_rows)[int]
│ render 22: (regr_avgx)[float]
│ render 23: (regr_avgy)[float]
└── • group (scalar)
│ columns: (min int, count int, max int, sum_int int, avg decimal, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, xor_agg bytes, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, count_rows int)
│ columns: (min int, count int, max int, sum_int int, avg decimal, sum decimal, stddev decimal, variance decimal, bool_and bool, bool_or bool, xor_agg bytes, corr float, covar_pop float, covar_samp float, sqrdiff decimal, regr_intercept float, regr_r2 float, regr_slope float, regr_sxx float, regr_sxy float, regr_syy float, count_rows int, regr_avgx float, regr_avgy float)
│ estimated row count: 1
│ aggregate 0: min(column1)
│ aggregate 1: count(column3)
Expand All @@ -171,6 +177,8 @@ vectorized: false
│ aggregate 19: regr_sxy(column1, column1)
│ aggregate 20: regr_syy(column1, column1)
│ aggregate 21: count_rows()
│ aggregate 22: regr_avgx(column1, column1)
│ aggregate 23: regr_avgy(column1, column1)
└── • values
columns: (column1 int, column3 unknown, column11 bool, column14 bytes)
Expand Down
29 changes: 15 additions & 14 deletions pkg/sql/opt/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ var AggregateOpReverseMap = map[Operator]string{
CovarPopOp: "covar_pop",
CovarSampOp: "covar_samp",
RegressionAvgXOp: "regr_avgx",
RegressionAvgYOp: "regr_avgy",
RegressionInterceptOp: "regr_intercept",
RegressionR2Op: "regr_r2",
RegressionSlopeOp: "regr_slope",
Expand Down Expand Up @@ -318,9 +319,9 @@ func AggregateIgnoresNulls(op Operator) bool {
ConstNotNullAggOp, CorrOp, CountOp, MaxOp, MinOp, SqrDiffOp, StdDevOp,
StringAggOp, SumOp, SumIntOp, VarianceOp, XorAggOp, PercentileDiscOp,
PercentileContOp, STMakeLineOp, STCollectOp, STExtentOp, STUnionOp, StdDevPopOp,
VarPopOp, CovarPopOp, CovarSampOp, RegressionAvgXOp, RegressionInterceptOp,
RegressionR2Op, RegressionSlopeOp, RegressionSXXOp, RegressionSXYOp,
RegressionSYYOp, RegressionCountOp:
VarPopOp, CovarPopOp, CovarSampOp, RegressionAvgXOp, RegressionAvgYOp,
RegressionInterceptOp, RegressionR2Op, RegressionSlopeOp, RegressionSXXOp,
RegressionSXYOp, RegressionSYYOp, RegressionCountOp:
return true

case ArrayAggOp, ConcatAggOp, ConstAggOp, CountRowsOp, FirstAggOp, JsonAggOp,
Expand All @@ -344,9 +345,9 @@ func AggregateIsNullOnEmpty(op Operator) bool {
MaxOp, MinOp, SqrDiffOp, StdDevOp, STMakeLineOp, StringAggOp, SumOp, SumIntOp,
VarianceOp, XorAggOp, PercentileDiscOp, PercentileContOp,
JsonObjectAggOp, JsonbObjectAggOp, StdDevPopOp, STCollectOp, STExtentOp, STUnionOp,
VarPopOp, CovarPopOp, CovarSampOp, RegressionAvgXOp, RegressionInterceptOp,
RegressionR2Op, RegressionSlopeOp, RegressionSXXOp, RegressionSXYOp,
RegressionSYYOp:
VarPopOp, CovarPopOp, CovarSampOp, RegressionAvgXOp, RegressionAvgYOp,
RegressionInterceptOp, RegressionR2Op, RegressionSlopeOp, RegressionSXXOp,
RegressionSXYOp, RegressionSYYOp:
return true

case CountOp, CountRowsOp, RegressionCountOp:
Expand All @@ -373,8 +374,8 @@ func AggregateIsNeverNullOnNonNullInput(op Operator) bool {
JsonAggOp, JsonbAggOp, MaxOp, MinOp, SqrDiffOp, STMakeLineOp,
StringAggOp, SumOp, SumIntOp, XorAggOp, PercentileDiscOp, PercentileContOp,
JsonObjectAggOp, JsonbObjectAggOp, StdDevPopOp, STCollectOp, STExtentOp, STUnionOp,
VarPopOp, CovarPopOp, RegressionAvgXOp, RegressionSXXOp, RegressionSXYOp,
RegressionSYYOp, RegressionCountOp:
VarPopOp, CovarPopOp, RegressionAvgXOp, RegressionAvgYOp, RegressionSXXOp,
RegressionSXYOp, RegressionSYYOp, RegressionCountOp:
return true

case VarianceOp, StdDevOp, CorrOp, CovarSampOp, RegressionInterceptOp,
Expand Down Expand Up @@ -427,9 +428,9 @@ func AggregatesCanMerge(inner, outer Operator) bool {
case ArrayAggOp, AvgOp, ConcatAggOp, CorrOp, JsonAggOp, JsonbAggOp,
JsonObjectAggOp, JsonbObjectAggOp, PercentileContOp, PercentileDiscOp,
SqrDiffOp, STCollectOp, StdDevOp, StringAggOp, VarianceOp, StdDevPopOp,
VarPopOp, CovarPopOp, CovarSampOp, RegressionAvgXOp, RegressionInterceptOp,
RegressionR2Op, RegressionSlopeOp, RegressionSXXOp, RegressionSXYOp,
RegressionSYYOp, RegressionCountOp:
VarPopOp, CovarPopOp, CovarSampOp, RegressionAvgXOp, RegressionAvgYOp,
RegressionInterceptOp, RegressionR2Op, RegressionSlopeOp, RegressionSXXOp,
RegressionSXYOp, RegressionSYYOp, RegressionCountOp:
return false

default:
Expand All @@ -449,9 +450,9 @@ func AggregateIgnoresDuplicates(op Operator) bool {
SumOp, SqrDiffOp, VarianceOp, StdDevOp, XorAggOp, JsonAggOp, JsonbAggOp,
StringAggOp, PercentileDiscOp, PercentileContOp, StdDevPopOp, STMakeLineOp,
VarPopOp, JsonObjectAggOp, JsonbObjectAggOp, STCollectOp, CovarPopOp,
CovarSampOp, RegressionAvgXOp, RegressionInterceptOp, RegressionR2Op,
RegressionSlopeOp, RegressionSXXOp, RegressionSXYOp, RegressionSYYOp,
RegressionCountOp:
CovarSampOp, RegressionAvgXOp, RegressionAvgYOp, RegressionInterceptOp,
RegressionR2Op, RegressionSlopeOp, RegressionSXXOp, RegressionSXYOp,
RegressionSYYOp, RegressionCountOp:
return false

default:
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/opt/ops/scalar.opt
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,12 @@ define RegressionAvgX {
X ScalarExpr
}

[Scalar, Aggregate]
define RegressionAvgY {
Y ScalarExpr
X ScalarExpr
}

[Scalar, Aggregate]
define RegressionIntercept {
Y ScalarExpr
Expand Down
Loading

0 comments on commit 557bc72

Please sign in to comment.