|
26 | 26 | import com.google.common.collect.HashBasedTable; |
27 | 27 | import com.google.common.collect.HashBiMap; |
28 | 28 | import com.google.common.collect.Lists; |
29 | | -import com.google.common.collect.Sets; |
30 | | -import com.typesafe.config.ConfigException; |
31 | 29 | import org.apache.calcite.sql.SqlAsOperator; |
32 | 30 | import org.apache.calcite.sql.SqlBasicCall; |
33 | 31 | import org.apache.calcite.sql.SqlDataTypeSpec; |
|
49 | 47 | import java.util.Map; |
50 | 48 | import java.util.Queue; |
51 | 49 | import java.util.Set; |
52 | | -import java.util.stream.Collector; |
53 | 50 |
|
54 | 51 | import static org.apache.calcite.sql.SqlKind.*; |
55 | 52 | import static org.apache.calcite.sql.SqlKind.CASE; |
@@ -191,25 +188,13 @@ public static void extractSelectFieldToFieldInfo(SqlNode fieldNode, String fromN |
191 | 188 | } |
192 | 189 | } |
193 | 190 |
|
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 | | - |
199 | 191 | public static SqlBasicCall buildAsNodeByJoinInfo(JoinInfo joinInfo, SqlNode sqlNode0, String tableAlias) { |
200 | 192 | SqlOperator operator = new SqlAsOperator(); |
201 | 193 |
|
202 | 194 | SqlParserPos sqlParserPos = new SqlParserPos(0, 0); |
203 | 195 | String newTableName = joinInfo.getNewTableName(); |
204 | | - String lefTbAlias = joinInfo.getLeftTableAlias(); |
205 | 196 |
|
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(); |
213 | 198 |
|
214 | 199 | if (null == sqlNode0) { |
215 | 200 | sqlNode0 = new SqlIdentifier(newTableName, null, sqlParserPos); |
@@ -716,15 +701,15 @@ public static String buildTableNameWithScope(String leftTableName, String leftTa |
716 | 701 | //兼容左边表是as 的情况 |
717 | 702 | String leftStr = Strings.isNullOrEmpty(leftTableName) ? leftTableAlias : leftTableName; |
718 | 703 | String newName = leftStr + "_" + rightTableName; |
719 | | - String newTableName = TableUtils.buildTableNameWithScope(newName, scope); |
720 | 704 | if (CollectionUtils.isEmpty(existTableNames)) { |
721 | | - return newName; |
| 705 | + return TableUtils.buildTableNameWithScope(newName, scope); |
722 | 706 | } |
| 707 | + |
723 | 708 | if (!existTableNames.contains(newName)) { |
724 | | - return newName; |
| 709 | + return TableUtils.buildTableNameWithScope(newName, scope); |
725 | 710 | } |
726 | | - return newName + "_" + System.currentTimeMillis(); |
727 | 711 |
|
| 712 | + return TableUtils.buildTableNameWithScope(newName, scope) + "_" + System.currentTimeMillis(); |
728 | 713 | } |
729 | 714 |
|
730 | 715 | } |
0 commit comments