Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

add greatest and least #700

Merged
merged 7 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ We support and actively test against certain third-party clients to ensure compa
|`DAYOFYEAR(date)`|Returns the day of the year of the given date.|
|`FLOOR(number)`|Return the largest integer value that is less than or equal to `number`.|
|`FROM_BASE64(str)`|Decodes the base64-encoded string str.|
|`GREATEST(...)`|Returns the greatest numeric or string value.|
|`HOUR(date)`|Returns the hours of the given date.|
juanjux marked this conversation as resolved.
Show resolved Hide resolved
|`IFNULL(expr1, expr2)`|If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2.|
|`IS_BINARY(blob)`|Returns whether a BLOB is a binary file or not.|
|`JSON_EXTRACT(json_doc, path, ...)`|Extracts data from a json document using json paths.|
|`LEAST(...)`|Returns the smaller numeric or string value.|
|`LN(X)`|Return the natural logarithm of X.|
|`LOG(X), LOG(B, X)`|If called with one parameter, this function returns the natural logarithm of X. If called with two parameters, this function returns the logarithm of X to the base B. If X is less than or equal to 0, or if B is less than or equal to 1, then NULL is returned.|
|`LOG10(X)`|Returns the base-10 logarithm of X.|
Expand Down
46 changes: 24 additions & 22 deletions SUPPORTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,50 @@

## Functions
- ARRAY_LENGTH
- CEIL
- CEILING
- COALESCE
- CONCAT
- CONCAT_WS
- CONNECTION_ID
- DATABASE
- FLOOR
- FROM_BASE64
- GREATEST
- IS_BINARY
- SPLIT
- SUBSTRING
- IS_BINARY
- LOWER
- UPPER
- CEILING
- CEIL
- FLOOR
- ROUND
- COALESCE
- CONNECTION_ID
- SOUNDEX
- JSON_EXTRACT
- DATABASE
- SQRT
- LEAST
- LN
- LOG10
- LOG2
- LOWER
- LPAD
- POW
- POWER
- ROUND
- RPAD
- LPAD
- LN
- LOG2
- LOG10
- SLEEP
- SOUNDEX
- SPLIT
- SQRT
- SUBSTRING
- TO_BASE64
- FROM_BASE64
- UPPER

## Time functions
- DATE
- DATE_ADD
- DATE_SUB
- DAY
- WEEKDAY
- DAYOFMONTH
- DAYOFWEEK
- DAYOFYEAR
- HOUR
- MINUTE
- MONTH
- NOW
- SECOND
- WEEKDAY
- YEAR
- YEARWEEK
- NOW
- DATE_ADD
- DATE_SUB
40 changes: 40 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,46 @@ var queries = []struct {
`SELECT JSON_EXTRACT('[1, 2, 3]', '$.[0]')`,
[]sql.Row{{float64(1)}},
},
{
`SELECT GREATEST(1, 2, 3, 4)`,
[]sql.Row{{int64(4)}},
},
{
`SELECT GREATEST(1, 2, "3", 4)`,
[]sql.Row{{float64(4)}},
},
{
`SELECT GREATEST(1, 2, "9", "foo999")`,
[]sql.Row{{float64(9)}},
},
{
`SELECT GREATEST("aaa", "bbb", "ccc")`,
[]sql.Row{{"ccc"}},
},
{
`SELECT GREATEST(i, s) FROM mytable`,
[]sql.Row{{float64(1)}, {float64(2)}, {float64(3)}},
},
{
`SELECT LEAST(1, 2, 3, 4)`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some tests using strings too?

Copy link
Contributor

@erizocosmico erizocosmico May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And some tests using table columns too, please

Copy link
Contributor Author

@juanjux juanjux May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajnavarro there are already tests with strings on greatest_latest_test.go (the ones called "all strings", "all strings and empty", and a couple mixing strings with other types).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajnavarro , @erizocosmico added tests with strings and tables to this file, PTAL.

[]sql.Row{{int64(1)}},
},
{
`SELECT LEAST(1, 2, "3", 4)`,
[]sql.Row{{float64(1)}},
},
{
`SELECT LEAST(1, 2, "9", "foo999")`,
[]sql.Row{{float64(1)}},
},
{
`SELECT LEAST("aaa", "bbb", "ccc")`,
[]sql.Row{{"aaa"}},
},
{
`SELECT LEAST(i, s) FROM mytable`,
[]sql.Row{{float64(1)}, {float64(2)}, {float64(3)}},
},
}

func TestQueries(t *testing.T) {
Expand Down
Loading