Skip to content

Commit a133477

Browse files
committed
address comments
1 parent d9ac983 commit a133477

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

partiql-eval/src/main/kotlin/org/partiql/eval/internal/Compiler.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ internal class Compiler(
161161
val args = node.args.map { visitRex(it, ctx).modeHandled() }.toTypedArray()
162162
val candidates = node.candidates.map { candidate ->
163163
val fn = symbols.getFn(candidate.fn)
164-
val types = fn.signature.parameters.map { it.type }.toTypedArray()
165164
val coercions = candidate.coercions.toTypedArray()
166-
ExprCallDynamic.Candidate(fn, types, coercions)
165+
ExprCallDynamic.Candidate(fn, coercions)
167166
}
168167
return ExprCallDynamic(candidates, args)
169168
}

partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ internal class ExprCallDynamic(
4444
*/
4545
internal class Candidate(
4646
val fn: Fn,
47-
val types: Array<PartiQLValueType>,
4847
val coercions: Array<Ref.Cast?>
4948
) {
5049

50+
private val signatureParameters = fn.signature.parameters.map { it.type }.toTypedArray()
51+
5152
fun eval(originalArgs: Array<PartiQLValue>): PartiQLValue {
5253
val args = originalArgs.mapIndexed { i, arg ->
5354
when (val c = coercions[i]) {
@@ -58,17 +59,27 @@ internal class ExprCallDynamic(
5859
return fn.invoke(args)
5960
}
6061

61-
internal fun matches(args: Array<PartiQLValue>): Boolean {
62-
for (i in args.indices) {
63-
if (types[i] == PartiQLValueType.ANY) {
64-
return true
65-
}
66-
if (args[i].type != types[i]) {
67-
val c = coercions[i]
68-
when {
69-
c == null -> return false
70-
c.input != args[i].type -> return false
71-
c.target != types[i] -> return false
62+
internal fun matches(inputs: Array<PartiQLValue>): Boolean {
63+
for (i in inputs.indices) {
64+
val inputType = inputs[i].type
65+
val parameterType = signatureParameters[i]
66+
val c = coercions[i]
67+
when (c) {
68+
// coercion might be null if one of the following is true
69+
// Function parameter is ANY,
70+
// Input type is null
71+
// input type is the same as function parameter
72+
null -> {
73+
if (!(inputType == parameterType || inputType == PartiQLValueType.NULL || parameterType == PartiQLValueType.ANY)) {
74+
return false
75+
}
76+
}
77+
else -> {
78+
// checking the input type is expected by the coercion
79+
if (inputType != c.input) return false
80+
// checking the result is expected by the function signature
81+
// this should branch should never be reached, but leave it here for clarity
82+
if (c.target != parameterType) return false
7283
}
7384
}
7485
}

test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class EvalExecutor(
8484
if (v1.isNull && v2.isNull) {
8585
return true
8686
}
87+
// TODO: this comparator is designed for order by
88+
// One of the false result it might produce is that
89+
// it treats MISSING and NULL equally.
90+
// we should move to hash or equals in value class once
91+
// we finished implementing those.
8792
if (comparator.compare(v1, v2) == 0) {
8893
return true
8994
}

0 commit comments

Comments
 (0)