-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1316 from partiql/eval-tests
Updates pivot on rebase and join tests
- Loading branch information
Showing
6 changed files
with
186 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelScanIndexed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.partiql.eval.internal.operator.rel | ||
|
||
import org.partiql.eval.internal.Record | ||
import org.partiql.eval.internal.operator.Operator | ||
import org.partiql.value.CollectionValue | ||
import org.partiql.value.PartiQLValue | ||
import org.partiql.value.PartiQLValueExperimental | ||
import org.partiql.value.int64Value | ||
|
||
@OptIn(PartiQLValueExperimental::class) | ||
internal class RelScanIndexed( | ||
private val expr: Operator.Expr | ||
) : Operator.Relation { | ||
|
||
private lateinit var iterator: Iterator<PartiQLValue> | ||
private var index: Long = 0 | ||
|
||
override fun open() { | ||
val r = expr.eval(Record.empty) | ||
index = 0 | ||
iterator = when (r) { | ||
is CollectionValue<*> -> r.iterator() | ||
else -> iterator { yield(r) } | ||
} | ||
} | ||
|
||
override fun next(): Record? { | ||
if (!iterator.hasNext()) { | ||
return null | ||
} | ||
val i = index | ||
val v = iterator.next() | ||
index += 1 | ||
return Record.of(v, int64Value(i)) | ||
} | ||
|
||
override fun close() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.partiql.eval.internal.operator.rex | ||
|
||
import org.partiql.eval.internal.Record | ||
import org.partiql.eval.internal.operator.Operator | ||
import org.partiql.value.PartiQLValue | ||
import org.partiql.value.PartiQLValueExperimental | ||
import org.partiql.value.StringValue | ||
import org.partiql.value.check | ||
import org.partiql.value.structValue | ||
|
||
@OptIn(PartiQLValueExperimental::class) | ||
internal class ExprPivot( | ||
private val input: Operator.Relation, | ||
private val key: Operator.Expr, | ||
private val value: Operator.Expr, | ||
) : Operator.Expr { | ||
|
||
override fun eval(record: Record): PartiQLValue { | ||
input.open() | ||
val fields = mutableListOf<Pair<String, PartiQLValue>>() | ||
while (true) { | ||
val row = input.next() ?: break | ||
val k = key.eval(row).check<StringValue>() | ||
val v = value.eval(row) | ||
fields.add(k.value!! to v) | ||
} | ||
input.close() | ||
return structValue(fields) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters