JingsongLi commented on a change in pull request #10960: [FLINK-15487][table]
Update code generation for new type inference
URL: https://github.com/apache/flink/pull/10960#discussion_r373385389
##########
File path:
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/codegen/CodeGenUtils.scala
##########
@@ -694,38 +706,67 @@ object CodeGenUtils {
}
}
+ /**
+ * Generates code for converting the given external source data type to the
internal data format.
+ *
+ * Use this function for converting at the edges of the API.
+ */
def genToInternalIfNeeded(
ctx: CodeGeneratorContext,
- t: DataType,
- term: String): String = {
- if (isInternalClass(t)) {
- s"(${boxedTypeTermForType(fromDataTypeToLogicalType(t))}) $term"
+ sourceType: DataType,
+ externalTerm: String)
+ : GeneratedExpression = {
+ // convert external source type to internal format
+ val internalResultTerm = if (isInternalClass(sourceType)) {
+ s"(${boxedTypeTermForType(fromDataTypeToLogicalType(sourceType))})
$externalTerm"
+ } else {
+ genToInternal(ctx, sourceType, externalTerm)
+ }
+ // extract null term from result term
+ if (sourceType.getConversionClass.isPrimitive) {
+ generateNonNullField(sourceType.getLogicalType, internalResultTerm)
} else {
- genToInternal(ctx, t, term)
+ generateInputFieldUnboxing(ctx, sourceType.getLogicalType, externalTerm,
internalResultTerm)
}
}
- def genToExternal(ctx: CodeGeneratorContext, t: DataType, term: String):
String = {
- val iTerm = boxedTypeTermForType(fromDataTypeToLogicalType(t))
- if (isConverterIdentity(t)) {
- s"($iTerm) $term"
+ def genToExternal(
+ ctx: CodeGeneratorContext,
+ targetType: DataType,
+ internalTerm: String): String = {
+ if (isConverterIdentity(targetType)) {
+ s"$internalTerm"
} else {
- val eTerm = boxedTypeTermForExternalType(t)
+ val iTerm = boxedTypeTermForType(fromDataTypeToLogicalType(targetType))
+ val eTerm = boxedTypeTermForExternalType(targetType)
Review comment:
If you don't mind, consider a hotfix to modify the
`boxedTypeTermForExternalType`, because `getConversionClass` can't be null now.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services