-
Notifications
You must be signed in to change notification settings - Fork 1
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
Corrects tests regarding coercion, indexing, bag operators, and missing attributes #112
Conversation
evalMode: EvalModeError, | ||
result: EvaluationFail, | ||
}, | ||
] |
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.
I believe the next test "rangeOverSexp" is also incorrect. An sexp is a collection. The result should be bag::[a, b, c ]
not a singleton bag.
Notice that we turn an input Ion list into a collection that we range over, but here we treat the sexp collection as a single value. This does not make sense.
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.
Agreed. Will add that test to the scope of this PR.
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.
Added! Also found and fixed some more incorrect tests -- see 1da4e8b.
assert: [ | ||
{ | ||
evalMode:EvalModeCoerce, | ||
result:EvaluationSuccess, | ||
output:$bag::[ | ||
{ | ||
a:5 | ||
} | ||
] | ||
}, | ||
{ | ||
evalMode: EvalModeError, | ||
result: EvaluationFail, | ||
}, | ||
] |
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.
Commenting to track rangeOverStruct failure in strict mode.
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.
this tuple case is covered in section 5.1.1:
5.1.1. Mistyping Cases
In the following cases the expression in the FROM clause item has the wrong type. Under the type checking option, all
of these cases raise an error and the query fails.
...
• Iteration over a tuple value: Consider the query:
FROM t AS v AT p
or the query:
FROM t AS v
where t is a tuple. Then t coerces into the bag << t >>
so it should give an error in strict mode. Existing permissive mode behavior is correct.
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.
still have a couple files I'm looking through, namely
- partiql-tests-data/eval/query/select/from-clause.ion and
- partiql-tests-data/eval/query/group-by/group-by.ion
test changes in the other files I've looked through look good
{readings:$bag::[0.5]} | ||
] | ||
}, | ||
{ |
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.
Agree w/ how this test will give an error in strict mode due to the path expression l.sensor
in the 2nd grouping expression. I guess the original test was meant to demonstrate how to prevent NULL
and MISSING
from being grouped together.
Not sure if there's really a way to prevent GROUP BY
on l.sensor
from erroring in strict mode.
result: EvaluationSuccess, | ||
output: $bag::[{x: 0}] | ||
}, | ||
{ |
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.
Nice catch for these tests. Was an oversight on my part -- I completely missed the heading "Mistyping Cases" when porting
@@ -126,7 +126,6 @@ bagOperators::[ | |||
evalMode:[EvalModeCoerce, EvalModeError], | |||
result:EvaluationSuccess, | |||
output:$bag::[ | |||
1, |
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.
Would be helpful to link partiql/partiql-lang#75 and/or leave a comment about the behavior here. Didn't realize the DISTINCT
is called on both inputs before calling the EXCEPT
.
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.
Nice work correcting the conformance tests! Finished looking at all the tests. Left a couple non-blocking comments.
assert: [ | ||
{ | ||
evalMode:EvalModeCoerce, | ||
result:EvaluationSuccess, | ||
output:$bag::[ | ||
{ | ||
a:5 | ||
} | ||
] | ||
}, | ||
{ | ||
evalMode: EvalModeError, | ||
result: EvaluationFail, | ||
}, | ||
] |
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.
this tuple case is covered in section 5.1.1:
5.1.1. Mistyping Cases
In the following cases the expression in the FROM clause item has the wrong type. Under the type checking option, all
of these cases raise an error and the query fails.
...
• Iteration over a tuple value: Consider the query:
FROM t AS v AT p
or the query:
FROM t AS v
where t is a tuple. Then t coerces into the bag << t >>
so it should give an error in strict mode. Existing permissive mode behavior is correct.
evalMode:EvalModeError, | ||
result:EvaluationFail | ||
}, | ||
] |
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.
So basically all the changed tests from above this point that had used supplierId_missings
, supplierId_mixed
, price_missings
, or price_mixed
in the GROUP BY
or aggregation expression which should have resulted in an error in strict mode?
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.
All the changes look better aligned with the spec.
I wonder, however, if what the spec says about FROM RHS Coercion
and UNPIVOT
actually runs afoul of our ability satisfy the "Gradual Guarantee" as per the "Refined Criteria for Gradual Typing" paper.
Perhaps push all the other changes and hold back the FROM
and UNPIVOT
changes while we investigate the typing implications?
Totally. I've removed those cases and have pushed them to PR #113. This is now ready for final review. |
Description
FROM RHS Coercion
The excerpt below comes from the PartiQL Specification and states that, in strict mode, the query will FAIL when the RHS of a FROM is a scalar. In permissive, it'll be coerced to a bag holding the scalar.
This is applicable to the following 11 tests:
dateTimePartsAsVariableNames
various types in from clause
rangeTwiceOverScalar
single source FROM with scalar
single source FROM with scalar and AT clause
single source FROM with tuple
single source FROM with tuple and AT clause
single source FROM with absent value null
single source FROM with absent value null and AT clause
single source FROM with absent value missing
single source FROM with absent value missing and AT clause
Negative Indexing
From the PartiQL Specification:
This is applicable to the following 2 tests:
ordinalAccessWithNegativeIndex
ordinalAccessWithNegativeIndexAndBindings
SFW Coercion
The excerpt below comes from the PartiQL Specification and states that SELECT queries shall be coerced.
This is applicable to the following 4 tests:
SELECT VALUE with nested aggregates : SELECT VALUE (SELECT SUM(outerFromSource.col1) AS the_sum FROM <<1>>) FROM simple_1_col_1_group as outerFromSource
selectListMultipleAggregatesNestedQuery
Expression with multiple subqueriees containing aggregates : CAST((SELECT COUNT(1) FROM products) AS LIST)[0]._1 / CAST((SELECT COUNT(1) FROM suppliers) AS LIST)[0]._1
Aggregates with subquery containing another aggregate : SELECT COUNT(1) + CAST((SELECT SUM(numInStock) FROM products) AS LIST)[0]._1 as a_number FROM products
Note: I had to rename some of these due to the inclusion of the queries in their names.
EXCEPT DISTINCT Bug
For more information, please see partiql/partiql-lang#75
This is applicable to the following 1 test:
outerExceptDistinct
.Tuple Path Navigation Failures
From the PartiQL Specification:
Notably, it seems that, in type checking mode, grouping does NOT coerce any type checking errors to NULL/MISSING. However, if a MISSING is encountered (not an error), then it will be coerced to
NULL
.Similarly, aggregate functions are modeled as scalar functions that take in BAGS and output scalars. It seems that a type check exception occurring within the arguments of an aggregate function will result in a query failure (it won't be caught) with type checking mode. In permissive, these failures are coerced to MISSING, and the aggregate functions handle them appropriately.
This is applicable to the following 58 tests:
selectValueStructConstructorWithMissing
SELECT supplierId_missings FROM products_sparse p GROUP BY p.supplierId_missings
SELECT p.supplierId_missings FROM products_sparse p GROUP BY p.supplierId_missings
SELECT VALUE { 'supplierId_missings' : p.supplierId_missings } FROM products_sparse p GROUP BY p.supplierId_missings
SELECT supplierId_mixed FROM products_sparse p GROUP BY p.supplierId_mixed
SELECT p.supplierId_mixed FROM products_sparse p GROUP BY p.supplierId_mixed
SELECT VALUE { 'supplierId_mixed' : p.supplierId_mixed } FROM products_sparse p GROUP BY p.supplierId_mixed
SELECT regionId, supplierId_missings FROM products_sparse p GROUP BY p.regionId, p.supplierId_missings
SELECT p.regionId, p.supplierId_missings FROM products_sparse p GROUP BY p.regionId, p.supplierId_missings
SELECT VALUE { 'regionId': p.regionId, 'supplierId_missings': p.supplierId_missings } FROM products_sparse p GROUP BY p.regionId, p.supplierId_missings
SELECT regionId, supplierId_mixed FROM products_sparse p GROUP BY p.regionId, p.supplierId_mixed
SELECT regionId, p.supplierId_mixed FROM products_sparse p GROUP BY p.regionId, p.supplierId_mixed
SELECT VALUE { 'regionId': p.regionId, 'supplierId_mixed': p.supplierId_mixed } FROM products_sparse p GROUP BY p.regionId, p.supplierId_mixed
SELECT COUNT(1) AS the_count, <ALL_AGGS>(p.price_missings) AS the_agg FROM products_sparse AS p
SELECT COUNT(1) AS the_count, <ALL_AGGS>(p.price_mixed) AS the_agg FROM products_sparse AS p
SELECT categoryId, COUNT(1) AS the_count, <ALL_AGGS>(p.price_missings) AS the_agg FROM products_sparse AS p GROUP BY categoryId
SELECT categoryId, COUNT(1) AS the_count, <ALL_AGGS>(p.price_mixed) AS the_agg FROM products_sparse AS p GROUP BY categoryId
SELECT p.categoryId, COUNT(1) AS the_count, <ALL_AGGS>( price_nulls) AS the_agg FROM products_sparse AS p GROUP BY p.categoryId
SELECT p.categoryId, COUNT(1) AS the_count, <ALL_AGGS>(p.price_mixed) AS the_agg FROM products_sparse AS p GROUP BY p.categoryId
undefinedUnqualifiedVariable_inSelect_withProjectionOption
selectListWithMissing
ANY with GROUP BY
ANY DISTINCT with GROUP BY
SOME with GROUP BY
SOME DISTINCT with GROUP BY
EVERY with GROUP BY
EVERY DISTINCT with GROUP BY
undefinedUnqualifiedVariableInSelectWithUndefinedVariableBehaviorMissing
array element evaluates to MISSING
bag element evaluates to MISSING
bag element evaluates to MISSING in bag constructor
cast and operations with missing argument
group by with absent values
group by with differenciated absent values
UNPIVOT Coercion
I fixed a handful of tests that do not handle the Unpivot mistyping scenarios. According to the PartiQL Specification:
AT Alias When Unordered
I fixed some tests that previously contradicted the following excerpt from the PartiQL Specification:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.