on dev help sign in
add more stats functions
444dcf5Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+105−9
@@ -1396,8 +1396,6 @@ aggregation
1396class Aggregate expr1 expr2 aggr
1396class Aggregate expr1 expr2 aggr
1397 | aggr -> expr1, aggr -> expr2 where
1397 | aggr -> expr1, aggr -> expr2 where
1398
1398
1399−
1400−
1401 -- | A special aggregation that does not require an input
1399 -- | A special aggregation that does not require an input
1402 --
1400 --
1403 -- >>> :{
1401 -- >>> :{
@@ -1497,13 +1495,13 @@ class Aggregate expr1 expr2 aggr
1497 -- ^ what to aggregate
1495 -- ^ what to aggregate
1498 -> aggr (nullity 'PGbool)
1496 -> aggr (nullity 'PGbool)
1499
1497
1500− -- | maximum aggregation
1498+ -- | maximum value of expression across all input values
1501 max_
1499 max_
1502 :: expr1 (nullity ty)
1500 :: expr1 (nullity ty)
1503 -- ^ what to maximize
1501 -- ^ what to maximize
1504 -> aggr (nullity ty)
1502 -> aggr (nullity ty)
1505
1503
1506− -- | minimum aggregation
1504+ -- | minimum value of expression across all input values
1507 min_
1505 min_
1508 :: expr1 (nullity ty)
1506 :: expr1 (nullity ty)
1509 -- ^ what to minimize
1507 -- ^ what to minimize
@@ -1515,31 +1513,103 @@ class Aggregate expr1 expr2 aggr
1515 -- ^ what to average
1513 -- ^ what to average
1516 -> aggr (nullity (PGAvg ty))
1514 -> aggr (nullity (PGAvg ty))
1517
1515
1518− -- | correlation coefficient
1516+ -- | @corr (y :*: x)@, correlation coefficient
1519 corr
1517 corr
1520 :: expr2 (nullity 'PGfloat8)
1518 :: expr2 (nullity 'PGfloat8)
1521 -> aggr (nullity 'PGfloat8)
1519 -> aggr (nullity 'PGfloat8)
1522
1520
1523− -- | population covariance
1521+ -- | @covarPop (y :*: x)@, population covariance
1524 covarPop
1522 covarPop
1525 :: expr2 (nullity 'PGfloat8)
1523 :: expr2 (nullity 'PGfloat8)
1526 -> aggr (nullity 'PGfloat8)
1524 -> aggr (nullity 'PGfloat8)
1527
1525
1528− -- | sample covariance
1526+ -- | @covarPop (y :*: x)@, sample covariance
1529 covarSamp
1527 covarSamp
1530 :: expr2 (nullity 'PGfloat8)
1528 :: expr2 (nullity 'PGfloat8)
1531 -> aggr (nullity 'PGfloat8)
1529 -> aggr (nullity 'PGfloat8)
1532
1530
1533− -- | average of the independent variable (sum(X)/N)
1531+ -- | @regrAvgX (y :*: x)@, average of the independent variable (sum(X)/N)
1534 regrAvgX
1532 regrAvgX
1535 :: expr2 (nullity 'PGfloat8)
1533 :: expr2 (nullity 'PGfloat8)
1536 -> aggr (nullity 'PGfloat8)
1534 -> aggr (nullity 'PGfloat8)
1537
1535
1538− -- | average of the dependent variable (sum(Y)/N)
1536+ -- | @regrAvgY (y :*: x)@, average of the dependent variable (sum(Y)/N)
1539 regrAvgY
1537 regrAvgY
1540 :: expr2 (nullity 'PGfloat8)
1538 :: expr2 (nullity 'PGfloat8)
1541 -> aggr (nullity 'PGfloat8)
1539 -> aggr (nullity 'PGfloat8)
1542
1540
1541+ -- | @regrCount (y :*: x)@, number of input rows in which both expressions are nonnull
1542+ regrCount
1543+ :: expr2 (nullity 'PGfloat8)
1544+ -> aggr (nullity 'PGint8)
1545+
1546+ -- | @regrIntercept (y :*: x)@, y-intercept of the least-squares-fit linear
1547+ -- equation determined by the (X, Y) pairs
1548+ regrIntercept
1549+ :: expr2 (nullity 'PGfloat8)
1550+ -> aggr (nullity 'PGfloat8)
1551+
1552+ -- | @regrR2 (y :*: x)@, square of the correlation coefficient
1553+ regrR2
1554+ :: expr2 (nullity 'PGfloat8)
1555+ -> aggr (nullity 'PGfloat8)
1556+
1557+ -- | @regrSlope (y :*: x)@, slope of the least-squares-fit linear equation
1558+ -- determined by the (X, Y) pairs
1559+ regrSlope
1560+ :: expr2 (nullity 'PGfloat8)
1561+ -> aggr (nullity 'PGfloat8)
1562+
1563+ -- | @regrSxx (y :*: x)@, sum(X^2) - sum(X)^2/N
1564+ -- (“sum of squares” of the independent variable)
1565+ regrSxx
1566+ :: expr2 (nullity 'PGfloat8)
1567+ -> aggr (nullity 'PGfloat8)
1568+
1569+ -- | @regrSxy (y :*: x)@, sum(X*Y) - sum(X) * sum(Y)/N
1570+ -- (“sum of products” of independent times dependent variable)
1571+ regrSxy
1572+ :: expr2 (nullity 'PGfloat8)
1573+ -> aggr (nullity 'PGfloat8)
1574+
1575+ -- | @regrSyy (y :*: x)@, sum(Y^2) - sum(Y)^2/N
1576+ -- (“sum of squares” of the dependent variable)
1577+ regrSyy
1578+ :: expr2 (nullity 'PGfloat8)
1579+ -> aggr (nullity 'PGfloat8)
1580+
1581+ -- | historical alias for `stddevSamp`
1582+ stddev
1583+ :: expr1 (nullity ty)
1584+ -> aggr (nullity (PGAvg ty))
1585+
1586+ -- | population standard deviation of the input values
1587+ stddevPop
1588+ :: expr1 (nullity ty)
1589+ -> aggr (nullity (PGAvg ty))
1590+
1591+ -- | sample standard deviation of the input values
1592+ stddevSamp
1593+ :: expr1 (nullity ty)
1594+ -> aggr (nullity (PGAvg ty))
1595+
1596+ -- | historical alias for `varSamp`
1597+ variance
1598+ :: expr1 (nullity ty)
1599+ -> aggr (nullity (PGAvg ty))
1600+
1601+ -- | population variance of the input values
1602+ -- (square of the population standard deviation)
1603+ varPop
1604+ :: expr1 (nullity ty)
1605+ -> aggr (nullity (PGAvg ty))
1606+
1607+ -- | sample variance of the input values
1608+ -- (square of the sample standard deviation)
1609+ varSamp
1610+ :: expr1 (nullity ty)
1611+ -> aggr (nullity (PGAvg ty))
1612+
1543data Distinction expr ty
1613data Distinction expr ty
1544 = All (expr ty)
1614 = All (expr ty)
1545 | Distinct (expr ty)
1615 | Distinct (expr ty)
@@ -1580,6 +1650,19 @@ instance Aggregate
1580 covarSamp = unsafeAggregate2 "covar_samp"
1650 covarSamp = unsafeAggregate2 "covar_samp"
1581 regrAvgX = unsafeAggregate2 "regr_avgx"
1651 regrAvgX = unsafeAggregate2 "regr_avgx"
1582 regrAvgY = unsafeAggregate2 "regr_avgy"
1652 regrAvgY = unsafeAggregate2 "regr_avgy"
1653+ regrCount = unsafeAggregate2 "regr_count"
1654+ regrIntercept = unsafeAggregate2 "regr_intercept"
1655+ regrR2 = unsafeAggregate2 "regr_r2"
1656+ regrSlope = unsafeAggregate2 "regr_slope"
1657+ regrSxx = unsafeAggregate2 "regr_sxx"
1658+ regrSxy = unsafeAggregate2 "regr_sxy"
1659+ regrSyy = unsafeAggregate2 "regr_syy"
1660+ stddev = unsafeAggregate1 "stddev"
1661+ stddevPop = unsafeAggregate1 "stddev_pop"
1662+ stddevSamp = unsafeAggregate1 "stddev_samp"
1663+ variance = unsafeAggregate1 "variance"
1664+ varPop = unsafeAggregate1 "var_pop"
1665+ varSamp = unsafeAggregate1 "var_samp"
1583instance Aggregate
1666instance Aggregate
1584 (Expression grp commons schemas params from)
1667 (Expression grp commons schemas params from)
1585 (Expression grp commons schemas params from GHC.:*: Expression grp commons schemas params from)
1668 (Expression grp commons schemas params from GHC.:*: Expression grp commons schemas params from)
@@ -1600,6 +1683,19 @@ instance Aggregate
1600 covarSamp = unsafeWindowFunction2 "covar_samp"
1683 covarSamp = unsafeWindowFunction2 "covar_samp"
1601 regrAvgX = unsafeWindowFunction2 "regr_avgx"
1684 regrAvgX = unsafeWindowFunction2 "regr_avgx"
1602 regrAvgY = unsafeWindowFunction2 "regr_avgy"
1685 regrAvgY = unsafeWindowFunction2 "regr_avgy"
1686+ regrCount = unsafeWindowFunction2 "regr_count"
1687+ regrIntercept = unsafeWindowFunction2 "regr_intercept"
1688+ regrR2 = unsafeWindowFunction2 "regr_r2"
1689+ regrSlope = unsafeWindowFunction2 "regr_slope"
1690+ regrSxx = unsafeWindowFunction2 "regr_sxx"
1691+ regrSxy = unsafeWindowFunction2 "regr_sxy"
1692+ regrSyy = unsafeWindowFunction2 "regr_syy"
1693+ stddev = unsafeWindowFunction1 "stddev"
1694+ stddevPop = unsafeWindowFunction1 "stddev_pop"
1695+ stddevSamp = unsafeWindowFunction1 "stddev_samp"
1696+ variance = unsafeWindowFunction1 "variance"
1697+ varPop = unsafeWindowFunction1 "var_pop"
1698+ varSamp = unsafeWindowFunction1 "var_samp"
1603
1699
1604-- | escape hatch to define aggregate functions
1700-- | escape hatch to define aggregate functions
1605unsafeAggregate1
1701unsafeAggregate1