-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add Plan Evaluator #592
Add Plan Evaluator #592
Conversation
- AST->logical - logical->resolved - lesolved->physical. Not yet integrated with anything--that will come in a future commit.
cf7f832
to
c20b466
Compare
c20b466
to
10ebc0e
Compare
e2b4a98
to
bb6ebb4
Compare
bb6ebb4
to
3b898db
Compare
…plan-staging-planner-pipeline
…plan-staging-planner-pipeline
…lan-staging-plan-evaluator
* | ||
* [1]: https://www.complang.tuwien.ac.at/anton/lvas/sem06w/fest.pdf | ||
*/ | ||
internal class PhysicalExprToThunkConverterImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the copied & revised EvaluatingCompiler
. You'll note that the compileSelect()
function is gone.
It is not worth reviewing the entire file in detail since most of it's old code with only PartiqlAst
replaced with PartiqlPhysical
. I'll note the places below that are new, however.
private fun compileBindingsToValues(expr: PartiqlPhysical.Expr.BindingsToValues): PhysicalPlanThunk { | ||
val mapThunk = compileAstExpr(expr.exp) | ||
val bexprThunk: RelationThunkEnv = PhysicalBexprToThunkConverter(this, thunkFactory.valueFactory) | ||
.convert(expr.query) | ||
|
||
return thunkFactory.thunkEnv(expr.metas) { env -> | ||
val elements = sequence { | ||
val relItr = bexprThunk(env) | ||
while (relItr.nextRow()) { | ||
yield(mapThunk(env)) | ||
} | ||
} | ||
valueFactory.newBag(elements) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This compileBindingsToValues
is a new function.
@Suppress("UNUSED_PARAMETER") | ||
private fun compileLocalId(expr: PartiqlPhysical.Expr.LocalId, metas: MetaContainer): PhysicalPlanThunk { | ||
val localIndex = expr.index.value.toIntExact() | ||
return thunkFactory.thunkEnv(metas) { env -> | ||
env.registers[localIndex] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compileLocalId
is new.
TODO: is there a reason I can't delete the unused metas
parameter?
} | ||
} | ||
|
||
private fun compileStruct(expr: PartiqlPhysical.Expr.Struct): PhysicalPlanThunk { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was modified to support the enhanced struct constructors.
} | ||
|
||
/** | ||
* Given an AST node that represents a `LIKE` predicate, return an ExprThunk that evaluates a `LIKE` predicate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given a "plan" node
* Represents an element in a select list that is to be projected into the final result. | ||
* i.e. an expression, or a (project_all) node. | ||
*/ | ||
private sealed class CompiledStructPart { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is new and is part of support for the enhanced struct constructor.
@@ -98,10 +97,17 @@ class EvaluatorTests { | |||
"selectDistinctWithAggregate", // TODO: Support aggregates in physical plans | |||
"selectDistinctAggregationWithGroupBy", // TODO: Support GROUP BY in physical plans |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why, but these were missed in #586
|
||
/** | ||
* Provides rules for basic AST sanity checks that should be performed before any attempt at further phsycial | ||
* plan processing. This is provided as a distinct [PartiqlPhysical.Visitor] so that [PlanCompiler] may assume that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PlanCompiler
is the old name.
/** | ||
* Simple API that defines a method to convert a [PartiqlPhysical.Expr] to a [PhysicalPlanThunk]. | ||
* | ||
* Intended to abstract prevent [PhysicalBexprToThunkConverter] from having to take a direct dependency on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit.: abstract prevent
-> prevent
?
This reverts commit 2cb4314.
// customFunctions must be on the right side of + here to ensure that they overwrite any | ||
// built-in functions with the same name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this for later but I'm noting—overwrite any built-int—as a design decision that we need to make on the open type system.
import kotlin.test.assertNotEquals | ||
import kotlin.test.assertNull | ||
|
||
internal class PlannerPipelineFactory : PipelineFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a kdoc
here too.
Merges the following PRs to `main`: - #583 - #584 - #587 - #588 - #589 - #609 - #590 - #592 Also, this adds a TODO comment (ea40e4a, requested by @am357 in offline chat) and excludes `PlannerPipeline` from the new aggregate tests which were pulled in when merging from `main` and were not part of the other PRs (34025b3). By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Merges the following PRs to `main`: - #583 - #584 - #587 - #588 - #589 - #609 - #590 - #592 Also, this adds a TODO comment (ea40e4a, requested by @am357 in offline chat) and excludes `PlannerPipeline` from the new aggregate tests which were pulled in when merging from `main` and were not part of the other PRs (34025b3). By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Merges the following PRs to `main`: - #583 - #584 - #587 - #588 - #589 - #609 - #590 - #592 Also, this adds a TODO comment (ea40e4a, requested by @am357 in offline chat) and excludes `PlannerPipeline` from the new aggregate tests which were pulled in when merging from `main` and were not part of the other PRs (34025b3). By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Merges the following PRs to `main`: - #583 - #584 - #587 - #588 - #589 - #609 - #590 - #592 Also, this adds a TODO comment (ea40e4a, requested by @am357 in offline chat) and excludes `PlannerPipeline` from the new aggregate tests which were pulled in when merging from `main` and were not part of the other PRs (34025b3). By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Yes, there's a failed unit test here. I will need to fix that before this can be merged--that does not however, mean can'tEDIT: No longer, this is now fixed.get started reviewing this before then.
This was originally part of #582 and is based on #590, which must be merged first.
Compilation of a query plan is now handled by two classes:
PhysicalBexprToThunkConverter
, which compiles the physical algebra itself.PhysicalExprToThunkConverterImpl
, which is a copy and paste ofEvaluatingCompiler
with:(select ...)
node (including the features out of scope for now:ORDER BY
,GROUP BY
,HAVING
, aggregate functions (SUM
,MAX
,MIN
, etc),PIVOT
andUNPIVOT
).(struct ...)
constructor (that supports struct unions)id
node removed. (This is handled now by eitherlocal_id
orglobal_id
, where variables can be resolved at compile time and by the$__dynamic_lookup__(...)
ExprFunction
if they cannot (and this is enabled).bindings_to_values
expression added (see PIG domains for planner and plan evaluator #584)The two classes are mutually recursive. Each invokes the other to compile value or relational expressions as needed.
Why Is the Duplication Needed
The duplication is unfortunate but necessary and can hopefully be removed in the short term. The goal is, once we're confident in the new plan compiler and it has reached feature parity, to delete
EvaluatingCompiler
. All of the physical plan's node types (value and relational expressions) exist in thePartiqlPhysical
domain while the AST's node types exist in thePartiqlAst
domain. If this duplication is to persist long term, we might need to look at how to eliminate it (possibly thru a new PIG feature), since maintaining bothPhysicalExprToThunkConverterImpl
andEvaluatingCompiler
long term could get onerous.Other Notables That Need Reviewing
EvaluatorState
and its uses. This is the equivalent ofEnvironment
for the plan compiler.sequence { }
,RelationIterator
etc and their uses. Kotlin coroutines are used during relational operator evaluation.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.