Skip to content

Commit

Permalink
Merge pull request #19 from go-jet/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
go-jet authored Oct 4, 2019
2 parents e3290ce + 258468c commit 02fafd8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/jet/func_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ func EVERY(boolExpression BoolExpression) boolWindowExpression {
return newBoolWindowFunc("EVERY", boolExpression)
}

// MAX is aggregate function. Returns minimum value of expression across all input values.
func MAX(expression Expression) Expression {
return newWindowFunc("MAX", expression)
}

// MAXf is aggregate function. Returns maximum value of float expression across all input values
func MAXf(floatExpression FloatExpression) floatWindowExpression {
return NewFloatWindowFunc("MAX", floatExpression)
Expand All @@ -125,6 +130,11 @@ func MAXi(integerExpression IntegerExpression) integerWindowExpression {
return newIntegerWindowFunc("MAX", integerExpression)
}

// MIN is aggregate function. Returns minimum value of expression across all input values.
func MIN(expression Expression) Expression {
return newWindowFunc("MIN", expression)
}

// MINf is aggregate function. Returns minimum value of float expression across all input values
func MINf(floatExpression FloatExpression) floatWindowExpression {
return NewFloatWindowFunc("MIN", floatExpression)
Expand Down
16 changes: 16 additions & 0 deletions internal/jet/func_expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ func TestFuncEVERY(t *testing.T) {
}

func TestFuncMIN(t *testing.T) {
t.Run("expression", func(t *testing.T) {
assertClauseSerialize(t, MIN(table1ColDate), "MIN(table1.col_date)")
assertClauseSerialize(t, MIN(Date(2001, 1, 1)), "MIN($1)", "2001-01-01")
assertClauseSerialize(t, MIN(Time(12, 10, 10)), "MIN($1)", "12:10:10")
assertClauseSerialize(t, MIN(Timestamp(2001, 1, 1, 12, 10, 10)), "MIN($1)", "2001-01-01 12:10:10")
assertClauseSerialize(t, MIN(Timestampz(2001, 1, 1, 12, 10, 10, 1, "UTC")), "MIN($1)", "2001-01-01 12:10:10.000000001 UTC")
})

t.Run("float", func(t *testing.T) {
assertClauseSerialize(t, MINf(table1ColFloat), "MIN(table1.col_float)")
})
Expand All @@ -40,6 +48,14 @@ func TestFuncMIN(t *testing.T) {
}

func TestFuncMAX(t *testing.T) {
t.Run("expression", func(t *testing.T) {
assertClauseSerialize(t, MAX(table1ColDate), "MAX(table1.col_date)")
assertClauseSerialize(t, MAX(Date(2001, 1, 1)), "MAX($1)", "2001-01-01")
assertClauseSerialize(t, MAX(Time(12, 10, 10)), "MAX($1)", "12:10:10")
assertClauseSerialize(t, MAX(Timestamp(2001, 1, 1, 12, 10, 10)), "MAX($1)", "2001-01-01 12:10:10")
assertClauseSerialize(t, MAX(Timestampz(2001, 1, 1, 12, 10, 10, 1, "UTC")), "MAX($1)", "2001-01-01 12:10:10.000000001 UTC")
})

t.Run("float", func(t *testing.T) {
assertClauseSerialize(t, MAXf(table1ColFloat), "MAX(table1.col_float)")
assertClauseSerialize(t, MAXf(Float(11.2222)), "MAX($1)", float64(11.2222))
Expand Down
6 changes: 6 additions & 0 deletions mysql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,18 @@ var BIT_OR = jet.BIT_OR
// COUNT is aggregate function. Returns number of input rows for which the value of expression is not null.
var COUNT = jet.COUNT

// MAX is aggregate function. Returns maximum value of expression across all input values
var MAX = jet.MAX

// MAXi is aggregate function. Returns maximum value of int expression across all input values
var MAXi = jet.MAXi

// MAXf is aggregate function. Returns maximum value of float expression across all input values
var MAXf = jet.MAXf

// MIN is aggregate function. Returns minimum value of int expression across all input values
var MIN = jet.MIN

// MINi is aggregate function. Returns minimum value of int expression across all input values
var MINi = jet.MINi

Expand Down
6 changes: 6 additions & 0 deletions postgres/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ var COUNT = jet.COUNT
// EVERY is aggregate function. Returns true if all input values are true, otherwise false
var EVERY = jet.EVERY

// MAXf is aggregate function. Returns maximum value of expression across all input values
var MAX = jet.MAX

// MAXf is aggregate function. Returns maximum value of float expression across all input values
var MAXf = jet.MAXf

// MAXi is aggregate function. Returns maximum value of int expression across all input values
var MAXi = jet.MAXi

// MIN is aggregate function. Returns minimum value of expression across all input values.
var MIN = jet.MIN

// MINf is aggregate function. Returns minimum value of float expression across all input values
var MINf = jet.MINf

Expand Down
4 changes: 4 additions & 0 deletions tests/mysql/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ SELECT customer.customer_id AS "customer.customer_id",
customer.last_update AS "customer.last_update",
SUM(payment.amount) AS "amount.sum",
AVG(payment.amount) AS "amount.avg",
MAX(payment.payment_date) AS "amount.max_date",
MAX(payment.amount) AS "amount.max",
MIN(payment.payment_date) AS "amount.min_date",
MIN(payment.amount) AS "amount.min",
COUNT(payment.amount) AS "amount.count"
FROM dvds.payment
Expand All @@ -103,7 +105,9 @@ ORDER BY payment.customer_id, SUM(payment.amount) ASC;

SUMf(Payment.Amount).AS("amount.sum"),
AVG(Payment.Amount).AS("amount.avg"),
MAX(Payment.PaymentDate).AS("amount.max_date"),
MAXf(Payment.Amount).AS("amount.max"),
MIN(Payment.PaymentDate).AS("amount.min_date"),
MINf(Payment.Amount).AS("amount.min"),
COUNT(Payment.Amount).AS("amount.count"),
).
Expand Down
4 changes: 4 additions & 0 deletions tests/postgres/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,9 @@ SELECT customer.customer_id AS "customer.customer_id",
customer.active AS "customer.active",
SUM(payment.amount) AS "amount.sum",
AVG(payment.amount) AS "amount.avg",
MAX(payment.payment_date) AS "amount.max_date",
MAX(payment.amount) AS "amount.max",
MIN(payment.payment_date) AS "amount.min_date",
MIN(payment.amount) AS "amount.min",
COUNT(payment.amount) AS "amount.count"
FROM dvds.payment
Expand All @@ -1025,7 +1027,9 @@ ORDER BY customer.customer_id, SUM(payment.amount) ASC;

SUMf(Payment.Amount).AS("amount.sum"),
AVG(Payment.Amount).AS("amount.avg"),
MAX(Payment.PaymentDate).AS("amount.max_date"),
MAXf(Payment.Amount).AS("amount.max"),
MIN(Payment.PaymentDate).AS("amount.min_date"),
MINf(Payment.Amount).AS("amount.min"),
COUNT(Payment.Amount).AS("amount.count"),
).
Expand Down

0 comments on commit 02fafd8

Please sign in to comment.