-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FILTER_DISTINCT function. #589
Merged
dlurton
merged 6 commits into
physical-plan-staging
from
physical-plan-staging-filter-distinct
May 19, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48a003e
Add 3 query planner passes.
dlurton a5bd78b
Address build failures
dlurton befac52
Add FILTER_DISTINCT ExprFunction
dlurton 69e709a
Merge branch 'physical-plan-staging' into physical-plan-staging-filte…
dlurton 8481fb1
Fix errors after merge
dlurton f7bf1cd
Remove another file left behind after merge
dlurton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
73 changes: 73 additions & 0 deletions
73
lang/test/org/partiql/lang/eval/builtins/functions/FilterDistinctEvaluationTest.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,73 @@ | ||
package org.partiql.lang.eval.builtins.functions | ||
|
||
import org.junit.Test | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.ArgumentsSource | ||
import org.partiql.lang.errors.ErrorCode | ||
import org.partiql.lang.errors.Property | ||
import org.partiql.lang.eval.EvaluatorTestBase | ||
import org.partiql.lang.eval.builtins.ExprFunctionTestCase | ||
import org.partiql.lang.eval.builtins.checkInvalidArity | ||
import org.partiql.lang.util.ArgumentsProviderBase | ||
import org.partiql.lang.util.propertyValueMapOf | ||
import org.partiql.lang.util.to | ||
|
||
class FilterDistinctEvaluationTest : EvaluatorTestBase() { | ||
// Pass test cases | ||
@ParameterizedTest | ||
@ArgumentsSource(ToStringPassCases::class) | ||
fun runPassTests(testCase: ExprFunctionTestCase) = | ||
runEvaluatorTestCase(query = testCase.source, expectedResult = testCase.expectedLegacyModeResult) | ||
|
||
// We rely on the built-in [DEFAULT_COMPARATOR] for the actual definition of equality, which is not being tested | ||
// here. | ||
class ToStringPassCases : ArgumentsProviderBase() { | ||
override fun getParameters(): List<Any> = listOf( | ||
|
||
// These three tests ensure we can accept lists, bags, s-expressions and structs | ||
ExprFunctionTestCase("filter_distinct([0, 0, 1])", "[0, 1]"), // list | ||
ExprFunctionTestCase("filter_distinct(<<0, 0, 1>>)", "[0, 1]"), // bag | ||
ExprFunctionTestCase("filter_distinct(SEXP(0, 0, 1))", "[0, 1]"), // s-exp | ||
ExprFunctionTestCase("filter_distinct({'a': 0, 'b': 0, 'c': 1})", "[0, 1]"), // struct | ||
|
||
// Some "smoke tests" to ensure the basic plumbing is working right. | ||
ExprFunctionTestCase("filter_distinct(['foo', 'foo', 1, 1, `symbol`, `symbol`])", "[\"foo\", 1, symbol]"), | ||
ExprFunctionTestCase("filter_distinct([{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }])", "[{ 'a': 1 }]"), | ||
ExprFunctionTestCase("filter_distinct([[1, 1], [1, 1], [2, 2]])", "[[1,1], [2, 2]]"), | ||
) | ||
} | ||
|
||
// Error test cases: Invalid arguments | ||
data class InvalidArgTestCase( | ||
val source: String, | ||
val actualArgumentType: String | ||
) | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(InvalidArgCases::class) | ||
fun toStringInvalidArgumentTests(testCase: InvalidArgTestCase) = runEvaluatorErrorTestCase( | ||
query = testCase.source, | ||
expectedErrorCode = ErrorCode.EVALUATOR_INCORRECT_TYPE_OF_ARGUMENTS_TO_FUNC_CALL, | ||
expectedErrorContext = propertyValueMapOf( | ||
1, 1, | ||
Property.FUNCTION_NAME to "filter_distinct", | ||
Property.EXPECTED_ARGUMENT_TYPES to "BAG, LIST, SEXP, or STRUCT", | ||
Property.ACTUAL_ARGUMENT_TYPES to testCase.actualArgumentType, | ||
Property.ARGUMENT_POSITION to 1 | ||
), | ||
expectedPermissiveModeResult = "MISSING", | ||
) | ||
|
||
class InvalidArgCases : ArgumentsProviderBase() { | ||
override fun getParameters(): List<Any> = listOf( | ||
InvalidArgTestCase("filter_distinct(1)", "INT"), | ||
InvalidArgTestCase("filter_distinct(1.0)", "DECIMAL"), | ||
InvalidArgTestCase("filter_distinct('foo')", "STRING"), | ||
InvalidArgTestCase("filter_distinct(`some_symbol`)", "SYMBOL"), | ||
InvalidArgTestCase("filter_distinct(`{{ '''a clob''' }}`)", "CLOB"), | ||
) | ||
} | ||
|
||
@Test | ||
fun invalidArityTest() = checkInvalidArity(funcName = "filter_distinct", maxArity = 1, minArity = 1) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful for PartiQL to have the equivalent of Ion Hash for use cases like this.