Skip to content

Commit d417e51

Browse files
author
dapeng
committed
修复维表表明没有带有scope的问题
1 parent 5540db8 commit d417e51

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

core/src/main/java/com/dtstack/flink/sql/exec/ExecuteProcessHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private static void sqlTranslation(String localSqlPluginPath,
229229
}
230230
if (isSide) {
231231
//sql-dimensional table contains the dimension table of execution
232-
sideSqlExec.exec(result.getExecSql(), sideTableMap, tableEnv, registerTableCache, queryConfig, null, null);
232+
sideSqlExec.exec(result.getExecSql(), sideTableMap, tableEnv, registerTableCache, queryConfig, null, String.valueOf(scope));
233233
} else {
234234
LOG.info("----------exec sql without dimension join-----------");
235235
LOG.info("----------real sql exec is--------------------------\n{}", result.getExecSql());

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import com.google.common.collect.HashBasedTable;
2727
import com.google.common.collect.HashBiMap;
2828
import com.google.common.collect.Lists;
29-
import com.google.common.collect.Sets;
30-
import com.typesafe.config.ConfigException;
3129
import org.apache.calcite.sql.SqlAsOperator;
3230
import org.apache.calcite.sql.SqlBasicCall;
3331
import org.apache.calcite.sql.SqlDataTypeSpec;
@@ -49,7 +47,6 @@
4947
import java.util.Map;
5048
import java.util.Queue;
5149
import java.util.Set;
52-
import java.util.stream.Collector;
5350

5451
import static org.apache.calcite.sql.SqlKind.*;
5552
import static org.apache.calcite.sql.SqlKind.CASE;
@@ -191,25 +188,13 @@ public static void extractSelectFieldToFieldInfo(SqlNode fieldNode, String fromN
191188
}
192189
}
193190

194-
public static String buildInternalTableName(String left, char split, String right) {
195-
StringBuilder sb = new StringBuilder();
196-
return sb.append(left).append(split).append(right).toString();
197-
}
198-
199191
public static SqlBasicCall buildAsNodeByJoinInfo(JoinInfo joinInfo, SqlNode sqlNode0, String tableAlias) {
200192
SqlOperator operator = new SqlAsOperator();
201193

202194
SqlParserPos sqlParserPos = new SqlParserPos(0, 0);
203195
String newTableName = joinInfo.getNewTableName();
204-
String lefTbAlias = joinInfo.getLeftTableAlias();
205196

206-
if(Strings.isNullOrEmpty(lefTbAlias)){
207-
Set<String> fromTableSet = Sets.newHashSet();
208-
TableUtils.getFromTableInfo(joinInfo.getLeftNode(), fromTableSet);
209-
lefTbAlias = StringUtils.join(fromTableSet, "_");
210-
}
211-
212-
String newTableAlias = !StringUtils.isEmpty(tableAlias) ? tableAlias : buildInternalTableName(lefTbAlias, SPLIT, joinInfo.getRightTableAlias());
197+
String newTableAlias = !StringUtils.isEmpty(tableAlias) ? tableAlias : joinInfo.getNewTableAlias();
213198

214199
if (null == sqlNode0) {
215200
sqlNode0 = new SqlIdentifier(newTableName, null, sqlParserPos);
@@ -716,15 +701,15 @@ public static String buildTableNameWithScope(String leftTableName, String leftTa
716701
//兼容左边表是as 的情况
717702
String leftStr = Strings.isNullOrEmpty(leftTableName) ? leftTableAlias : leftTableName;
718703
String newName = leftStr + "_" + rightTableName;
719-
String newTableName = TableUtils.buildTableNameWithScope(newName, scope);
720704
if (CollectionUtils.isEmpty(existTableNames)) {
721-
return newName;
705+
return TableUtils.buildTableNameWithScope(newName, scope);
722706
}
707+
723708
if (!existTableNames.contains(newName)) {
724-
return newName;
709+
return TableUtils.buildTableNameWithScope(newName, scope);
725710
}
726-
return newName + "_" + System.currentTimeMillis();
727711

712+
return TableUtils.buildTableNameWithScope(newName, scope) + "_" + System.currentTimeMillis();
728713
}
729714

730715
}

0 commit comments

Comments
 (0)