-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable
min
& max
to work on all the data types and across data ty… (
#604)
- Loading branch information
Showing
8 changed files
with
329 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
lang/test/org/partiql/lang/eval/builtins/aggfunctions/AvgTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.partiql.lang.eval.builtins.aggfunctions | ||
|
||
import org.junit.Test | ||
import org.partiql.lang.errors.ErrorCode | ||
import org.partiql.lang.eval.EvaluatorTestBase | ||
|
||
class AvgTests : EvaluatorTestBase() { | ||
@Test | ||
fun avgNull() = runEvaluatorTestCase("AVG([null, null])", expectedResult = "null") | ||
|
||
@Test | ||
fun avgMissing() = runEvaluatorTestCase("AVG([missing, missing])", expectedResult = "null") | ||
|
||
@Test | ||
fun avgInt() = runEvaluatorTestCase("AVG(`[1, 2, 3]`)", expectedResult = "2.") | ||
|
||
@Test | ||
fun avgMixed0() = runEvaluatorTestCase("AVG(`[1, 2e0, 3e0]`)", expectedResult = "2.") | ||
|
||
@Test | ||
fun avgMixed1() = runEvaluatorTestCase("AVG(`[1, 2d0, 3d0]`)", expectedResult = "2.") | ||
|
||
@Test | ||
fun avgMixed2() = runEvaluatorTestCase("AVG(`[1, 2e0, 3d0]`)", expectedResult = "2.") | ||
|
||
@Test | ||
fun avgMixed3() = runEvaluatorTestCase("AVG(`[1, 2d0, 3e0]`)", expectedResult = "2.") | ||
|
||
@Test | ||
fun avgOverflow() = runEvaluatorErrorTestCase( | ||
"AVG([1, 9223372036854775807])", | ||
ErrorCode.EVALUATOR_INTEGER_OVERFLOW, | ||
expectedPermissiveModeResult = "MISSING" | ||
) | ||
|
||
@Test | ||
fun avgUnderflow() = runEvaluatorErrorTestCase( | ||
"AVG([-1, -9223372036854775808])", | ||
ErrorCode.EVALUATOR_INTEGER_OVERFLOW, | ||
expectedPermissiveModeResult = "MISSING" | ||
) | ||
} |
57 changes: 57 additions & 0 deletions
57
lang/test/org/partiql/lang/eval/builtins/aggfunctions/CountTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.partiql.lang.eval.builtins.aggfunctions | ||
|
||
import org.junit.Test | ||
import org.partiql.lang.eval.EvaluatorTestBase | ||
|
||
class CountTests : EvaluatorTestBase() { | ||
@Test | ||
fun countEmpty() = runEvaluatorTestCase("COUNT(`[]`)", expectedResult = "0") | ||
|
||
@Test | ||
fun countNull() = runEvaluatorTestCase("COUNT([null, null])", expectedResult = "0") | ||
|
||
@Test | ||
fun countMissing() = runEvaluatorTestCase("COUNT([missing])", expectedResult = "0") | ||
|
||
@Test | ||
fun countBoolean() = runEvaluatorTestCase("COUNT(`[true, false]`)", expectedResult = "2") | ||
|
||
@Test | ||
fun countInt() = runEvaluatorTestCase("COUNT(`[1, 2, 3]`)", expectedResult = "3") | ||
|
||
@Test | ||
fun countDecimal() = runEvaluatorTestCase("COUNT(`[1e0, 2e0, 3e0]`)", expectedResult = "3") | ||
|
||
@Test | ||
fun countFloat() = runEvaluatorTestCase("COUNT(`[1e0, 2e0, 3e0]`)", expectedResult = "3") | ||
|
||
@Test | ||
fun countString() = runEvaluatorTestCase("COUNT(`[\"1\", \"2\", \"3\"]`)", expectedResult = "3") | ||
|
||
@Test | ||
fun countTimestamp() = runEvaluatorTestCase("COUNT(`[2020-01-01T00:00:00Z, 2020-01-01T00:00:01Z]`)", expectedResult = "2") | ||
|
||
@Test | ||
fun countBlob() = runEvaluatorTestCase("COUNT(`[{{ aaaa }}, {{ aaab }}]`)", expectedResult = "2") | ||
|
||
@Test | ||
fun countClob() = runEvaluatorTestCase("COUNT(`[{{ \"aaaa\" }}, {{ \"aaab\" }}]`)", expectedResult = "2") | ||
|
||
@Test | ||
fun countSexp() = runEvaluatorTestCase("COUNT(`[(1), (2)]`)", expectedResult = "2") | ||
|
||
@Test | ||
fun countList() = runEvaluatorTestCase("COUNT(`[[1], [2]]`)", expectedResult = "2") | ||
|
||
@Test | ||
fun countBag() = runEvaluatorTestCase("COUNT([<<1>>, <<2>>])", expectedResult = "2") | ||
|
||
@Test | ||
fun countStruct() = runEvaluatorTestCase("COUNT(`[{'a':1}, {'a':2}]`)", expectedResult = "2") | ||
|
||
@Test | ||
fun countMixed0() = runEvaluatorTestCase("COUNT([null, missing, 1, 2])", expectedResult = "2") | ||
|
||
@Test | ||
fun countMixed1() = runEvaluatorTestCase("COUNT([1, '2', true, `2020-01-01T00:00:00Z`, `{{ aaaa }}`])", expectedResult = "5") | ||
} |
78 changes: 78 additions & 0 deletions
78
lang/test/org/partiql/lang/eval/builtins/aggfunctions/MaxTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.partiql.lang.eval.builtins.aggfunctions | ||
|
||
import org.junit.Test | ||
import org.partiql.lang.eval.EvaluatorTestBase | ||
|
||
class MaxTests : EvaluatorTestBase() { | ||
@Test | ||
fun maxNull() = runEvaluatorTestCase("max([null, null])", expectedResult = "null") | ||
|
||
@Test | ||
fun maxMissing() = runEvaluatorTestCase("max([missing, missing])", expectedResult = "null") | ||
|
||
@Test | ||
fun maxNumber0() = runEvaluatorTestCase("max(`[1, 2, 3]`)", expectedResult = "3") | ||
|
||
@Test | ||
fun maxNumber1() = runEvaluatorTestCase("max(`[1, 2.0, 3]`)", expectedResult = "3") | ||
|
||
@Test | ||
fun maxNumber2() = runEvaluatorTestCase("max(`[1, 2e0, 3e0]`)", expectedResult = "3e0") | ||
|
||
@Test | ||
fun maxNumber3() = runEvaluatorTestCase("max(`[1, 2d0, 3d0]`)", expectedResult = "3d0") | ||
|
||
@Test | ||
fun maxNumber4() = runEvaluatorTestCase("max(`[1, 2e0, 3d0]`)", expectedResult = "3d0") | ||
|
||
@Test | ||
fun maxNumber5() = runEvaluatorTestCase("max(`[1, 2d0, 3e0]`)", expectedResult = "3e0") | ||
|
||
@Test | ||
fun maxString0() = runEvaluatorTestCase("max(['a', 'abc', '3'])", expectedResult = "\"abc\"") | ||
|
||
@Test | ||
fun maxString1() = runEvaluatorTestCase("max(['1', '2', '3', null])", expectedResult = "\"3\"") | ||
|
||
@Test | ||
fun maxTimestamp0() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, `2020-01-01T00:00:01Z`, `2020-01-01T00:00:02Z`])", expectedResult = "2020-01-01T00:00:02Z") | ||
|
||
@Test | ||
fun maxTimestamp1() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, `2020-01-01T00:01:00Z`, `2020-01-01T00:02:00Z`])", expectedResult = "2020-01-01T00:02:00Z") | ||
|
||
@Test | ||
fun maxTimestamp2() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, `2020-01-01T01:00:00Z`, `2020-01-01T02:00:00Z`])", expectedResult = "2020-01-01T02:00:00Z") | ||
|
||
@Test | ||
fun maxTimestamp3() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, `2020-01-02T00:00:00Z`, `2020-01-03T00:00:00Z`])", expectedResult = "2020-01-03T00:00:00Z") | ||
|
||
@Test | ||
fun maxTimestamp4() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, `2020-02-01T00:00:00Z`, `2020-03-01T00:00:00Z`])", expectedResult = "2020-03-01T00:00:00Z") | ||
|
||
@Test | ||
fun maxTimestamp5() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, `2021-01-01T00:00:00Z`, `2022-01-01T00:00:00Z`])", expectedResult = "2022-01-01T00:00:00Z") | ||
|
||
@Test | ||
fun maxTimestamp6() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, `2020-01-01T00:00:01Z`, `2020-01-01T00:00:02Z`, null])", expectedResult = "2020-01-01T00:00:02Z") | ||
|
||
@Test | ||
fun maxBoolean() = runEvaluatorTestCase("max([false, true])", expectedResult = "true") | ||
|
||
@Test | ||
fun maxBlob() = runEvaluatorTestCase("max([`{{ aaaa }}`, `{{ aaab }}`])", expectedResult = "{{aaab}}") | ||
|
||
@Test | ||
fun maxClob() = runEvaluatorTestCase("max([`{{\"a\"}}`, `{{\"b\"}}`])", expectedResult = "{{\"b\"}}") | ||
|
||
@Test | ||
fun maxMixed0() = runEvaluatorTestCase("max([false, 1])", expectedResult = "1") | ||
|
||
@Test | ||
fun maxMixed1() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, 1])", expectedResult = "2020-01-01T00:00:00Z") | ||
|
||
@Test | ||
fun maxMixed2() = runEvaluatorTestCase("max([`2020-01-01T00:00:00Z`, '1'])", expectedResult = "\"1\"") | ||
|
||
@Test | ||
fun maxMixed3() = runEvaluatorTestCase("max([`{{\"abcd\"}}`, '1'])", expectedResult = "{{\"abcd\"}}") | ||
} |
Oops, something went wrong.