Skip to content

Commit

Permalink
Fix SqlDialect (and InternalSD) parens for set ops
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Jul 12, 2024
1 parent 0bd0572 commit c69dd6f
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
7 changes: 7 additions & 0 deletions partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlDialect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public abstract class SqlDialect : AstBaseVisitor<SqlBlock, SqlBlock>() {
h = h concat ")"
h
}
is Expr.BagOp -> {
var h = head
h = h concat "("
h = visitExprBagOp(node, h)
h = h concat ")"
h
}
else -> visitExpr(node, head)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ internal abstract class InternalSqlDialect : AstBaseVisitor<InternalSqlBlock, In
t = t concat ")"
t
}
is Expr.BagOp -> {
var t = tail
t = t concat "("
t = visitExprBagOp(node, t)
t = t concat ")"
t
}
else -> visitExpr(node, tail)
}

Expand Down
114 changes: 114 additions & 0 deletions partiql-ast/src/test/kotlin/org/partiql/ast/sql/SqlDialectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,120 @@ class SqlDialectTest {
rhs = v("y")
}
},
expect("(x UNION y) UNION z") {
exprBagOp {
type = setOp {
type = SetOp.Type.UNION
setq = null
}
outer = false
lhs = exprBagOp {
type = setOp {
type = SetOp.Type.UNION
setq = null
}
outer = false
lhs = v("x")
rhs = v("y")
}
rhs = v("z")
}
},
expect("x UNION (y UNION z)") {
exprBagOp {
type = setOp {
type = SetOp.Type.UNION
setq = null
}
outer = false
lhs = v("x")
rhs = exprBagOp {
type = setOp {
type = SetOp.Type.UNION
setq = null
}
outer = false
lhs = v("y")
rhs = v("z")
}
}
},
expect("(x EXCEPT y) EXCEPT z") {
exprBagOp {
type = setOp {
type = SetOp.Type.EXCEPT
setq = null
}
outer = false
lhs = exprBagOp {
type = setOp {
type = SetOp.Type.EXCEPT
setq = null
}
outer = false
lhs = v("x")
rhs = v("y")
}
rhs = v("z")
}
},
expect("x EXCEPT (y EXCEPT z)") {
exprBagOp {
type = setOp {
type = SetOp.Type.EXCEPT
setq = null
}
outer = false
lhs = v("x")
rhs = exprBagOp {
type = setOp {
type = SetOp.Type.EXCEPT
setq = null
}
outer = false
lhs = v("y")
rhs = v("z")
}
}
},
expect("(x INTERSECT y) INTERSECT z") {
exprBagOp {
type = setOp {
type = SetOp.Type.INTERSECT
setq = null
}
outer = false
lhs = exprBagOp {
type = setOp {
type = SetOp.Type.INTERSECT
setq = null
}
outer = false
lhs = v("x")
rhs = v("y")
}
rhs = v("z")
}
},
expect("x INTERSECT (y INTERSECT z)") {
exprBagOp {
type = setOp {
type = SetOp.Type.INTERSECT
setq = null
}
outer = false
lhs = v("x")
rhs = exprBagOp {
type = setOp {
type = SetOp.Type.INTERSECT
setq = null
}
outer = false
lhs = v("y")
rhs = v("z")
}
}
},
)

@JvmStatic
Expand Down

0 comments on commit c69dd6f

Please sign in to comment.