You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "zhougit86 (via GitHub)" <gi...@apache.org> on 2023/05/22 16:42:24 UTC

[GitHub] [flink] zhougit86 opened a new pull request, #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

zhougit86 opened a new pull request, #22624:
URL: https://github.com/apache/flink/pull/22624

   
   
   ## What is the purpose of the change
   
   fix the default behaviour of cast exceptoin
   
   
   ## Brief change log
   
   when the exception is thrown in legacy cast rule, the null variable is another name, we can return a null when exception thrown
   
   
   ## Verifying this change
   
   
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   
   
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): ( no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
     - The serializers: ( no )
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: ( no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (not documented)
   


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1654876318

   https://github.com/apache/flink/pull/23028
   https://github.com/apache/flink/pull/23029
   @snuyanzin Hi master, not sure if this is what you mean create backports?


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1567066058

   @snuyanzin Hi Master, Could you please help review the test case and let me know if it makes sense.... 


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1589095661

   @flinkbot run azure


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1596157634

   > @zhougit86 Thanks for contribution. But i'm still trying to understand what's the problem and why your changes can fix it. Could you please provide a reproducible case so that I can try to reproduce it in my local and to understand the problem.
   
   @luoyuxia could you please help review? thx


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1605542677

   > ## CI report:
   > * [9b777cc](https://github.com/apache/flink/commit/9b777cc410c0075201b7d24158c6cfe2aa368b15) Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=50286)
   > 
   > Bot commands
   
   @snuyanzin Master, not sure whether the rebase took effect? :)


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1596941999

   hi @zhougit86 
   it looks ok from my side thanks for addressing comments
   
   the only nit pick: could you please rename `CastFunctionMiscITLegacyCase` in way that it matches regex `'[A-Z][A-Za-z\d]*Test(s|Case)?|Test[A-Z][A-Za-z\d]*|IT(.*)|(.*)IT(Case)`
   e.g. something like `CastFunctionMiscLegacyITCase`


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1619350179

   > 
   
   sure thing, will do quickly


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1559128930

   @flinkbot run azure


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1599038504

   also could you please rebase to the latest master?
   The failure was fixed in later commits, so rebase should help with passing tests


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin merged pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin merged PR #22624:
URL: https://github.com/apache/flink/pull/22624


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1583841476

   @luoyuxia please find the test case in the commit, when the "cast( a as bigint)" function's input type is "STRING().notNull()", we suppose to get a null value. but now it returns a default value "-1". this is not correct.
   
   In the test case, I made it throw a not null enforcer exception. without the change, I will return a -1, which I think is not correct.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1582543341

   @zhougit86 Thanks for contribution. But i'm still trying to understand what's the problem and why your changes can fix it. Could you please provide a reproducible case so that I can try to reproduce it in my local and to understand the problem.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on a diff in pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #22624:
URL: https://github.com/apache/flink/pull/22624#discussion_r1223926176


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGenUtils.scala:
##########
@@ -556,7 +556,7 @@ object CodeGenUtils {
         s"$rowTerm.setNullAt($indexTerm)"
       }
 
-      if (fieldType.isNullable) {
+      if (fieldType.isNullable || fieldExpr.nullTerm.startsWith("castRuleResultIsNull")) {

Review Comment:
   IMHO it is not good to rely on var namings
   rather it's better to check properties
   why can't we pass a corresponding arg to `org.apache.flink.table.planner.codegen.calls.ScalarOperatorGens$#generateCast` for `nullOnFailure` ?



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1618312678

   @zhougit86 thanks for the contribution
   are you willing to create backports to 1.17.x, 1.16.x?


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1558940043

   @flinkbot run azure


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1598820824

   > hi @zhougit86 it looks ok from my side thanks for addressing comments
   > 
   > the only nit pick: could you please rename `CastFunctionMiscITLegacyCase` in way that it matches regex `'[A-Z][A-Za-z\d]*Test(s|Case)?|Test[A-Z][A-Za-z\d]*|IT(.*)|(.*)IT(Case)` e.g. something like `CastFunctionMiscLegacyITCase`
   
   Thx for the review master, fixed @snuyanzin 


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1598826176

   hmm, it looks like you renamed class however not renamed file... could you also please rename file in order to have them in sync?


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on a diff in pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on code in PR #22624:
URL: https://github.com/apache/flink/pull/22624#discussion_r1227751941


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGenUtils.scala:
##########
@@ -556,7 +556,7 @@ object CodeGenUtils {
         s"$rowTerm.setNullAt($indexTerm)"
       }
 
-      if (fieldType.isNullable) {
+      if (fieldType.isNullable || fieldExpr.nullTerm.startsWith("castRuleResultIsNull")) {

Review Comment:
   Thanks for advice, I updated it and make the target type nullable , which makes it the same as the legacy codegen return value. Please let me know your thinking



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGenUtils.scala:
##########
@@ -556,7 +556,7 @@ object CodeGenUtils {
         s"$rowTerm.setNullAt($indexTerm)"
       }
 
-      if (fieldType.isNullable) {
+      if (fieldType.isNullable || fieldExpr.nullTerm.startsWith("castRuleResultIsNull")) {

Review Comment:
   Thanks for advice, I updated it and make the target type nullable , which makes it the same as the legacy codegen return value. Please let me know your thinking @snuyanzin 



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1618304146

   thanks for addressing comment
   great that it's becoming even smaller


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on a diff in pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #22624:
URL: https://github.com/apache/flink/pull/22624#discussion_r1223904857


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionMiscITLegacyCase.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.functions;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.config.ExecutionConfigOptions;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+
+import java.util.stream.Stream;
+
+import static org.apache.flink.table.api.DataTypes.STRING;
+import static org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR;
+import static org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_SINK_NOT_NULL_ENFORCER;
+
+/**
+ * Tests for {@link BuiltInFunctionDefinitions#CAST} when legacy cast mode enabled regarding {@link
+ * DataTypes#ROW}.
+ */
+class CastFunctionMiscITLegacyCase extends BuiltInFunctionTestBase {
+    Configuration getConfiguration() {
+        return super.getConfiguration()
+                .set(
+                        TABLE_EXEC_LEGACY_CAST_BEHAVIOUR,
+                        ExecutionConfigOptions.LegacyCastBehaviour.ENABLED)
+                .set(
+                        TABLE_EXEC_SINK_NOT_NULL_ENFORCER,
+                        ExecutionConfigOptions.NotNullEnforcer.ERROR);
+    }
+
+    @Override
+    Stream<TestSetSpec> getTestSetSpecs() {
+        return Stream.of(
+                TestSetSpec.forFunction(BuiltInFunctionDefinitions.CAST, "try cast throw exception")

Review Comment:
   this description is confusing: are we testing `CAST` or `TRY_CAST`?



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1599996291

   > also could you please rebase to the latest master? The failure was fixed in later commits, so rebase should help with passing tests
   
   thx for the instruction... my bad not modify file name .... fixed @snuyanzin 


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1558939031

   > Can you please add a reproducible test to be sure that the PR fixes what it is expected to fix?
   
   Thx for replay, I added a test: CastFunctionMiscITLegacyCase. if without the code I added, the test could return a value -1, which is not expected


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1557558838

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bf4bb92fcfa2aa374139293d26b52fd04f78ef5a",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "bf4bb92fcfa2aa374139293d26b52fd04f78ef5a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bf4bb92fcfa2aa374139293d26b52fd04f78ef5a UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1600477468

   
   @flinkbot run azure
   
   


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1614295522

   > @zhougit86 sorry for the late response
   > 
   > I have a question: could you please clarify it it seems your change is inside condition
   > 
   > ```scala
   > if (codeGeneratorCastRule.canFail(inputType, targetType) && nullOnFailure) {
   > ...
   > val adjustedTargetType = if (nullOnFailure) targetType.copy(nullOnFailure) else targetType
   >           return GeneratedExpression(
   >             resultTerm,
   >             nullTerm,
   >             operand.code + "\n" + castCode,
   >             adjustedTargetType
   >           )
   > ...
   > } else {
   > ...
   >           return GeneratedExpression(
   >             castCodeBlock.getReturnTerm,
   >             castCodeBlock.getIsNullTerm,
   >             operand.code + castCode,
   >             targetType
   >           )
   > }
   > ```
   > 
   > shouldn't we extract `val adjustedTargetType = if (nullOnFailure) targetType.copy(nullOnFailure) else targetType` from `if/else` and apply it to both `if` and `else` branches?
   
   Hate to admit my negligence being caught again :(
   
   I think maybe we shouldn't extract ```val adjustedTargetType = if (nullOnFailure) targetType.copy(nullOnFailure) else targetType```  out from the ```if/else``` section, as in the else section, we will not catch the Exception thrown by the cast, so the nullTerm is actually useless in the generated code. 
   
   Anyway, I will remove the redundant ```if (nullOnFailure)```, let me know your think please...


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on a diff in pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on code in PR #22624:
URL: https://github.com/apache/flink/pull/22624#discussion_r1227749658


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionMiscITLegacyCase.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.functions;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.config.ExecutionConfigOptions;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+
+import java.util.stream.Stream;
+
+import static org.apache.flink.table.api.DataTypes.STRING;
+import static org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR;
+import static org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_SINK_NOT_NULL_ENFORCER;
+
+/**
+ * Tests for {@link BuiltInFunctionDefinitions#CAST} when legacy cast mode enabled regarding {@link
+ * DataTypes#ROW}.
+ */
+class CastFunctionMiscITLegacyCase extends BuiltInFunctionTestBase {
+    Configuration getConfiguration() {
+        return super.getConfiguration()
+                .set(
+                        TABLE_EXEC_LEGACY_CAST_BEHAVIOUR,
+                        ExecutionConfigOptions.LegacyCastBehaviour.ENABLED)
+                .set(
+                        TABLE_EXEC_SINK_NOT_NULL_ENFORCER,
+                        ExecutionConfigOptions.NotNullEnforcer.ERROR);
+    }
+
+    @Override
+    Stream<TestSetSpec> getTestSetSpecs() {
+        return Stream.of(
+                TestSetSpec.forFunction(BuiltInFunctionDefinitions.CAST, "try cast throw exception")

Review Comment:
   > this description is confusing: are we testing `CAST` or `TRY_CAST`?
   
   @snuyanzin modified the description, made it clear this is a legacy cast behaviour



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1612073732

   @zhougit86 sorry for the late response
   
   I have a question: could you please clarify it
   it seems your change is inside condition
   ```scala
   if (codeGeneratorCastRule.canFail(inputType, targetType) && nullOnFailure) {
   ...
   val adjustedTargetType = if (nullOnFailure) targetType.copy(nullOnFailure) else targetType
             return GeneratedExpression(
               resultTerm,
               nullTerm,
               operand.code + "\n" + castCode,
               adjustedTargetType
             )
   ...
   } else {
   ...
             return GeneratedExpression(
               castCodeBlock.getReturnTerm,
               castCodeBlock.getIsNullTerm,
               operand.code + castCode,
               targetType
             )
   }
   ```
   shouldn't we extract `val adjustedTargetType = if (nullOnFailure) targetType.copy(nullOnFailure) else targetType` from `if/else` and apply it to both `if` and `else` branches? 


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] zhougit86 commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "zhougit86 (via GitHub)" <gi...@apache.org>.
zhougit86 commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1614305351

   @flinkbot run azure


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22624: [FLINK-32132][table-planner] Cast function CODEGEN does not work as e…

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22624:
URL: https://github.com/apache/flink/pull/22624#issuecomment-1557666714

   Can you please add a reproducible test to be sure that the PR fixes what it is expected to fix?


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org