-
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 set op typing; fixes various behaviors in set op parsing and modeling #1506
Conversation
Adds compilation/evaluation support for UNION/INTERSECT/EXCEPT ALL/DISTINCT
Conformance comparison report
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 |
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 | ||
} | ||
} |
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.
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.
Will mark this PR as a draft to account for some
|
… exprs; add/update tests
Above TODOs should be addressed. Still have a few more before PR is ready for review:
|
c69dd6f
to
0dd43ea
Compare
partiql-ast/src/main/kotlin/org/partiql/ast/sql/internal/InternalSqlDialect.kt
Show resolved
Hide resolved
@@ -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 |
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.
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) { |
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.
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.
/** | ||
* 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) | ||
} | ||
} |
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.
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
- require no
- 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
- use
// 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. |
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.
For now, do not do comparability check of types. Only check same number of columns for both set ops.
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 reviewing, minor comments
@@ -1,5 +1,5 @@ | |||
group=org.partiql | |||
version=0.14.6-SNAPSHOT | |||
version=0.14.6 |
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.
Did you drop SNAPSHOT for the release?
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.
yeah -- was planning to cut the 0.14.6 release after this PR gets merged in
assert(node.lhs is Expr.SFW || node.lhs is Expr.BagOp) | ||
assert(node.rhs is Expr.SFW || node.rhs is Expr.BagOp) |
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 suggest adding a message here.
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 a message for both arg asserts
Relevant Issues
UNION
typing in themain
branch #1501Description
Rel
set ops. Plan is slightly simpler than the set operator modeling used inv1
branch. Primarily, no additional set class wrapping the set operatorsRex
set ops to planUNION
in transpilation partiql-scribe#55Other Information
Updated Unreleased Section in CHANGELOG: [YES]
Any backward-incompatible changes? [YES]
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.