This is an automated email from the ASF dual-hosted git repository. twalthr pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit 76b47b219dab18ddb41beb29fa8664110bdb891d Author: Marios Trivyzas <[email protected]> AuthorDate: Thu Dec 2 12:25:27 2021 +0100 [hotfix][table-planner] Add class header comment to generated code Use a class header comment to add useful configuration variables that can help debugging a generated class code. Added timezone and legacy behaviour info in this comment on the generated class implementing CAST. --- .../planner/codegen/CodeGeneratorContext.scala | 25 ++++++++++++++++++++++ .../planner/codegen/FunctionCodeGenerator.scala | 1 + .../planner/codegen/calls/ScalarOperatorGens.scala | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGeneratorContext.scala b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGeneratorContext.scala index 3be8032..6ddcbe7 100644 --- a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGeneratorContext.scala +++ b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGeneratorContext.scala @@ -51,6 +51,10 @@ class CodeGeneratorContext(val tableConfig: TableConfig) { // holding a list of objects that could be used passed into generated class val references: mutable.ArrayBuffer[AnyRef] = new mutable.ArrayBuffer[AnyRef]() + // set of strings (lines) that will be concatenated into a single class header comment + private val reusableHeaderComments: mutable.LinkedHashSet[String] = + mutable.LinkedHashSet[String]() + // set of member statements that will be added only once // we use a LinkedHashSet to keep the insertion order private val reusableMemberStatements: mutable.LinkedHashSet[String] = @@ -143,6 +147,16 @@ class CodeGeneratorContext(val tableConfig: TableConfig) { def nullCheck: Boolean = tableConfig.getNullCheck + + /** + * Add a line comment to [[reusableHeaderComments]] list which will be concatenated + * into a single class header comment. + * @param comment The comment to add for class header + */ + def addReusableHeaderComment(comment: String): Unit = { + reusableHeaderComments.add(comment) + } + // --------------------------------------------------------------------------------- // Local Variables for Code Split // --------------------------------------------------------------------------------- @@ -197,6 +211,17 @@ class CodeGeneratorContext(val tableConfig: TableConfig) { // --------------------------------------------------------------------------------- /** + * @return Comment to be added as a header comment on the generated class + */ + def getClassHeaderComment(): String = { + s""" + |/* + | * ${reusableHeaderComments.mkString("\n * ")} + | */ + """.stripMargin + } + + /** * @return code block of statements that need to be placed in the member area of the class * (e.g. inner class definition) */ diff --git a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/FunctionCodeGenerator.scala b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/FunctionCodeGenerator.scala index 44a4c23..24c286f 100644 --- a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/FunctionCodeGenerator.scala +++ b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/FunctionCodeGenerator.scala @@ -125,6 +125,7 @@ object FunctionCodeGenerator { val funcCode = j""" + ${ctx.getClassHeaderComment()} public class $funcName extends ${samHeader._1.getCanonicalName} { diff --git a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala index 045976c..61252f4 100644 --- a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala +++ b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala @@ -937,6 +937,12 @@ object ScalarOperatorGens { operand: GeneratedExpression, targetType: LogicalType) : GeneratedExpression = { + + ctx.addReusableHeaderComment( + s"Using option '${ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR.key()}':" + + s"'${isLegacyCastBehaviourEnabled(ctx)}'") + ctx.addReusableHeaderComment("Timezone: " + ctx.tableConfig.getLocalTimeZone) + // Try to use the new cast rules val rule = CastRuleProvider.resolve(operand.resultType, targetType) rule match {
