Skip to content

Commit

Permalink
Adds closePeeking and openPeeking to RelPeeking
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Apr 24, 2024
1 parent b57bc37 commit 0962bcf
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ internal class RelDistinct(

private val seen = mutableSetOf<Record>()

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
input.open(env)
super.open(env)
}

override fun peek(): Record? {
Expand All @@ -25,9 +24,8 @@ internal class RelDistinct(
return null
}

override fun close() {
override fun closePeeking() {
seen.clear()
input.close()
super.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ internal class RelExceptAll(
private val seen: MutableMap<Record, Int> = mutableMapOf()
private var init: Boolean = false

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
lhs.open(env)
rhs.open(env)
init = false
seen.clear()
super.open(env)
}

override fun peek(): Record? {
Expand All @@ -35,11 +34,10 @@ internal class RelExceptAll(
return null
}

override fun close() {
override fun closePeeking() {
lhs.close()
rhs.close()
seen.clear()
super.close()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ internal class RelExceptDistinct(
private var seen: MutableSet<Record> = mutableSetOf()
private var init: Boolean = false

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
lhs.open(env)
rhs.open(env)
init = false
seen = mutableSetOf()
super.open(env)
}

override fun peek(): Record? {
Expand All @@ -38,11 +37,10 @@ internal class RelExceptDistinct(
return null
}

override fun close() {
override fun closePeeking() {
lhs.close()
rhs.close()
seen.clear()
super.close()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ internal class RelFilter(

private lateinit var env: Environment

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
this.env = env
input.open(env)
super.open(env)
}

override fun peek(): Record? {
Expand All @@ -28,9 +27,8 @@ internal class RelFilter(
return null
}

override fun close() {
override fun closePeeking() {
input.close()
super.close()
}

@OptIn(PartiQLValueExperimental::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ internal class RelIntersectAll(
private val seen: MutableMap<Record, Int> = mutableMapOf()
private var init: Boolean = false

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
lhs.open(env)
rhs.open(env)
init = false
seen.clear()
super.open(env)
}

override fun peek(): Record? {
Expand All @@ -35,11 +34,10 @@ internal class RelIntersectAll(
return null
}

override fun close() {
override fun closePeeking() {
lhs.close()
rhs.close()
seen.clear()
super.close()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ internal class RelIntersectDistinct(
private val seen: MutableSet<Record> = mutableSetOf()
private var init: Boolean = false

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
lhs.open(env)
rhs.open(env)
init = false
seen.clear()
super.open(env)
}

override fun peek(): Record? {
Expand All @@ -32,11 +31,10 @@ internal class RelIntersectDistinct(
return null
}

override fun close() {
override fun closePeeking() {
lhs.close()
rhs.close()
seen.clear()
super.close()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ internal abstract class RelJoinNestedLoop : RelPeeking() {
private var lhsRecord: Record? = null
private lateinit var env: Environment

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
this.env = env
lhs.open(env)
if (lhs.hasNext().not()) {
return
}
lhsRecord = lhs.next()
rhs.open(env.push(lhsRecord!!))
super.open(env)
}

abstract fun join(condition: Boolean, lhs: Record, rhs: Record): Record?
Expand Down Expand Up @@ -69,10 +68,9 @@ internal abstract class RelJoinNestedLoop : RelPeeking() {
return toReturn
}

override fun close() {
override fun closePeeking() {
lhs.close()
rhs.close()
super.close()
}

@OptIn(PartiQLValueExperimental::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,29 @@ import org.partiql.eval.internal.operator.Operator
*/
internal abstract class RelPeeking : Operator.Relation, IteratorPeeking<Record>() {

/**
* This shall have the same functionality as [open]. Implementers of [RelPeeking] shall not override [open].
*/
abstract fun openPeeking(env: Environment)

/**
* This shall have the same functionality as [close]. Implementers of [RelPeeking] shall not override [close].
*/
abstract fun closePeeking()

/**
* Implementers shall not override this method.
*/
override fun open(env: Environment) {
next = null
openPeeking(env)
}

/**
* Implementers shall not override this method.
*/
override fun close() {
next = null
closePeeking()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ internal class RelUnionDistinct(
private val seen: MutableSet<Record> = mutableSetOf()
private lateinit var input: Iterator<Record>

override fun open(env: Environment) {
override fun openPeeking(env: Environment) {
lhs.open(env)
rhs.open(env)
seen.clear()
input = IteratorChain(arrayOf(lhs, rhs))
super.open(env)
}

override fun peek(): Record? {
Expand All @@ -31,10 +30,9 @@ internal class RelUnionDistinct(
return null
}

override fun close() {
override fun closePeeking() {
lhs.close()
rhs.close()
seen.clear()
super.close()
}
}

0 comments on commit 0962bcf

Please sign in to comment.