You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-zh@flink.apache.org by 张洪涛 <ho...@163.com> on 2019/03/20 06:40:57 UTC
[Blink]Cep SQL code generator bug
Hi
当CEP SQL Pattern中出现aggregate 操作 并且SQL code generator 没有split 情况下 code generator 会出现问题
TableConfigOptions.SQL_CODEGEN_LENGTH_MAX 设置为默认 即48 * 1024
SQL Example
SELECT *
FROM source
MATCH_RECOGNIZE (
PARTITION BY userId
ORDER BY proctime
MEASURES
...
SUM(e1.price) as price,
e1.behavior as behavior,
e1.`timestamp` as `timestamp`
ONE ROW PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (e1+ e2)
DEFINE
e1 as SUM(e1.price) > 10000
);
code generator 生成的code 如下 (部分)
可以看到 isNull$26, field$26 在agg函数的scope是没有定义的 而是被定义到了其他函数中
private org.apache.flink.table.dataformat.GenericRow transformRowForAgg_variable$8(org.apache.flink.table.dataformat.BaseRow inAgg) {
org.apache.flink.table.dataformat.GenericRow result$25 = new org.apache.flink.table.dataformat.GenericRow(1);
isNull$26 = inAgg.isNullAt(2);
field$26 = -1;
if (!isNull$26) {
field$26 = inAgg.getInt(2);
}
if (isNull$26) {
result$25.update(0, null);
} else {
result$25.update(0, field$26);
}
return result$25;
}
试着通过修改MatchCodeGenerator.scala代码可以修复 ,但是不确定是否最佳方案
+++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/MatchCodeGenerator.scala
@@ -351,6 +351,7 @@ class MatchCodeGenerator(
j"""
public class $funcName extends ${functionClass.getCanonicalName} {
${ctx.reuseMemberCode()}
+ ${ctx.reuseFieldCode()} // 在没有code split 的时候 生成reuseFieldCode
${reusePatternLists()}
${reuseClassifierLists()}
${ctx.reusePerRecordCode()}
- ${ctx.reuseFieldCode()} // 将此行注释
${ctx.reuseInputUnboxingCode()}
$bodyCode
}
--
Best Regards,
HongTao