Package net.hydromatic.morel.compile
Class CalciteCompiler
java.lang.Object
net.hydromatic.morel.compile.Compiler
net.hydromatic.morel.compile.CalciteCompiler
Compiles an expression to code that can be evaluated.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interfaceExtension toCodethat can also provide a translation to relational algebra.(package private) static classTranslation context.private static classHow a Morel variable maps onto the columns returned from a Join.Nested classes/interfaces inherited from class net.hydromatic.morel.compile.Compiler
Compiler.Action, Compiler.Context -
Field Summary
FieldsModifier and TypeFieldDescriptionMorel infix operators and their exact equivalents in Calcite.(package private) final CalciteMorel prefix and suffix operators and their exact equivalents in Calcite.Fields inherited from class net.hydromatic.morel.compile.Compiler
EMPTY_ENV, typeSystem -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.calcite.sql.SqlAggFunctionReturns the Calcite operator corresponding to a Morel built-in aggregate function.protected CalciteCompiler.RelCodecompileApply(Compiler.Context cx, Core.Apply apply) compileArg(Compiler.Context cx, Core.Exp expression) Compiles the argument to "apply".protected CodecompileFrom(Compiler.Context cx, Core.From from) protected CalciteFunctions.ContextcreateContext(Environment env) Creates a context.private static EvalEnvevalEnvOf(Environment env) protected CodefinishCompileApply(Compiler.Context cx, Applicable fnValue, Code argCode, Type argType) protected CodefinishCompileApply(Compiler.Context cx, Code fnCode, Code argCode, Type argType) protected CodefinishCompileLet(Compiler.Context cx, List<Code> matchCodes_, Code resultCode_, Type resultType) getRelationalVariables(Environment env, Set<String> nameSet, AstNode node) private static CalciteCompiler.RelContextgetRelContext(CalciteCompiler.RelContext cx, Environment env, List<String> names) private CalciteCompiler.RelContextgroup(CalciteCompiler.RelContext cx, Core.Group group) private static voidharmonizeRowTypes(org.apache.calcite.tools.RelBuilder relBuilder, int inputCount) private CalciteCompiler.RelContextjoin(CalciteCompiler.RelContext cx, int i, Core.Scan scan) private static org.apache.calcite.rel.core.JoinRelTypejoinRelType(Op op) private org.apache.calcite.rex.RexNodemaybeNot(CalciteCompiler.RelContext cx, org.apache.calcite.rex.RexNode e, boolean not) private org.apache.calcite.rex.RexNodemorelApply(CalciteCompiler.RelContext cx, Type type, Type argType, org.apache.calcite.rex.RexNode fn, org.apache.calcite.rex.RexNode arg) private org.apache.calcite.rex.RexNodeprivate CalciteCompiler.RelContextorder(CalciteCompiler.RelContext cx, Core.Order order) private TyperemoveTypeVars(Type type) Converts each type variable in a type to a dummy record type,{b: bool}.private CalciteCompiler.RelContextskip(CalciteCompiler.RelContext cx, Core.Skip skip) private CalciteCompiler.RelContexttake(CalciteCompiler.RelContext cx, Core.Take take) private Core.Tuple@Nullable org.apache.calcite.rel.RelNodetoRel(Environment env, Core.Exp expression) private org.apache.calcite.rel.RelNodetoRel2(CalciteCompiler.RelContext cx, Core.Exp expression) (package private) booleantoRel3(CalciteCompiler.RelContext cx, Core.Exp expression, boolean aggressive) (package private) CodetoRel4(Environment env, Code code, Type type) private org.apache.calcite.rex.RexNodetranslate(CalciteCompiler.RelContext cx, Core.Exp exp) private List<org.apache.calcite.rex.RexNode> translateList(CalciteCompiler.RelContext cx, List<Core.Exp> exps) private CalciteCompiler.RelContextwhere(CalciteCompiler.RelContext cx, Core.Where where) private CalciteCompiler.RelContextyield_(CalciteCompiler.RelContext cx, List<Binding> bindings, Core.Exp exp) private CalciteCompiler.RelContextyield_(CalciteCompiler.RelContext cx, Core.Yield yield) Methods inherited from class net.hydromatic.morel.compile.Compiler
compile, compile, compileArgs, compileDecl, compileStatement, createRowSinkFactory
-
Field Details
-
UNARY_OPERATORS
Morel prefix and suffix operators and their exact equivalents in Calcite. -
BINARY_OPERATORS
Morel infix operators and their exact equivalents in Calcite. -
calcite
-
-
Constructor Details
-
CalciteCompiler
-
-
Method Details
-
toRel
-
toRel2
-
toRel3
-
toRel4
-
createContext
Description copied from class:CompilerCreates a context.The whole way we provide compilation environments (including Environment) to generated code is a mess:
- This method is protected so that CalciteCompiler can override and get a Calcite type factory.
- User-defined functions should have a 'prepare' phase, where they use a type factory and environment, that is distinct from the 'eval' phase.
- We should pass compile and runtime environments via parameters, not thread-locals.
- The dummy session is there because session is mandatory, but we have not created a session yet. Lifecycle confusion.
- Overrides:
createContextin classCompiler
-
compileArg
Description copied from class:CompilerCompiles the argument to "apply".- Overrides:
compileArgin classCompiler
-
finishCompileLet
protected Code finishCompileLet(Compiler.Context cx, List<Code> matchCodes_, Code resultCode_, Type resultType) - Overrides:
finishCompileLetin classCompiler
-
compileApply
- Overrides:
compileApplyin classCompiler
-
removeTypeVars
Converts each type variable in a type to a dummy record type,{b: bool}. -
finishCompileApply
- Overrides:
finishCompileApplyin classCompiler
-
finishCompileApply
protected Code finishCompileApply(Compiler.Context cx, Applicable fnValue, Code argCode, Type argType) - Overrides:
finishCompileApplyin classCompiler
-
harmonizeRowTypes
private static void harmonizeRowTypes(org.apache.calcite.tools.RelBuilder relBuilder, int inputCount) -
compileFrom
- Overrides:
compileFromin classCompiler
-
yield_
-
yield_
private CalciteCompiler.RelContext yield_(CalciteCompiler.RelContext cx, List<Binding> bindings, Core.Exp exp) -
translate
-
maybeNot
private org.apache.calcite.rex.RexNode maybeNot(CalciteCompiler.RelContext cx, org.apache.calcite.rex.RexNode e, boolean not) -
getRelationalVariables
-
morelScalar
-
morelApply
private org.apache.calcite.rex.RexNode morelApply(CalciteCompiler.RelContext cx, Type type, Type argType, org.apache.calcite.rex.RexNode fn, org.apache.calcite.rex.RexNode arg) -
toRecord
-
translateList
private List<org.apache.calcite.rex.RexNode> translateList(CalciteCompiler.RelContext cx, List<Core.Exp> exps) -
join
-
joinRelType
-
where
-
skip
-
take
-
order
-
group
-
getRelContext
private static CalciteCompiler.RelContext getRelContext(CalciteCompiler.RelContext cx, Environment env, List<String> names) -
aggOp
Returns the Calcite operator corresponding to a Morel built-in aggregate function.Future work: rather than resolving by name, look up aggregate function in environment, and compare with standard implementation of "sum" etc.; support aggregate functions defined by expressions (e.g. lambdas).
-
evalEnvOf
-