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

Add set op typing; fixes various behaviors in set op parsing and modeling #1506

Merged
merged 10 commits into from
Jul 15, 2024

Conversation

alancai98
Copy link
Member

@alancai98 alancai98 commented Jul 10, 2024

Relevant Issues

Description

  • partiql-plan:
    • adds set quantifier to Rel set ops. Plan is slightly simpler than the set operator modeling used in v1 branch. Primarily, no additional set class wrapping the set operators
    • adds Rex set ops to plan
  • partiql-planner: adds typing support for set operator
  • partiql-parser:
    • distinguishes between PartiQL bag and SQL set ops
    • updates and adds tests following this behavioral change
  • partiql-ast:
    • SqlDialect -- fixes missing parens set op printing
  • Tested the updates in Scribe Upgrade to plk 0.14.6 + add UNION support partiql-scribe#56
  • Prepares v0.14.6 release

Other Information

  • Updated Unreleased Section in CHANGELOG: [YES]

  • Any backward-incompatible changes? [YES]

    • Yes, from prior discussion, this is a backwards incompatible change due to adding an additional field (set quantifier) to set operators in the plan. But since the plan typer always gave an error when typing the plan, no customers should have been using the previous modeling.
  • Any new external dependencies? [NO]

  • Do your changes comply with the Contributing Guidelines
    and Code Style Guidelines? [YES]

License Information

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 Jul 10, 2024
Copy link

github-actions bot commented Jul 10, 2024

Conformance comparison report

Base (55a27e6) c080b9f +/-
% Passing 92.54% 92.54% 0.00%
✅ Passing 5384 5384 0
❌ Failing 434 434 0
🔶 Ignored 0 0 0
Total Tests 5818 5818 0

Number passing in both: 5384

Number failing in both: 434

Number passing in Base (55a27e6) but now fail: 0

Number failing in Base (55a27e6) but now pass: 0

Comment on lines 309 to 315
for (i in 0..lhs.type.schema.lastIndex) {
val lhsBindingType = lhs.type.schema[i].type
val rhsBindingType = rhs.type.schema[i].type
if (lhsBindingType != rhsBindingType) {
return false
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Since the current schema type comparison is only partially implemented, I'll delete this validation block for the 0.14.6 release to unblock partiql/partiql-scribe#55. The different Scribe dialects may have their own notion of comparability and perform their own set operator checks.

@alancai98 alancai98 requested a review from RCHowell July 10, 2024 18:58
@alancai98
Copy link
Member Author

alancai98 commented Jul 10, 2024

Will mark this PR as a draft to account for some

  • parsing changes (current parser parses every set op to bag_op)
  • plan changes
    • current plan modeling maps bag_ops and SFW.set_ops as a Rel node w/ two Rel arguments
    • we should have a separate node for bag_ops over Rexs and SFW.set_ops over Rels

@alancai98 alancai98 marked this pull request as draft July 10, 2024 23:28
@alancai98
Copy link
Member Author

alancai98 commented Jul 12, 2024

Above TODOs should be addressed. Still have a few more before PR is ready for review:

  • - Check SqlDialect behavior for printing BagOp -- seems to be omitting parens for right-associative case
  • - Test PR's changes in local maven release and Scribe -- Upgrade to plk 0.14.6 + add UNION support partiql-scribe#56
  • - Update added set op parse tests to use the AstBuilder to remove some unneeded code

@@ -500,7 +500,7 @@ expr::[
where: optional::expr,
group_by: optional::group_by,
having: optional::expr,
set_op: optional::{
set_op: optional::{ // TODO modeling of `set_op` needs updated to support left-associative set ops https://github.com/partiql/partiql-lang-kotlin/issues/1507
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 current modeling of SQL set ops is not correct in the AST (see #1507). I chose to just reuse the Expr.BagOp node rather than use this Expr.SFW.SetOp node for this PR to preserve backwards compatibility for this release.

We should fix the modeling before the v1 release.

@@ -320,7 +320,14 @@ class QueryPrettyPrinter {
is PartiqlAst.Expr.Or -> writeNAryOperator("OR", node.operands, sb, level)
is PartiqlAst.Expr.InCollection -> writeNAryOperator("IN", node.operands, sb, level)
is PartiqlAst.Expr.BagOp -> {
var name = node.op.javaClass.simpleName.toUpperCase().replace("_", " ")
var name = when (node.op) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Buggy previous behavior would print OUTER UNION node as OUTERUNION.

Could have been more clever w/ printing but since this is legacy code that will be removed ahead of v1, just opted for a simple solution.

Comment on lines +1116 to +1125
/**
* Verifies if all of the [args] are
* 1. [Expr.SFW] or
* 2. [Expr.BagOp] and is a SQL Set op (i.e. [Expr.BagOp.outer] != true)
*/
private fun argsAreSFW(args: List<Expr>): Boolean {
return args.all { arg ->
arg is Expr.SFW || (arg is Expr.BagOp && arg.outer != true)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

New parsing logic to distinguish between SQL set ops and PartiQL bag ops

  • SQL set ops
    • require no OUTER before set operation and
    • require args are SQL set ops or SFW expression
  • PartiQL bag ops
    • use OUTER keyword or
    • do not use OUTER keyword but one or more arguments is a PartiQL bag op or non-SFW expression

Comment on lines +306 to +308
// TODO: [RFC-0007](https://github.com/partiql/partiql-lang/blob/main/RFCs/0007-rfc-bag-operators.md)
// states that the types must be "comparable". For now, we will always return true. In the future, we need
// to add support for checking comparable types.
Copy link
Member Author

Choose a reason for hiding this comment

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

For now, do not do comparability check of types. Only check same number of columns for both set ops.

@alancai98 alancai98 marked this pull request as ready for review July 12, 2024 22:49
@alancai98 alancai98 changed the title partiql-plan: adds set quantifier to set ops; partiql-planner: add typing support for set ops Add set op typing; fixes various behaviors in set op parsing and modeling Jul 12, 2024
Copy link
Member

@RCHowell RCHowell left a comment

Choose a reason for hiding this comment

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

Still reviewing, minor comments

@@ -1,5 +1,5 @@
group=org.partiql
version=0.14.6-SNAPSHOT
version=0.14.6
Copy link
Member

Choose a reason for hiding this comment

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

Did you drop SNAPSHOT for the release?

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 -- was planning to cut the 0.14.6 release after this PR gets merged in

Comment on lines 167 to 168
assert(node.lhs is Expr.SFW || node.lhs is Expr.BagOp)
assert(node.rhs is Expr.SFW || node.rhs is Expr.BagOp)
Copy link
Member

Choose a reason for hiding this comment

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

I suggest adding a message here.

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 message for both arg asserts

@alancai98 alancai98 requested a review from RCHowell July 15, 2024 20:07
@alancai98 alancai98 merged commit 54c6c47 into v0.14.6 Jul 15, 2024
10 checks passed
@alancai98 alancai98 deleted the cherry-pick-setop-changes branch July 15, 2024 22:55
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.

3 participants