Skip to content

Commit

Permalink
ql facade
Browse files Browse the repository at this point in the history
  • Loading branch information
saimu.msm committed Aug 10, 2023
1 parent 77704b0 commit a54e336
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private Map<Map<String, String>, Result> getTagsWithResults(QueryParam queryPara
if ("tsid".equals(name)) {
continue;
}
if ("timestamp".equals(name)) {
if ("timestamp".equals(name) || value.getDataType() == Value.DataType.Timestamp) {
point.setTimestamp(value.getTimestamp());
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ public QueryProto.QueryRequest convertRequest(DataQueryRequest request) {
}

QueryProto.Datasource.Builder datasourceBuilder = QueryProto.Datasource.newBuilder();
toProtoBean(datasourceBuilder, d);
Map<String, Object> objMap = J.toMap(J.toJson(d));
objMap.remove("select");
toProtoBean(datasourceBuilder, objMap);
Boolean aBoolean = tenantInitService.checkConditions(ms.getTenant(), ms.getWorkspace(),
datasourceBuilder.getMetric(), datasourceBuilder.getFiltersList());
if (!aBoolean) {
Expand Down Expand Up @@ -515,10 +517,11 @@ protected void parseQl(QueryDataSource d, MetricInfo metricInfo) {
if (StringUtils.isEmpty(expression)) {
selects.add("`" + columnName + "`");
} else {
selects.add(expression + " as " + "`" + columnName + "`");
selects.add(expression + " as " + columnName);
}
}
}
selects.add("`period`");
select.append(String.join(" , ", selects));
select.append(" from ").append(d.metric);
select.append(" where `period` <= ") //
Expand Down Expand Up @@ -562,22 +565,20 @@ protected void parseQl(QueryDataSource d, MetricInfo metricInfo) {
}
}
}
List<String> gbList = new ArrayList<>();
gbList.add("period");
if (!CollectionUtils.isEmpty(d.groupBy)) {
List<String> gbList = new ArrayList<>();
for (String gb : d.groupBy) {
if (!tags.contains(gb)) {
continue;
}
gbList.add(gb);
}
if (!CollectionUtils.isEmpty(gbList)) {
select.append(" group by `")//
.append(String.join("` , `", gbList)) //
.append("`");
}

}
select.append(" order by `period` acs");
select.append(" group by `")//
.append(String.join("` , `", gbList)) //
.append("`");
select.append(" order by `period` asc");
log.info("parse sql {}", select);
d.setQl(select.toString());
}
Expand Down

0 comments on commit a54e336

Please sign in to comment.