Skip to content
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

Ports tests from partiql-lang-kotlin's PTS #38

Merged
merged 20 commits into from
Oct 17, 2022
Merged

Ports tests from partiql-lang-kotlin's PTS #38

merged 20 commits into from
Oct 17, 2022

Conversation

alancai98
Copy link
Member

@alancai98 alancai98 commented Oct 5, 2022

Closes #7.

Ports tests from partiql-lang-kotlin PTS (https://github.com/partiql/partiql-lang-kotlin/tree/main/test/partiql-testscript/pts).

Associated Kotlin test runner PR: partiql/partiql-lang-kotlin#829 with an updated skip list.

Tests were ported using a script similar to what was used in porting the EvaluatorTestSuite.kt tests from partiql-lang-kotlin (#28). This was slightly trickier than the previous PR due to the number of tests being ported and because many of those tests did not have a PERMISSIVE/COERCE evaluation mode behavior defined.


TODO:

  • Self review of the PR and additional description since it's so large
  • ISL validation step of build fails (gives stack overflow error) on typed null values. Still sorting out if this is an error in the .isl validation file or in ISL
  • Clear up more of the typing behavior tests in the undecided directory

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@alancai98 alancai98 self-assigned this Oct 5, 2022
@alancai98
Copy link
Member Author

Build failing due to ISL validation check over typed nulls, which for some reason causes a stack overflow error. Still investigating before marking PR as ready for review.

@alancai98
Copy link
Member Author

Previous validation failure is due to amazon-ion/ion-schema-kotlin#169. Updated the required, nullable field to $any in the .isl to fix the stack overflow issue.

Copy link
Member Author

@alancai98 alancai98 left a comment

Choose a reason for hiding this comment

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

Most of the diff is from these ported PTS files:

  • select-mysql.ion
  • select-postgresql.ion

@@ -0,0 +1,3 @@
Directory contains tests that are not formally part of the PartiQL specification or SQL-92. These tests may contain
Copy link
Member Author

Choose a reason for hiding this comment

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

Decided to create this directory to hold tests that aren't part of the PartiQL or SQL-92 spec. Currently contains

Copy link
Member Author

Choose a reason for hiding this comment

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

In the future, this could be a good directory to also put tests with ambiguous behavior that will be sorted out in the future.

@@ -122,7 +122,7 @@ type::{
type: struct,
fields: {
result: { type: symbol, valid_values: [EvaluationSuccess], occurs: required },
output: nullable::{ occurs: required },
output: { type: $any, occurs: required },
Copy link
Member Author

Choose a reason for hiding this comment

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

Change was due to a stack overflow bug (existing issue: amazon-ion/ion-schema-kotlin#169) when validating typed nulls.

Copy link
Contributor

Choose a reason for hiding this comment

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

So you mean if we didn't have the bug we would go with nullable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, if the ion-schema-kotlin bug mentioned in amazon-ion/ion-schema-kotlin#169 didn't exist, then we could go with the previous approach (i.e. nullable::{ occurs: required }), which imo was more understandable. The change here is an equivalent way to specify a nullable, required field.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case can we add a TODO with reference to the bug? last time I checked we didn't have issue with adding comments in .ion files but not sure about .isl.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a TODO linking to the bug in 7065d48.

Regarding comments, it was mostly a concern related to standardizing the .ion test file formatting: #31. There shouldn't be an issue with adding comments to .isl for now.

@@ -61,3 +61,79 @@
result: SyntaxFail
},
}

'select-star'::[
Copy link
Member Author

Choose a reason for hiding this comment

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

PTS didn't distinguish between different error categories, so ported some tests from PTS that were syntax errors. From my read of the SQL-92 BNF, select star with other select list items is not permitted. PostgreSQL does allow some of the following cases, while others like MySQL gives a syntax error. From a discussion with Almann, we couldn't think of a use case where a user would want select star with other projection items, so it may be something we want to disallow in a future spec RFC.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it makes sense to put these tests under partiql namespace to re-iterate the fact that they are not necessarily SQL conformed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it would probably make some sense to indicate that these tests are not necessarily SQL-conformant. I'll wrap these tests in a partiql namespace and add a comment in the next commit.

],
]

invalid_function_args::[
Copy link
Member Author

Choose a reason for hiding this comment

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

Function calls with no schema present in STRICT/ERROR typing mode give errors with mistyped function arguments and return MISSING in PERMISSIVE/COERCE mode. But since a literal is provided in these tests, a static analysis pass could determine that the query has a mistyped argument and give an error.

From discussion with Almann, we determined that these cases (i.e. mistyped function args with statically-knowable types) should "fail-fast" and not wait till evaluation time. Similar reasoning applies to the other static-analysis tests ported in this PR. This type of static-time error will probably necessitate some RFC.

Copy link
Member

Choose a reason for hiding this comment

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

Are you saying the StaticAnalysisFail symbol may be a richer element, and the RFC will define this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what you meant by a "richer element". Could you clarify?

The tests in the fail/static-analysis directory define tests that will fail at some stage of static analysis or type-checking. These particular tests with invalid number of arguments and invalid function arguments (known at static-time since they involve literals) are classified as static analysis fail tests in this PR. What I meant by needing an RFC was that this particular behavior isn't part of the current PartiQL spec and we should add an RFC to define the static analysis fail behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can cut a partiql-spec issue for static-analysis failures if the above makes sense.

}
]

'repeated-field-on-struct'::[
Copy link
Member Author

Choose a reason for hiding this comment

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

The COERCE/permissive mode behavior is implementation-dependent as per section 4 of spec. Hence why only the ERROR/strict mode behavior tests are defined.

},
{
name:"More than one character given for ESCAPE",
statement:"SELECT * FROM `[true]` WHERE 'a' LIKE 'a' ESCAPE 'aa'",
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the somewhat ambiguous case for an invalid function argument that's not due to typing error -- hence why the behavior is the same for both eval modes. PostgreSQL don't do a "smarter" static check for the escape pattern of a LIKE operator but gives an evaluator error.

@alancai98 alancai98 requested review from am357 and jpschorr October 7, 2022 23:20
@alancai98 alancai98 marked this pull request as ready for review October 7, 2022 23:20
partiql-tests-data-extended/README.md Outdated Show resolved Hide resolved
],
]

