增加 平均值的批量处理方法
This commit is contained in:
@@ -86,6 +86,7 @@ public interface InfluxDbSqlConstant {
|
||||
String MAX = "MAX";
|
||||
String MIN = "MIN";
|
||||
String AVG = "MEAN";
|
||||
String CP95 = "CP95";
|
||||
String MEDIAN = "MEDIAN";
|
||||
String MODE = "MODE";
|
||||
String SPREAD = "SPREAD";
|
||||
|
||||
@@ -132,17 +132,18 @@ public class InfluxQueryWrapper {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public <T, R> InfluxQueryWrapper select(String columnName,String resultColumnName) {
|
||||
|
||||
public <T, R> InfluxQueryWrapper select(String columnName, String resultColumnName) {
|
||||
StringBuilder selectFragment = new StringBuilder();
|
||||
|
||||
selectFragment.append(StrPool.C_SPACE)
|
||||
.append(columnName)
|
||||
.append(StrPool.C_SPACE)
|
||||
.append(InfluxDbSqlConstant.AS)
|
||||
.append(StrPool.C_SPACE)
|
||||
.append(resultColumnName)
|
||||
.append(StrPool.C_SPACE);
|
||||
selectColumns.add(selectFragment+"");
|
||||
.append(columnName)
|
||||
.append(StrPool.C_SPACE)
|
||||
.append(InfluxDbSqlConstant.AS)
|
||||
.append(StrPool.C_SPACE)
|
||||
.append(resultColumnName)
|
||||
.append(StrPool.C_SPACE);
|
||||
selectColumns.add(selectFragment + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -172,7 +173,6 @@ public class InfluxQueryWrapper {
|
||||
// }
|
||||
|
||||
|
||||
|
||||
/************常见的简单函数处理比如max/min/mean/percentile****************/
|
||||
|
||||
/***
|
||||
@@ -267,7 +267,7 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, R> InfluxQueryWrapper mean(String columnName) {
|
||||
public InfluxQueryWrapper mean(String columnName) {
|
||||
String selectFragment = InfluxDbSqlConstant.AVG +
|
||||
InfluxDbSqlConstant.LBK +
|
||||
InfluxDbSqlConstant.DQM +
|
||||
@@ -281,6 +281,25 @@ public class InfluxQueryWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
/***
|
||||
* 批量获取指定字段平均值
|
||||
* @author hongawen
|
||||
* @param prefix 表字段名
|
||||
* @param suffix 映射名称
|
||||
* @return InfluxQueryWrapper
|
||||
* 输出 mean(prefix+diffContent+suffix) as prefix+diffContent+suffix
|
||||
*/
|
||||
public InfluxQueryWrapper meanSamePrefixAndSuffix(String prefix, String suffix, List<Object> diffContent) {
|
||||
if (CollectionUtil.isEmpty(diffContent)) {
|
||||
throw new RuntimeException("查询数值集合为空,请校验!");
|
||||
}
|
||||
for (Object obj : diffContent) {
|
||||
String fieldName = prefix + obj + suffix;
|
||||
this.mean(fieldName);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 统计中位数
|
||||
@@ -1310,7 +1329,7 @@ public class InfluxQueryWrapper {
|
||||
|
||||
public final <T, R> InfluxQueryWrapper groupBy(String columnName) {
|
||||
|
||||
groupColumn.add(columnName);
|
||||
groupColumn.add(columnName);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user