Package net.hydromatic.morel.compile
Class CalciteCompiler
- java.lang.Object
-
- net.hydromatic.morel.compile.Compiler
-
- net.hydromatic.morel.compile.CalciteCompiler
-
public class CalciteCompiler extends Compiler
Compiles an expression to code that can be evaluated.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceCalciteCompiler.RelCodeExtension toCodethat can also provide a translation to relational algebra.(package private) static classCalciteCompiler.RelContextTranslation context.private static classCalciteCompiler.VarDataHow 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
Fields Modifier and Type Field Description (package private) static Map<BuiltIn,org.apache.calcite.sql.SqlOperator>BINARY_OPERATORSMorel infix operators and their exact equivalents in Calcite.(package private) Calcitecalcite(package private) static Map<BuiltIn,org.apache.calcite.sql.SqlOperator>UNARY_OPERATORSMorel 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 Constructor Description CalciteCompiler(TypeSystem typeSystem, Calcite calcite)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private org.apache.calcite.sql.SqlAggFunctionaggOp(Core.Exp aggregate)Returns the Calcite operator corresponding to a Morel built-in aggregate function.protected CalciteCompiler.RelCodecompileApply(Compiler.Context cx, Core.Apply apply)CodecompileArg(Compiler.Context cx, Core.Exp expression)Compiles the argument to "apply".protected CalciteCompiler.RelCodecompileFrom(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)private Set<String>getRelationalVariables(Environment env, Set<String> nameSet, AstNode node)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.RexNodemorelScalar(CalciteCompiler.RelContext cx, Core.Exp exp)private 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 Core.TupletoRecord(CalciteCompiler.RelContext cx, Core.Id id)@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, 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 Detail
-
UNARY_OPERATORS
static final Map<BuiltIn,org.apache.calcite.sql.SqlOperator> UNARY_OPERATORS
Morel prefix and suffix operators and their exact equivalents in Calcite.
-
BINARY_OPERATORS
static final Map<BuiltIn,org.apache.calcite.sql.SqlOperator> BINARY_OPERATORS
Morel infix operators and their exact equivalents in Calcite.
-
calcite
final Calcite calcite
-
-
Constructor Detail
-
CalciteCompiler
public CalciteCompiler(TypeSystem typeSystem, Calcite calcite)
-
-
Method Detail
-
toRel
public @Nullable org.apache.calcite.rel.RelNode toRel(Environment env, Core.Exp expression)
-
toRel2
private org.apache.calcite.rel.RelNode toRel2(CalciteCompiler.RelContext cx, Core.Exp expression)
-
toRel3
boolean toRel3(CalciteCompiler.RelContext cx, Core.Exp expression, boolean aggressive)
-
toRel4
Code toRel4(Environment env, Code code, Type type)
-
createContext
protected CalciteFunctions.Context createContext(Environment env)
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
public Code compileArg(Compiler.Context cx, Core.Exp expression)
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
protected CalciteCompiler.RelCode compileApply(Compiler.Context cx, Core.Apply apply)
- Overrides:
compileApplyin classCompiler
-
removeTypeVars
private Type removeTypeVars(Type type)
Converts each type variable in a type to a dummy record type,{b: bool}.
-
finishCompileApply
protected Code finishCompileApply(Compiler.Context cx, Code fnCode, Code argCode, Type argType)
- 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
protected CalciteCompiler.RelCode compileFrom(Compiler.Context cx, Core.From from)
- Overrides:
compileFromin classCompiler
-
yield_
private CalciteCompiler.RelContext yield_(CalciteCompiler.RelContext cx, Core.Yield yield)
-
yield_
private CalciteCompiler.RelContext yield_(CalciteCompiler.RelContext cx, Core.Exp exp)
-
translate
private org.apache.calcite.rex.RexNode translate(CalciteCompiler.RelContext cx, Core.Exp exp)
-
maybeNot
private org.apache.calcite.rex.RexNode maybeNot(CalciteCompiler.RelContext cx, org.apache.calcite.rex.RexNode e, boolean not)
-
getRelationalVariables
private Set<String> getRelationalVariables(Environment env, Set<String> nameSet, AstNode node)
-
morelScalar
private org.apache.calcite.rex.RexNode morelScalar(CalciteCompiler.RelContext cx, Core.Exp exp)
-
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
private Core.Tuple toRecord(CalciteCompiler.RelContext cx, Core.Id id)
-
translateList
private List<org.apache.calcite.rex.RexNode> translateList(CalciteCompiler.RelContext cx, List<Core.Exp> exps)
-
join
private CalciteCompiler.RelContext join(CalciteCompiler.RelContext cx, int i, Core.Scan scan)
-
joinRelType
private static org.apache.calcite.rel.core.JoinRelType joinRelType(Op op)
-
where
private CalciteCompiler.RelContext where(CalciteCompiler.RelContext cx, Core.Where where)
-
order
private CalciteCompiler.RelContext order(CalciteCompiler.RelContext cx, Core.Order order)
-
group
private CalciteCompiler.RelContext group(CalciteCompiler.RelContext cx, Core.Group group)
-
aggOp
@Nonnull private org.apache.calcite.sql.SqlAggFunction aggOp(Core.Exp aggregate)
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
private static EvalEnv evalEnvOf(Environment env)
-
-