From 0962bcf58d8978311225d8553672747ac269519e Mon Sep 17 00:00:00 2001 From: John Ed Quinn Date: Wed, 24 Apr 2024 09:48:48 -0700 Subject: [PATCH] Adds closePeeking and openPeeking to RelPeeking --- .../eval/internal/operator/rel/RelDistinct.kt | 6 ++---- .../eval/internal/operator/rel/RelExceptAll.kt | 6 ++---- .../internal/operator/rel/RelExceptDistinct.kt | 6 ++---- .../eval/internal/operator/rel/RelFilter.kt | 6 ++---- .../internal/operator/rel/RelIntersectAll.kt | 6 ++---- .../operator/rel/RelIntersectDistinct.kt | 6 ++---- .../internal/operator/rel/RelJoinNestedLoop.kt | 6 ++---- .../eval/internal/operator/rel/RelPeeking.kt | 18 ++++++++++++++++++ .../internal/operator/rel/RelUnionDistinct.kt | 6 ++---- 9 files changed, 34 insertions(+), 32 deletions(-) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelDistinct.kt index b4d041ccf7..15dcc1ba5a 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelDistinct.kt @@ -10,9 +10,8 @@ internal class RelDistinct( private val seen = mutableSetOf() - override fun open(env: Environment) { + override fun openPeeking(env: Environment) { input.open(env) - super.open(env) } override fun peek(): Record? { @@ -25,9 +24,8 @@ internal class RelDistinct( return null } - override fun close() { + override fun closePeeking() { seen.clear() input.close() - super.close() } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptAll.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptAll.kt index 5920a8ea61..f62a433b32 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptAll.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptAll.kt @@ -12,12 +12,11 @@ internal class RelExceptAll( private val seen: MutableMap = 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? { @@ -35,11 +34,10 @@ internal class RelExceptAll( return null } - override fun close() { + override fun closePeeking() { lhs.close() rhs.close() seen.clear() - super.close() } /** diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptDistinct.kt index c5d153bb39..9874aabaea 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExceptDistinct.kt @@ -18,12 +18,11 @@ internal class RelExceptDistinct( private var seen: MutableSet = 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? { @@ -38,11 +37,10 @@ internal class RelExceptDistinct( return null } - override fun close() { + override fun closePeeking() { lhs.close() rhs.close() seen.clear() - super.close() } /** diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelFilter.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelFilter.kt index 5c8b38949d..2081f14d58 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelFilter.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelFilter.kt @@ -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? { @@ -28,9 +27,8 @@ internal class RelFilter( return null } - override fun close() { + override fun closePeeking() { input.close() - super.close() } @OptIn(PartiQLValueExperimental::class) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectAll.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectAll.kt index 77ca4dfa6e..33f2ba869a 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectAll.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectAll.kt @@ -12,12 +12,11 @@ internal class RelIntersectAll( private val seen: MutableMap = 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? { @@ -35,11 +34,10 @@ internal class RelIntersectAll( return null } - override fun close() { + override fun closePeeking() { lhs.close() rhs.close() seen.clear() - super.close() } /** diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectDistinct.kt index e32575395c..2700924104 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelIntersectDistinct.kt @@ -12,12 +12,11 @@ internal class RelIntersectDistinct( private val seen: MutableSet = 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? { @@ -32,11 +31,10 @@ internal class RelIntersectDistinct( return null } - override fun close() { + override fun closePeeking() { lhs.close() rhs.close() seen.clear() - super.close() } /** diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelJoinNestedLoop.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelJoinNestedLoop.kt index ed761c10d2..cb39e48188 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelJoinNestedLoop.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelJoinNestedLoop.kt @@ -19,7 +19,7 @@ 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()) { @@ -27,7 +27,6 @@ internal abstract class RelJoinNestedLoop : RelPeeking() { } lhsRecord = lhs.next() rhs.open(env.push(lhsRecord!!)) - super.open(env) } abstract fun join(condition: Boolean, lhs: Record, rhs: Record): Record? @@ -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) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelPeeking.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelPeeking.kt index be2cf203b8..6206b783bf 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelPeeking.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelPeeking.kt @@ -11,11 +11,29 @@ import org.partiql.eval.internal.operator.Operator */ internal abstract class RelPeeking : Operator.Relation, IteratorPeeking() { + /** + * 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() } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelUnionDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelUnionDistinct.kt index ca4f8366d0..bafa6cb28e 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelUnionDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelUnionDistinct.kt @@ -13,12 +13,11 @@ internal class RelUnionDistinct( private val seen: MutableSet = mutableSetOf() private lateinit var input: Iterator - 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? { @@ -31,10 +30,9 @@ internal class RelUnionDistinct( return null } - override fun close() { + override fun closePeeking() { lhs.close() rhs.close() seen.clear() - super.close() } }