Fixing typechecker on ASTSubtypes escalating to ASTs

nicksrules
Oliver Kennedy 2023-07-13 15:28:54 -04:00
parent 6169f4d614
commit 4738e5e631
Signed by: okennedy
GPG Key ID: 3E5F9B3ABD3FDB60
2 changed files with 12 additions and 9 deletions

View File

@ -10,11 +10,11 @@ object Catalyst extends HardcodedDefinition
Node("Filter")(
"condition" -> Type.Native("Expression"),
"child" -> Type.AST("LogicalPlan")
),
).withSupertypes("UnaryNode"),
Node("Project")(
"projectList" -> Type.Array(Type.Native("NamedExpression")),
"child" -> Type.AST("LogicalPlan")
),
).withSupertypes("UnaryNode"),
Node("Union")(
"children" -> Type.Array(Type.AST("LogicalPlan")),
"byName" -> Type.Bool,
@ -30,27 +30,27 @@ object Catalyst extends HardcodedDefinition
Node("LocalLimit")(
"limitExpr" -> Type.Native("Expression"),
"child" -> Type.AST("LogicalPlan")
),
).withSupertypes("UnaryNode"),
Node("GlobalLimit")(
"limitExpr" -> Type.Native("Expression"),
"child" -> Type.AST("LogicalPlan")
),
).withSupertypes("UnaryNode"),
Node("Aggregate")(
"groupingExpressions" -> Type.Array(Type.Native("Expression")),
"aggregateExpressions" -> Type.Array(Type.Native("NamedExpression")),
"child" -> Type.AST("LogicalPlan")
),
).withSupertypes("UnaryNode"),
Node("Window")(
"windowExpressions" -> Type.Array(Type.Native("NamedExpression")),
"partitionSpec" -> Type.Array(Type.Native("Expression")),
"orderSpec" -> Type.Array(Type.Native("SortOrder")),
"child" -> Type.AST("LogicalPlan")
),
).withSupertypes("UnaryNode"),
Node("EventTimeWatermark")(
"eventTime" -> Type.Native("Attribute"),
"delay" -> Type.Native("CalendarInterval"),
"child" -> Type.AST("LogicalPlan"),
),
).withSupertypes("UnaryNode"),
)
//////////////////////////////////////////////////////
@ -134,7 +134,7 @@ object Catalyst extends HardcodedDefinition
)
Function("canPushThrough", Type.Bool)(
Type.Node("UnaryNode")
Type.ASTSubtype("UnaryNode")
)
Function("canPushThroughCondition", Type.Bool)(
@ -613,7 +613,7 @@ object Catalyst extends HardcodedDefinition
Rule("PushDownPredicates-2-6", "LogicalPlan")(
Bind("filter", Match("Filter")(
Bind("unusedCondition"),
Bind("u", Match("UnaryNode")), // here be dragons.
Bind("u", OfType(Type.ASTSubtype("UnaryNode"))), // here be dragons.
)) and Test(
Apply("canPushThrough")(
Ref("u")

View File

@ -14,6 +14,9 @@ object Typecheck
case (a, b) if a == b => true
case (Type.Node(label), o:Type.ASTType) =>
schema.nodesByName(label).allSupertypes contains o
case (n:Type.ASTSubtype, o:Type.AST) =>
println(schema.asts(o.family).subtypes.keys)
schema.asts(o.family).subtypes contains n
case (Type.Union(elems), a) =>
elems.forall { escalatesTo(_, a, schema) }
case (a, Type.Union(elems)) =>