Skip to content

Commit 2f6d5bb

Browse files
committed
[hotfix-32959][core] opt join dim table double group retract
1 parent fa95faf commit 2f6d5bb

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

core/src/main/java/com/dtstack/flink/sql/side/SideSqlExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public void exec(String sql,
133133
sideSQLParser.setLocalTableCache(localTableCache);
134134
Queue<Object> exeQueue = sideSQLParser.getExeQueue(sql, sideTableMap.keySet(), scope);
135135
Object pollObj = null;
136+
// create view中是否包含维表
137+
boolean includeDimTable = false;
136138

137139
while ((pollObj = exeQueue.poll()) != null) {
138140

@@ -175,9 +177,13 @@ public void exec(String sql,
175177
}
176178

177179
localTableCache.put(createView.getTableName(), table);
180+
if(includeDimTable){
181+
dimTableNewTable.put(createView.getTableName(), table);
182+
}
178183
}
179-
184+
includeDimTable = false;
180185
} else if (pollObj instanceof JoinInfo) {
186+
includeDimTable = true;
181187
LOG.info("----------exec join info----------\n{}", pollObj.toString());
182188
joinFun(pollObj, localTableCache, dimTableNewTable,sideTableMap, tableEnv);
183189
}

core/src/main/java/com/dtstack/flink/sql/util/TableUtils.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -850,31 +850,29 @@ public static boolean checkIsDimTableGroupBy(SqlNode sqlNode, Collection<String>
850850
// 2.(sub query) as alias group by
851851
// 3.tableName group by
852852
// 4.tableName as alias group by
853-
// 5.tableName no group by
854-
// 6.tableName as alias no group by
855-
856-
// 没有group by:5.no group by
857-
if (fromNode.getKind() == IDENTIFIER
858-
&& (groupNodeList == null || groupNodeList.size() == 0)) {
859-
return false;
860-
}
853+
// 5.others return false
861854

862855
// (子查询) group by:1.(sub query) group by
863856
if (fromNode.getKind() == SELECT) {
864857
return checkIsDimTableGroupBy(fromNode, newRegisterTableList);
865858
}
866859

867860
// 表名 as 别名 group by、(子查询) as 别名 group by、表名 group by
868-
if (fromNode.getKind() == AS) {
869-
// 表名 as 别名 group by:4.tableName as alias group by
870-
SqlNode operand = ((SqlBasicCall) fromNode).getOperands()[0];
871-
// (子查询) as 别名 group by:2.(sub query) as alias group by
872-
if (operand.getKind() != IDENTIFIER) {
873-
return checkIsDimTableGroupBy(fromNode, newRegisterTableList);
861+
if (fromNode.getKind() == AS || fromNode.getKind() == IDENTIFIER) {
862+
SqlNode operand;
863+
// 表名 group by:3.tableName group by
864+
if (fromNode.getKind() == IDENTIFIER) {
865+
operand = fromNode;
866+
} else {
867+
// 表名 as 别名 group by:4.tableName as alias group by
868+
operand = ((SqlBasicCall) fromNode).getOperands()[0];
869+
// (子查询) as 别名 group by:2.(sub query) as alias group by
870+
if (operand.getKind() != IDENTIFIER) {
871+
return checkIsDimTableGroupBy(fromNode, newRegisterTableList);
872+
}
874873
}
875874

876875
// 最里层是表名 group by,且group by字段不为空,且表名包含在维表中
877-
// 6.tableName as alias no group by,会在这一层过滤掉
878876
if (operand.getKind() == IDENTIFIER
879877
&& groupNodeList != null
880878
&& groupNodeList.size() != 0

0 commit comments

Comments
 (0)