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

RFC-0007 Bag Operator Coercion Behavior Inconsistencies #76

Open
johnedquinn opened this issue Apr 17, 2024 · 0 comments
Open

RFC-0007 Bag Operator Coercion Behavior Inconsistencies #76

johnedquinn opened this issue Apr 17, 2024 · 0 comments
Labels
question Further information is requested

Comments

@johnedquinn
Copy link
Member

As I was reading RFC-0007, I had remembered some of the coercion rules applicable to the RHS of a FROM clause in the PartiQL Specification. Specifically, from the PartiQL Specification:

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. Under the permissive option, the cases proceed as follows:

Iteration over a scalar value: Consider the query:
FROM s AS v AT p
or the query:
FROM s AS v

where s is a scalar value. Then s coerces into the bag << s >>, i.e., the bag that has a single element, the s. The
rest of the semantics is identical to what happens when the lhs of the FROM item is a bag.

The PartiQL Specification states that, in strict mode, coercion does NOT occur when attempting to execute FROM <scalar>. However, in permissive mode, coercion to a bag will occur. As I was reading RFC-0007, I see the following coercion rules for OUTER <BAG OP>:

V1 OUTER UNION ALL V2     = SQL_UNION(F(V1), F(V2))
V1 OUTER INTERSECT ALL V2 = SQL_INTERSECT(F(V1), F(V2))
V1 OUTER EXCEPT ALL V2    = SQL_EXCEPT(F(V1), F(V2))

V1 OUTER UNION DISTINCT V2     = DISTINCT(SQL_UNION(F(V1), F(V2)))
V1 OUTER INTERSECT DISTINCT V2 = DISTINCT(SQL_INTERSECT(F(V1), F(V2)))
V1 OUTER EXCEPT DISTINCT V2    = DISTINCT(SQL_EXCEPT(F(V1), F(V2)))

The coercion function F is defined for all PartiQL values (Appendix C) by:

F(absent_value) -> << >>               
F(scalar_value) -> << scalar_value >> # singleton bag
F(tuple_value)  -> << tuple_value >>  # singleton bag, see future extensions
F(array_value)  -> bag_value          # discard ordering
F(bag_value)    -> bag_value          # identity

So, my question is: is the coercion function applied in both typing modes? To me, it would seem odd to coerce in strict mode -- as the behavior seems inconsistent with the behavior of the FROM clause.

@johnedquinn johnedquinn added the question Further information is requested label Apr 17, 2024
@johnedquinn johnedquinn changed the title RFC-0007 Bag Operator Coercion Behavior RFC-0007 Bag Operator Coercion Behavior Inconsistencies Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant