Skip to content

Commit

Permalink
fix typer/transfomrer
Browse files Browse the repository at this point in the history
  • Loading branch information
yliuuuu committed Dec 8, 2023
1 parent f8f6b2a commit a07b6aa
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ internal object PlanTransform : PlanBaseVisitor<PlanNode, ProblemCallback>() {
override fun visitFnResolved(node: Fn.Resolved, ctx: ProblemCallback) = org.partiql.plan.fn(node.signature)

override fun visitFnUnresolved(node: Fn.Unresolved, ctx: ProblemCallback): org.partiql.plan.Rex.Op {
return org.partiql.plan.Rex.Op.Err("Unresolved function")
error("Unresolved function ${node.identifier}")
}

override fun visitAgg(node: Agg, ctx: ProblemCallback) = super.visitAgg(node, ctx) as org.partiql.plan.Agg

override fun visitAggResolved(node: Agg.Resolved, ctx: ProblemCallback) = org.partiql.plan.Agg(node.signature)

override fun visitAggUnresolved(node: Agg.Unresolved, ctx: ProblemCallback): org.partiql.plan.Rex.Op {
return org.partiql.plan.Rex.Op.Err("Unresolved aggregation")
error("Unresolved aggregation ${node.identifier}")
}

override fun visitStatement(node: Statement, ctx: ProblemCallback) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,17 @@ internal class PlanTyper(
return rex(type, rexOpPath(root, newSteps))
}

// Default returns the original node, in some case we need the resolved node.
// i.e., the path step is a call node
override fun visitRexOpPathStep(node: Rex.Op.Path.Step, ctx: StaticType?): Rex.Op.Path.Step =
when (node) {
is Rex.Op.Path.Step.Index -> Rex.Op.Path.Step.Index(visitRex(node.key, ctx))
is Rex.Op.Path.Step.Key -> Rex.Op.Path.Step.Key(visitRex(node.key, ctx))
is Rex.Op.Path.Step.Symbol -> Rex.Op.Path.Step.Symbol(node.identifier)
is Rex.Op.Path.Step.Unpivot -> Rex.Op.Path.Step.Unpivot()
is Rex.Op.Path.Step.Wildcard -> Rex.Op.Path.Step.Wildcard()
}

/**
* Resolve and type scalar function calls.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.partiql.planner.internal.typer.path

import org.junit.jupiter.api.DynamicContainer
import org.junit.jupiter.api.TestFactory
import org.partiql.planner.internal.typer.PartiQLTyperTestBase
import org.partiql.types.StaticType
import java.util.stream.Stream

/**
* This test makes sure that the planner can resolve various path expression
*/
class SanityTests : PartiQLTyperTestBase() {
@TestFactory
fun path(): Stream<DynamicContainer> {
val tests = buildList {
(0..14).forEach {
this.add("paths-${it.toString().padStart(2,'0')}")
}
}.map { inputs.get("basics", it)!! }

val argsMap: Map<TestResult, Set<List<StaticType>>> = buildMap {
put(TestResult.Success(StaticType.ANY), setOf(listOf(StaticType.ANY, StaticType.ANY)))
put(TestResult.Failure, emptySet<List<StaticType>>())
}

return super.testGen("path", tests, argsMap)
}
}
34 changes: 17 additions & 17 deletions partiql-planner/src/testFixtures/resources/inputs/basics/paths.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,67 @@

--#[paths-00]
-- tuple navigation
x.y;
t1.y;

--#[paths-01]
-- array navigation with literal
x[0];
t1[0];

--#[paths-02]
-- tuple navigation with array notation
x['y'];
t1['y'];

--#[paths-03]
-- tuple navigation (2)
x."y";
t1."y";

--#[paths-04]
-- tuple navigation with explicit cast as string
x[CAST(z AS STRING)];
t1[CAST(t2 AS STRING)];

-- ----------------------------------------
-- Composition of Navigation (5 choose 3)
-- ----------------------------------------

--#[paths-05]
x.y[0]['y'];
t1.y[0]['y'];

--#[paths-06]
x.y[0]."y";
t1.y[0]."y";

--#[paths-07]
x.y[0][CAST(z AS STRING)];
t1.y[0][CAST(t2 AS STRING)];

--#[paths-08]
x.y['y']."y";
t1.y['y']."y";

--#[paths-09]
x.y['y'][CAST(z AS STRING)];
t1.y['y'][CAST(t2 AS STRING)];

--#[paths-10]
x.y."y"[CAST(z AS STRING)];
t1.y."y"[CAST(t2 AS STRING)];

--#[paths-11]
x[0]['y']."y";
t1[0]['y']."y";

--#[paths-12]
x[0]['y'][CAST(z AS STRING)];
t1[0]['y'][CAST(t2 AS STRING)];

--#[paths-13]
x[0]."y"[CAST(z AS STRING)];
t1[0]."y"[CAST(t2 AS STRING)];

--#[paths-14]
x['y']."y"[CAST(z AS STRING)];
t1['y']."y"[CAST(t2 AS STRING)];

-- ----------------------------------------
-- Array Navigation with Expressions
-- ----------------------------------------

--#[paths-15]
x[0+1];
t1[0+1];

--#[paths-16]
x[ABS(1)];
t1[ABS(1)];

-- ----------------------------------------
-- PartiQL Path Navigation (+SFW)
Expand Down

0 comments on commit a07b6aa

Please sign in to comment.