Skip to content

Adds support for DISTINCT in Eval #1292

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

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.eval.internal

import org.partiql.eval.internal.operator.Operator
import org.partiql.eval.internal.operator.rel.RelDistinct
import org.partiql.eval.internal.operator.rel.RelFilter
import org.partiql.eval.internal.operator.rel.RelJoinInner
import org.partiql.eval.internal.operator.rel.RelJoinLeft
Expand Down Expand Up @@ -174,6 +175,11 @@ internal class Compiler(
return ExprLiteral(node.value)
}

override fun visitRelOpDistinct(node: Rel.Op.Distinct, ctx: Unit): Operator {
val input = visitRel(node.input, ctx)
return RelDistinct(input)
}

override fun visitRelOpFilter(node: Rel.Op.Filter, ctx: Unit): Operator {
val input = visitRel(node.input, ctx)
val condition = visitRex(node.predicate, ctx)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.partiql.eval.internal.operator.rel

import org.partiql.eval.internal.Record
import org.partiql.eval.internal.operator.Operator

internal class RelDistinct(
val input: Operator.Relation
) : Operator.Relation {

private val seen = mutableSetOf<Record>()

override fun open() {
input.open()
}

override fun next(): Record? {
var next = input.next()
while (next != null) {
if (seen.contains(next).not()) {
seen.add(next)
return next
}
next = input.next()
}
return null
}

override fun close() {
input.close()
}
}
Loading