mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-15 14:36:47 +00:00
(improvement)(chat) Special handling for count_distinct operator during SQL correcting and explaining (#320)
This commit is contained in:
@@ -41,5 +41,16 @@ public enum AggOperatorEnum {
|
||||
return AggOperatorEnum.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if aggType is count_Distinct type
|
||||
* 1.outer SQL parses the count_distinct(field) operator as count(DISTINCT field).
|
||||
* 2.tableSQL generates aggregation that ignores the count_distinct operator.
|
||||
* @param aggType aggType
|
||||
* @return is count_Distinct type or not
|
||||
*/
|
||||
public static boolean isCountDistinct(String aggType) {
|
||||
return null != aggType && aggType.toUpperCase().equals(COUNT_DISTINCT.getOperator());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.Function;
|
||||
@@ -74,7 +76,12 @@ public class SqlParserSelectFunctionHelper {
|
||||
return null;
|
||||
}
|
||||
Function sumFunction = new Function();
|
||||
sumFunction.setName(aggregateName);
|
||||
if (AggOperatorEnum.isCountDistinct(aggregateName)) {
|
||||
sumFunction.setName("count");
|
||||
sumFunction.setDistinct(true);
|
||||
} else {
|
||||
sumFunction.setName(aggregateName);
|
||||
}
|
||||
sumFunction.setParameters(new ExpressionList(expression));
|
||||
return sumFunction;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user