[ 
https://issues.apache.org/jira/browse/FLINK-11961?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16795997#comment-16795997
 ] 

Jark Wu commented on FLINK-11961:
---------------------------------

Hi [~lzljs3620320], it's not to combine {{PlannerExpression}} and 
{{CallGenerator}}. It is like a combination of  {{PlannerExpression}} and 
{{CallGenerator}}. 

Similar to {{CallGenerator}}: they have the same responsibility to generate 
code for a call. But ExprCodeGen extends that a bit: not just support a call 
but also other expressions such as {{LiteralCodeGen}}, {{FieldAccessCodeGen}}. 

Similar to {{PlannerExpression}}: they have the same Inheritance structure, 
e.g. the base classes {{BinaryExprCodeGen}}, {{UnaryExprCodeGen}} and concrete 
classes for every functions/operators code generation {{ConcatCodeGen}}, 
{{LikeCodeGen}}, {{PlusCodeGen}}.



> Clear up and refactor the code generation of scalar functions and operators
> ---------------------------------------------------------------------------
>
>                 Key: FLINK-11961
>                 URL: https://issues.apache.org/jira/browse/FLINK-11961
>             Project: Flink
>          Issue Type: Improvement
>          Components: SQL / Planner
>            Reporter: Jark Wu
>            Assignee: Jark Wu
>            Priority: Major
>
> Currently, the code generation of scalar functions and operators are complex 
> and messy. 
> There are several ways to support codegen for a function/operator:
> (1) Implement {{generate...}} in {{ScalarOperatorGens}} and invoke it in the 
> big match pattern of {{ExprCodeGenerator}}.
> (2) Implement a {{CallGenerator}} and add it to {{FunctionGenerator}}.
> (3) Implement a util method and add it to {{BuiltinMethods}} and 
> {{FunctionGenerator}}.
> It will confuse developer which is the most efficient way to implement a 
> function.
> In this issue, we will propose a unified way to code generate 
> functions/operators.
> Some initial idea:
> 1. Introduce an {{ExprCodeGen}} interface, and all the function/operators 
> code generator should extend this to implement the {{codegen}} method. It's 
> like a combination of {{PlannerExpression}} and {{CallGenerator}}. 
> 2. Rename {{ExprCodeGenerator}} to {{RexCodeGenerator}}.
> 3. Use a big match pattern to mapping {{RexCall}} to specific {{ExprCodeGen}}
> {code:scala}
> trait ExprCodeGen {
>   def operands: Seq[GeneratedExpression]
>   def resultType: InternalType
>   def codegen(ctx: CodeGeneratorContext): GeneratedExpression
> }
> case class ConcatCodeGen(operands: Seq[GeneratedExpression]) extends 
> ExprCodeGen {
>   override def resultType: InternalType = InternalTypes.STRING
>   override def codegen(ctx: CodeGeneratorContext): GeneratedExpression = {
>     nullSafeCodeGen(ctx) {
>       terms => s"$BINARY_STRING.concat(${terms.mkString(", ")})"
>     }
>   }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to