mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 05:43:51 +00:00
[improvement][headless]Simplify query sql and fix demo.
This commit is contained in:
@@ -65,7 +65,7 @@ public class SqlQueryParser implements QueryParser {
|
|||||||
// check if there are fields not matched with any metric or dimension
|
// check if there are fields not matched with any metric or dimension
|
||||||
if (allFields.size() > metricSchemas.size() + dimensions.size()) {
|
if (allFields.size() > metricSchemas.size() + dimensions.size()) {
|
||||||
queryStatement
|
queryStatement
|
||||||
.setErrMsg("There are fields in the SQL not matched with any semantic column.");
|
.setErrMsg("There are querying columns in the SQL not matched with any semantic field.");
|
||||||
queryStatement.setStatus(1);
|
queryStatement.setStatus(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ public class DimensionNode extends SemanticNode {
|
|||||||
public static SqlNode build(Dimension dimension, SqlValidatorScope scope, EngineType engineType)
|
public static SqlNode build(Dimension dimension, SqlValidatorScope scope, EngineType engineType)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
SqlNode sqlNode = parse(dimension.getExpr(), scope, engineType);
|
SqlNode sqlNode = parse(dimension.getExpr(), scope, engineType);
|
||||||
return buildAs(dimension.getName(), sqlNode);
|
if (!dimension.getName().equals(dimension.getExpr())) {
|
||||||
|
sqlNode = buildAs(dimension.getName(), sqlNode);
|
||||||
|
}
|
||||||
|
return sqlNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SqlNode> expand(Dimension dimension, SqlValidatorScope scope,
|
public static List<SqlNode> expand(Dimension dimension, SqlValidatorScope scope,
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ public class MeasureNode extends SemanticNode {
|
|||||||
|
|
||||||
public static SqlNode buildNonAgg(String alias, Measure measure, SqlValidatorScope scope,
|
public static SqlNode buildNonAgg(String alias, Measure measure, SqlValidatorScope scope,
|
||||||
EngineType engineType) throws Exception {
|
EngineType engineType) throws Exception {
|
||||||
|
if (measure.getExpr() == null) {
|
||||||
|
return getExpr(measure, alias, scope, engineType);
|
||||||
|
} else {
|
||||||
return buildAs(measure.getName(), getExpr(measure, alias, scope, engineType));
|
return buildAs(measure.getName(), getExpr(measure, alias, scope, engineType));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static SqlNode buildAgg(Measure measure, boolean noAgg, SqlValidatorScope scope,
|
public static SqlNode buildAgg(Measure measure, boolean noAgg, SqlValidatorScope scope,
|
||||||
EngineType engineType) throws Exception {
|
EngineType engineType) throws Exception {
|
||||||
|
|||||||
@@ -317,12 +317,12 @@ public class SqlGenerateUtils {
|
|||||||
|
|
||||||
public String getExpr(Measure measure, AggOption aggOption) {
|
public String getExpr(Measure measure, AggOption aggOption) {
|
||||||
if (AggOperatorEnum.COUNT_DISTINCT.getOperator().equalsIgnoreCase(measure.getAgg())) {
|
if (AggOperatorEnum.COUNT_DISTINCT.getOperator().equalsIgnoreCase(measure.getAgg())) {
|
||||||
return AggOption.NATIVE.equals(aggOption) ? measure.getBizName()
|
return AggOption.NATIVE.equals(aggOption) ? measure.getExpr()
|
||||||
: AggOperatorEnum.COUNT.getOperator() + " ( " + AggOperatorEnum.DISTINCT + " "
|
: AggOperatorEnum.COUNT.getOperator() + " ( " + AggOperatorEnum.DISTINCT + " "
|
||||||
+ measure.getBizName() + " ) ";
|
+ measure.getExpr() + " ) ";
|
||||||
}
|
}
|
||||||
return AggOption.NATIVE.equals(aggOption) ? measure.getBizName()
|
return AggOption.NATIVE.equals(aggOption) ? measure.getExpr()
|
||||||
: measure.getAgg() + " ( " + measure.getBizName() + " ) ";
|
: measure.getAgg() + " ( " + measure.getExpr() + " ) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExpr(MetricResp metricResp) {
|
public String getExpr(MetricResp metricResp) {
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ public class ModelConverter {
|
|||||||
|
|
||||||
public static ModelDO convert(ModelReq modelReq, User user) {
|
public static ModelDO convert(ModelReq modelReq, User user) {
|
||||||
ModelDO modelDO = new ModelDO();
|
ModelDO modelDO = new ModelDO();
|
||||||
ModelDetail modelDetail = createModelDetail(modelReq);
|
// ModelDetail modelDetail = createModelDetail(modelReq);
|
||||||
modelReq.createdBy(user.getName());
|
modelReq.createdBy(user.getName());
|
||||||
BeanMapper.mapper(modelReq, modelDO);
|
BeanMapper.mapper(modelReq, modelDO);
|
||||||
modelDO.setStatus(StatusEnum.ONLINE.getCode());
|
modelDO.setStatus(StatusEnum.ONLINE.getCode());
|
||||||
modelDO.setModelDetail(JSONObject.toJSONString(modelDetail));
|
modelDO.setModelDetail(JSONObject.toJSONString(modelReq.getModelDetail()));
|
||||||
modelDO.setDrillDownDimensions(JSONObject.toJSONString(modelReq.getDrillDownDimensions()));
|
modelDO.setDrillDownDimensions(JSONObject.toJSONString(modelReq.getDrillDownDimensions()));
|
||||||
if (modelReq.getExt() != null) {
|
if (modelReq.getExt() != null) {
|
||||||
modelDO.setExt(JSONObject.toJSONString(modelReq.getExt()));
|
modelDO.setExt(JSONObject.toJSONString(modelReq.getExt()));
|
||||||
@@ -264,17 +264,14 @@ public class ModelConverter {
|
|||||||
|
|
||||||
private static ModelDetail createModelDetail(ModelReq modelReq) {
|
private static ModelDetail createModelDetail(ModelReq modelReq) {
|
||||||
ModelDetail modelDetail = new ModelDetail();
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
List<Measure> measures = modelReq.getModelDetail().getMeasures();
|
// List<Measure> measures = modelReq.getModelDetail().getMeasures();
|
||||||
if (measures == null) {
|
// for (Measure measure : measures) {
|
||||||
measures = Lists.newArrayList();
|
// if (StringUtils.isBlank(measure.getBizName())) {
|
||||||
}
|
// continue;
|
||||||
for (Measure measure : measures) {
|
// }
|
||||||
if (StringUtils.isBlank(measure.getBizName())) {
|
// measure.setExpr(measure.getBizName());
|
||||||
continue;
|
// measure.setBizName(String.format("%s_%", modelReq.getBizName(), measure.getExpr()));
|
||||||
}
|
// }
|
||||||
measure.setExpr(measure.getBizName());
|
|
||||||
measure.setBizName(String.format("%s_%s", modelReq.getBizName(), measure.getExpr()));
|
|
||||||
}
|
|
||||||
BeanMapper.mapper(modelReq.getModelDetail(), modelDetail);
|
BeanMapper.mapper(modelReq.getModelDetail(), modelDetail);
|
||||||
return modelDetail;
|
return modelDetail;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,10 +307,9 @@ public class S2VisitsDemo extends S2BaseDemo {
|
|||||||
metricReq.setDescription("停留时长");
|
metricReq.setDescription("停留时长");
|
||||||
metricReq.setClassifications(Collections.singletonList("核心指标"));
|
metricReq.setClassifications(Collections.singletonList("核心指标"));
|
||||||
MetricDefineByMeasureParams metricTypeParams = new MetricDefineByMeasureParams();
|
MetricDefineByMeasureParams metricTypeParams = new MetricDefineByMeasureParams();
|
||||||
metricTypeParams.setExpr("s2_stay_time_statis_stay_hours");
|
metricTypeParams.setExpr("stay_hours");
|
||||||
List<Measure> measures = new ArrayList<>();
|
List<Measure> measures = new ArrayList<>();
|
||||||
Measure measure = new Measure("停留时长", "s2_stay_time_statis_stay_hours",
|
Measure measure = new Measure("停留时长", "stay_hours", AggOperatorEnum.SUM.getOperator(), 0);
|
||||||
AggOperatorEnum.SUM.getOperator(), 0);
|
|
||||||
measures.add(measure);
|
measures.add(measure);
|
||||||
metricTypeParams.setMeasures(measures);
|
metricTypeParams.setMeasures(measures);
|
||||||
metricReq.setMetricDefineByMeasureParams(metricTypeParams);
|
metricReq.setMetricDefineByMeasureParams(metricTypeParams);
|
||||||
@@ -329,10 +328,9 @@ public class S2VisitsDemo extends S2BaseDemo {
|
|||||||
metricReq.setBizName("pv");
|
metricReq.setBizName("pv");
|
||||||
metricReq.setDescription("一段时间内用户的访问次数");
|
metricReq.setDescription("一段时间内用户的访问次数");
|
||||||
MetricDefineByMeasureParams metricTypeParams = new MetricDefineByMeasureParams();
|
MetricDefineByMeasureParams metricTypeParams = new MetricDefineByMeasureParams();
|
||||||
metricTypeParams.setExpr("s2_pv_uv_statis_pv");
|
metricTypeParams.setExpr("pv");
|
||||||
List<Measure> measures = new ArrayList<>();
|
List<Measure> measures = new ArrayList<>();
|
||||||
Measure measure =
|
Measure measure = new Measure("访问次数", "pv", AggOperatorEnum.SUM.getOperator(), 0);
|
||||||
new Measure("访问次数", "s2_pv_uv_statis_pv", AggOperatorEnum.SUM.getOperator(), 0);
|
|
||||||
measures.add(measure);
|
measures.add(measure);
|
||||||
metricTypeParams.setMeasures(measures);
|
metricTypeParams.setMeasures(measures);
|
||||||
metricReq.setMetricDefineByMeasureParams(metricTypeParams);
|
metricReq.setMetricDefineByMeasureParams(metricTypeParams);
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class MetricTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SetSystemProperty(key = "s2.test", value = "true")
|
||||||
public void testMetricFilter() throws Exception {
|
public void testMetricFilter() throws Exception {
|
||||||
QueryResult actualResult = submitNewChat("alice的访问次数", agent.getId());
|
QueryResult actualResult = submitNewChat("alice的访问次数", agent.getId());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user