[
https://issues.apache.org/jira/browse/FLINK-10834?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16694115#comment-16694115
]
Hequn Cheng commented on FLINK-10834:
-------------------------------------
Hi, thanks for your discussion and suggestions.
As for flatten() with Nondeterministic udf, I think we can transform the Select
into two Selects. i.e. the query would be:
{code:java}
val result = StreamTestData.getSmall3TupleDataStream(env).toTable(tEnv, 'a,
'b,'c)
.select(FuncRow('a) as 'a)
.select('a.flatten())
{code}
So that the result of FuncRow('a) can be reused. However, the two Selects will
be merged by Calcite MergeRules(ProjectMergeRule, CalcMergeRule, ...). I opened
a discussion on Calcite dev [mailing
list|https://lists.apache.org/thread.html/096a6b75675f6e2a341c440df1afec00c0365c35f7e9b8cced310ad0@%3Cdev.calcite.apache.org%3E].
If it is accepted, we can solve this problem accordingly.
As for reuse problem for deterministic udfs, I think we can add some reuse
logic during codegen. I created another jira(FLINK-10956) for it.
> TableAPI flatten() calculated value error
> -----------------------------------------
>
> Key: FLINK-10834
> URL: https://issues.apache.org/jira/browse/FLINK-10834
> Project: Flink
> Issue Type: Bug
> Components: Table API & SQL
> Reporter: sunjincheng
> Assignee: Hequn Cheng
> Priority: Major
> Fix For: 1.7.1
>
>
> We have a UDF as follows:
> {code:java}
> object FuncRow extends ScalarFunction {
> def eval(v: Int): Row = {
> val version = "" + new Random().nextInt()
> val row = new Row(3)
> row.setField(0, version)
> row.setField(1, version)
> row.setField(2, version)
> row
> }
> override def isDeterministic: Boolean = false
> override def getResultType(signature: Array[Class[_]]): TypeInformation[_] =
> Types.ROW(Types.STRING, Types.STRING, Types.STRING)
> }
> {code}
> Do the following Query:
> {code:sql}
> val data = new mutable.MutableList[(Int, Long, String)]
> data.+=((1, 1L, "Hi"))
> val ds = env.fromCollection(data).toTable(tEnv, 'a, 'b,'c)
> .select(FuncRow('a).flatten()).as('v1, 'v2, 'v3)
> {code}
> The result is : -1189206469,-151367792,1988676906
> The result expected by the user should be: v1==v2==v3 .
> It looks the real reason is that there is no result of the reuse in codegen.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)