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

Shuiqiang Chen edited comment on FLINK-31848 at 4/23/23 9:39 AM:
-----------------------------------------------------------------

Here is a test case:

{code:scala}
  def testRowAndRow(): Unit = {
    val sqlQuery = "SELECT cast(b > 2 and c < 3 as string),b,c FROM MyTableRow "

    val data = List(
      Row.of("Hello", Int.box(1), Int.box(1)),
      Row.of("Hello", null, Int.box(1)),
      Row.of("Hello again", Int.box(3), Int.box(2)))

    implicit val tpe: TypeInformation[Row] = new RowTypeInfo(Types.STRING, 
Types.INT, Types.INT)

    val ds = env.fromCollection(data)

    val t = ds.toTable(tEnv, 'a, 'b, 'c)
    tEnv.createTemporaryView("MyTableRow", t)

    val result = tEnv.sqlQuery(sqlQuery).toAppendStream[Row]
    val sink = new TestingAppendSink
    result.addSink(sink)
    env.execute()

    val expected = List("FALSE,1,1, TRUE,3,2, null,null,1")
    assertEquals(expected.sorted, sink.getAppendResults.sorted)
  }
{code}
The expected result is List(FALSE,1,1, TRUE,3,2, null,null,1)
But get List(FALSE,1,1, FALSE,null,1, TRUE,3,2)



was (Author: csq):
Here is a test case:

{code:scala}
  def testRowAndRow(): Unit = {
    val sqlQuery = "SELECT cast(b > 2 and c < 3 as string),b,c FROM MyTableRow "

    val data = List(
      Row.of("Hello", Int.box(1), Int.box(1)),
      Row.of("Hello", null, Int.box(1)),
      Row.of("Hello again", Int.box(3), Int.box(2)))

    implicit val tpe: TypeInformation[Row] = new RowTypeInfo(Types.STRING, 
Types.INT, Types.INT)

    val ds = env.fromCollection(data)

    val t = ds.toTable(tEnv, 'a, 'b, 'c)
    tEnv.createTemporaryView("MyTableRow", t)

    val result = tEnv.sqlQuery(sqlQuery).toAppendStream[Row]
    val sink = new TestingAppendSink
    result.addSink(sink)
    env.execute()

    val expected = List("List(FALSE,1,1, TRUE,3,2, null,null,1)")
    assertEquals(expected.sorted, sink.getAppendResults.sorted)
  }
{code}
The expected result is List(FALSE,1,1, TRUE,3,2, null,null,1)
But get List(FALSE,1,1, FALSE,null,1, TRUE,3,2)


> And Operator has side effect when operands have udf
> ---------------------------------------------------
>
>                 Key: FLINK-31848
>                 URL: https://issues.apache.org/jira/browse/FLINK-31848
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>    Affects Versions: 1.13.2
>            Reporter: zju_zsx
>            Priority: Major
>         Attachments: image-2023-04-19-14-54-46-458.png
>
>
>  
> {code:java}
> CREATE TABLE kafka_source (
>    `content` varchar,
>    `testid` bigint,
>    `extra` int
>    );
> CREATE TABLE console_sink (
>    `content` varchar,
>    `testid` bigint
>  )
>   with (
>     'connector' = 'print'
> );
> insert into console_sink
> select 
>    content,testid+1
> from kafka_source where testid is not null and testid > 0 and my_udf(testid) 
> != 0; {code}
> my_udf has a constraint that the testid should not be null, but the testid is 
> not null and testid > 0 does not take effect.
>  
> Im ScalarOperatorGens.generateAnd
> !image-2023-04-19-14-54-46-458.png!
> if left.nullTerm is true, right code will be execute 。
> it seems that
> {code:java}
> if (!${left.nullTerm} && !${left.resultTerm}) {code}
> can be safely replaced with 
> {code:java}
> if (!${left.resultTerm}){code}
> ? 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to