From 05b616a3b97adef94839418b54b668e6a62c0a49 Mon Sep 17 00:00:00 2001 From: jipengli Date: Wed, 6 Mar 2024 12:00:11 +0800 Subject: [PATCH] [improvement](headless) queryStruct aggregator add alias --- .../tencent/supersonic/common/pojo/Aggregator.java | 2 ++ .../headless/api/pojo/request/QueryStructReq.java | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/tencent/supersonic/common/pojo/Aggregator.java b/common/src/main/java/com/tencent/supersonic/common/pojo/Aggregator.java index e535de293..1f2da6ddb 100644 --- a/common/src/main/java/com/tencent/supersonic/common/pojo/Aggregator.java +++ b/common/src/main/java/com/tencent/supersonic/common/pojo/Aggregator.java @@ -19,6 +19,8 @@ public class Aggregator { private List args; + private String alias; + public Aggregator() { } diff --git a/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/request/QueryStructReq.java b/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/request/QueryStructReq.java index 4cb35898c..78fe9b7b4 100644 --- a/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/request/QueryStructReq.java +++ b/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/request/QueryStructReq.java @@ -13,6 +13,10 @@ import com.tencent.supersonic.common.util.DateModeUtils; import com.tencent.supersonic.common.util.SqlFilterUtils; import com.tencent.supersonic.common.util.jsqlparser.SqlAddHelper; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import lombok.Data; import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.JSQLParserException; @@ -36,11 +40,6 @@ import org.apache.logging.log4j.util.Strings; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - @Data @Slf4j @@ -208,7 +207,8 @@ private String buildSql(QueryStructReq queryStructReq, boolean isBizName) throws } sumFunction.setParameters(new ExpressionList(new Column(columnName))); SelectExpressionItem selectExpressionItem = new SelectExpressionItem(sumFunction); - selectExpressionItem.setAlias(new Alias(columnName)); + String alias = StringUtils.isNotBlank(aggregator.getAlias()) ? aggregator.getAlias() : columnName; + selectExpressionItem.setAlias(new Alias(alias)); selectItems.add(selectExpressionItem); } }