invalid_function_args::[
Copy link
Member

Choose a reason for hiding this comment

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

Are you saying the StaticAnalysisFail symbol may be a richer element, and the RFC will define this?

partiql-tests-data/eval/query/select/joins.ion Outdated Show resolved Hide resolved
partiql-tests-data/eval/query/select/group-by.ion Outdated Show resolved Hide resolved
@alancai98 alancai98 requested review from RCHowell October 10, 2022 22:40
Copy link
Contributor

@am357 am357 left a comment

Choose a reason for hiding this comment

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

I'm not sure how we can review this PR effectively; I think this is one of those PRs that we need to skip the thorough review and lean on asserting its correctness by application i.e. relying on test execution in the Kotlin runner—considering this, I did a cursory review and left couple comments.

@@ -61,3 +61,79 @@
result: SyntaxFail
},
}

'select-star'::[
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it makes sense to put these tests under partiql namespace to re-iterate the fact that they are not necessarily SQL conformed.

@@ -122,7 +122,7 @@ type::{
type: struct,
fields: {
result: { type: symbol, valid_values: [EvaluationSuccess], occurs: required },
output: nullable::{ occurs: required },
output: { type: $any, occurs: required },
Copy link
Contributor

Choose a reason for hiding this comment

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

So you mean if we didn't have the bug we would go with nullable?

Copy link
Member Author

@alancai98 alancai98 left a comment

Choose a reason for hiding this comment

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

I'm not sure how we can review this PR effectively; I think this is one of those PRs that we need to skip the thorough review and lean on asserting its correctness by application i.e. relying on test execution in the Kotlin runner—considering this, I did a cursory review and left couple comments.

Yeah, I agree given the number of tests being ported. Hopefully running the ported tests through the Kotlin test runner can give more confidence that they were ported correctly and had the spec-conformant behavior properly defined to begin with. Working on the PartiQL Rust implementation should also help us identify potential bugs in the tests.

@@ -122,7 +122,7 @@ type::{
type: struct,
fields: {
result: { type: symbol, valid_values: [EvaluationSuccess], occurs: required },
output: nullable::{ occurs: required },
output: { type: $any, occurs: required },
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, if the ion-schema-kotlin bug mentioned in amazon-ion/ion-schema-kotlin#169 didn't exist, then we could go with the previous approach (i.e. nullable::{ occurs: required }), which imo was more understandable. The change here is an equivalent way to specify a nullable, required field.

@@ -61,3 +61,79 @@
result: SyntaxFail
},
}

'select-star'::[
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it would probably make some sense to indicate that these tests are not necessarily SQL-conformant. I'll wrap these tests in a partiql namespace and add a comment in the next commit.

@alancai98 alancai98 requested a review from am357 October 14, 2022 22:55
Copy link
Contributor

@am357 am357 left a comment

Choose a reason for hiding this comment

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

Thank you for putting together this change; I understand it hasn't been easy.

@alancai98 alancai98 merged commit 29c49b9 into main Oct 17, 2022
@alancai98 alancai98 deleted the add-eval-tests branch October 17, 2022 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port evaluation tests from partiql-lang-kotlin PTS
3 participants