hehuiyuan created FLINK-17117:
---------------------------------
Summary: There are an useless cast operation for sql on blink when generate code
Key: FLINK-17117
URL:
https://issues.apache.org/jira/browse/FLINK-17117 Project: Flink
Issue Type: Wish
Components: Table SQL / Planner
Reporter: hehuiyuan
Attachments: image-2020-04-13-19-44-19-174.png
!image-2020-04-13-19-44-19-174.png|width=641,height=305!
This mehthod `generateOneInputStreamOperator` when OperatorCodeGenerator generates SourceConversion:
{code:java}
@Override
public void processElement($STREAM_RECORD $ELEMENT) throws Exception {
$inputTypeTerm $inputTerm = ($inputTypeTerm) ${converter(s"$ELEMENT.getValue()")};
${ctx.reusePerRecordCode()}
${ctx.reuseLocalVariableCode()}
${if (lazyInputUnboxingCode) "" else ctx.reuseInputUnboxingCode()}
$processCode
}
{code}
{code:java}
$inputTypeTerm $inputTerm = ($inputTypeTerm) ${converter(s"$ELEMENT.getValue()")};
{code}
ScanUtil calls generateOneInputStreamOperator
{code:java}
val generatedOperator = OperatorCodeGenerator.generateOneInputStreamOperator[Any, BaseRow](
ctx,
convertName,
processCode,
outputRowType,
converter = inputTermConverter)
//inputTermConverter
val (inputTermConverter, inputRowType) = {
val convertFunc = CodeGenUtils.genToInternal(ctx, inputType)
internalInType match {
case rt: RowType => (convertFunc, rt)
case _ => ((record: String) => s"$GENERIC_ROW.of(${convertFunc(record)})",
RowType.of(internalInType))
}
}
{code}
CodeGenUtils.scala : genToInternal
{code:java}
def genToInternal(ctx: CodeGeneratorContext, t: DataType): String => String = {
val iTerm = boxedTypeTermForType(fromDataTypeToLogicalType(t))
if (isConverterIdentity(t)) {
term => s"($iTerm) $term"
} else {
val eTerm = boxedTypeTermForExternalType(t)
val converter = ctx.addReusableObject(
DataFormatConverters.getConverterForDataType(t),
"converter")
term => s"($iTerm) $converter.toInternal(($eTerm) $term)"
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)