mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
(chat)(fix):not add group by if already has distinct (#685)
This commit is contained in:
@@ -26,6 +26,7 @@ import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import net.sf.jsqlparser.schema.Column;
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.Statement;
|
||||
import net.sf.jsqlparser.statement.select.Distinct;
|
||||
import net.sf.jsqlparser.statement.select.GroupByElement;
|
||||
import net.sf.jsqlparser.statement.select.OrderByElement;
|
||||
import net.sf.jsqlparser.statement.select.PlainSelect;
|
||||
@@ -384,6 +385,18 @@ public class SqlParserSelectHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasDistinct(String sql) {
|
||||
Select selectStatement = getSelect(sql);
|
||||
SelectBody selectBody = selectStatement.getSelectBody();
|
||||
|
||||
if (!(selectBody instanceof PlainSelect)) {
|
||||
return false;
|
||||
}
|
||||
PlainSelect plainSelect = (PlainSelect) selectBody;
|
||||
Distinct distinct = plainSelect.getDistinct();
|
||||
return Objects.nonNull(distinct);
|
||||
}
|
||||
|
||||
public static boolean isLogicExpression(Expression whereExpression) {
|
||||
return whereExpression instanceof AndExpression || (whereExpression instanceof OrExpression
|
||||
|| (whereExpression instanceof XorExpression));
|
||||
|
||||
Reference in New Issue
Block a user