Render select item aliases for sub queries in from clause to avoid possible alias collision
This commit is contained in:
parent
23098ca254
commit
352970604d
|
@ -388,6 +388,11 @@ public class OracleSqlAstTranslator<T extends JdbcOperation> extends AbstractSql
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsDuplicateSelectItemsInQueryGroup() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsRowValueConstructorSyntax() {
|
||||
return false;
|
||||
|
|
|
@ -1550,6 +1550,11 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
|||
appendSql( "select" );
|
||||
appendSql( queryGroupAlias );
|
||||
appendSql( ".* from " );
|
||||
// We need to assign aliases when we render a query spec as sub query to avoid clashing aliases
|
||||
this.needsSelectAliases = this.needsSelectAliases || hasDuplicateSelectItems( querySpec );
|
||||
}
|
||||
else if ( !supportsDuplicateSelectItemsInQueryGroup() ) {
|
||||
this.needsSelectAliases = this.needsSelectAliases || hasDuplicateSelectItems( querySpec );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1589,10 +1594,23 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
|||
}
|
||||
}
|
||||
|
||||
private boolean hasDuplicateSelectItems(QuerySpec querySpec) {
|
||||
final List<SqlSelection> sqlSelections = querySpec.getSelectClause().getSqlSelections();
|
||||
final Map<Expression, Void> map = new IdentityHashMap<>( sqlSelections.size() );
|
||||
for ( int i = 0; i < sqlSelections.size(); i++ ) {
|
||||
map.put( sqlSelections.get( i ).getExpression(), null );
|
||||
}
|
||||
return map.size() != sqlSelections.size();
|
||||
}
|
||||
|
||||
protected boolean supportsSimpleQueryGrouping() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean supportsDuplicateSelectItemsInQueryGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected final void visitWhereClause(Predicate whereClauseRestrictions) {
|
||||
if ( whereClauseRestrictions != null && !whereClauseRestrictions.isEmpty() || additionalWherePredicate != null ) {
|
||||
appendSql( " where " );
|
||||
|
|
Loading…
Reference in New Issue