Skip to content

Commit

Permalink
Add shorthand projection isNeedRewrite judgement (#33758)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingZC authored Nov 21, 2024
1 parent ed92560 commit 0ea667a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private SubstitutableColumnNameToken generateSQLToken(final ShorthandProjectionS
ColumnProjection columnProjection = (ColumnProjection) each;
boolean newAddedColumn = existColumnNames.add(columnProjection.getOriginalTable().getValue() + "." + columnProjection.getOriginalColumn().getValue());
Optional<EncryptTable> encryptTable = encryptRule.findEncryptTable(columnProjection.getOriginalTable().getValue());
if (encryptTable.isPresent() && encryptTable.get().isEncryptColumn(columnProjection.getOriginalColumn().getValue()) && !selectStatementContext.containsTableSubquery()) {
if (encryptTable.isPresent() && encryptTable.get().isEncryptColumn(columnProjection.getOriginalColumn().getValue()) && isNeedRewrite(selectStatementContext, subqueryType)) {
EncryptColumn encryptColumn = encryptTable.get().getEncryptColumn(columnProjection.getOriginalColumn().getValue());
projections.addAll(generateProjections(encryptColumn, columnProjection, subqueryType, newAddedColumn));
continue;
Expand All @@ -137,6 +137,13 @@ private SubstitutableColumnNameToken generateSQLToken(final ShorthandProjectionS
return new SubstitutableColumnNameToken(startIndex, segment.getStopIndex(), projections, selectStatementContext.getDatabaseType());
}

private boolean isNeedRewrite(final SelectStatementContext selectStatementContext, final SubqueryType subqueryType) {
if (SubqueryType.TABLE == subqueryType) {
return true;
}
return !selectStatementContext.containsTableSubquery();
}

private boolean isNeedRewrite(final SelectStatementContext selectStatementContext, final ColumnProjectionSegment columnSegment) {
SelectStatement sqlStatement = selectStatementContext.getSqlStatement();
if (sqlStatement.getWithSegment().isPresent() && !(sqlStatement.getFrom().isPresent() && sqlStatement.getFrom().get() instanceof SubqueryTableSegment)
Expand Down

0 comments on commit 0ea667a

Please sign in to comment.