(improvement)(chat) remove space before function in semantic parser (#175)

This commit is contained in:
lexluo09
2023-10-08 18:24:18 +08:00
committed by GitHub
parent e3b3e8861d
commit d9bab899fe
2 changed files with 11 additions and 16 deletions

View File

@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@@ -384,7 +383,7 @@ public class CalculateAggConverter implements SemanticConverter {
}
private static String getAllJoinSelect(QueryStructReq queryStructCmd, String alias) {
private String getAllJoinSelect(QueryStructReq queryStructCmd, String alias) {
String aggStr = queryStructCmd.getAggregators().stream()
.map(f -> getSelectField(f, alias) + " as " + getSelectField(f, "")
+ "_roll")
@@ -418,23 +417,18 @@ public class CalculateAggConverter implements SemanticConverter {
}
private static String getAllSelect(QueryStructReq queryStructCmd, String alias) {
private String getAllSelect(QueryStructReq queryStructCmd, String alias) {
String aggStr = queryStructCmd.getAggregators().stream().map(f -> getSelectField(f, alias))
.collect(Collectors.joining(","));
return CollectionUtils.isEmpty(queryStructCmd.getGroups()) ? aggStr
: alias + String.join("," + alias, queryStructCmd.getGroups()) + "," + aggStr;
}
private static String getSelectField(final Aggregator agg, String alias) {
private String getSelectField(final Aggregator agg, String alias) {
if (agg.getFunc().equals(AggOperatorEnum.RATIO_OVER) || agg.getFunc().equals(AggOperatorEnum.RATIO_ROLL)) {
return alias + agg.getColumn();
}
if (CollectionUtils.isEmpty(agg.getArgs())) {
return agg.getFunc() + "( " + alias + agg.getColumn() + " ) AS " + agg.getColumn() + " ";
}
return agg.getFunc() + "( " + agg.getArgs().stream().map(arg ->
arg.equals(agg.getColumn()) ? arg : (StringUtils.isNumeric(arg) ? arg : ("'" + arg + "'"))
).collect(Collectors.joining(",")) + " ) AS " + agg.getColumn() + " ";
return sqlGenerateUtils.getSelectField(agg);
}
private String getGroupBy(QueryStructReq queryStructCmd) {

View File

@@ -1,14 +1,15 @@
package com.tencent.supersonic.semantic.query.utils;
import static com.tencent.supersonic.common.pojo.Constants.JOIN_UNDERLINE;
import com.tencent.supersonic.common.pojo.Aggregator;
import com.tencent.supersonic.semantic.api.model.enums.TimeDimensionEnum;
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
import com.tencent.supersonic.common.pojo.Aggregator;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import static com.tencent.supersonic.common.pojo.Constants.JOIN_UNDERLINE;
@Component
@Slf4j
@@ -54,9 +55,9 @@ public class SqlGenerateUtils {
public String getSelectField(final Aggregator agg) {
if (CollectionUtils.isEmpty(agg.getArgs())) {
return agg.getFunc() + " ( " + agg.getColumn() + " ) AS " + agg.getColumn() + " ";
return agg.getFunc() + "( " + agg.getColumn() + " ) AS " + agg.getColumn() + " ";
}
return agg.getFunc() + " ( " + agg.getArgs().stream().map(arg ->
return agg.getFunc() + "( " + agg.getArgs().stream().map(arg ->
arg.equals(agg.getColumn()) ? arg : (StringUtils.isNumeric(arg) ? arg : ("'" + arg + "'"))
).collect(Collectors.joining(",")) + " ) AS " + agg.getColumn() + " ";
}