#1619 - Support aggregation formula on fetch clause e.g. query.fetch("machineUsage", "sum(totalKms)")

This commit is contained in:
rob bygrave committed 2019-01-23 16:45:47 +13:00
commit eb1bca805e
15 files changed
+572 -35

No files matched your search

@@ -2586,9 +2586,9 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
/**
* Return a 'dynamic property' used to read a formula.
*/
private STreeProperty findSqlTreeFormula(String formulaExpression) {
return dynamicProperty.computeIfAbsent(formulaExpression, (formula) -> new FormulaPropertyPath(this, formula).build());
private STreeProperty findSqlTreeFormula(String formula, String path) {
String key = formula + "-" + path;
return dynamicProperty.computeIfAbsent(key, (fullKey) -> new FormulaPropertyPath(this, formula, path).build());
}
/**
@@ -2597,9 +2597,9 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
* The property can be a dynamic formula or a well known bean property.
*/
@Override
public STreeProperty findPropertyWithDynamic(String propName) {
public STreeProperty findPropertyWithDynamic(String propName, String path) {
if (propName.indexOf('(') > -1) {
return findSqlTreeFormula(propName);
return findSqlTreeFormula(propName, path);
}
return _findBeanProperty(propName);
}
@@ -20,15 +20,17 @@ class FormulaPropertyPath {
private final String internalExpression;
private final String path;
private boolean countDistinct;
private String cast;
private String alias;
FormulaPropertyPath(BeanDescriptor<?> descriptor, String formula) {
FormulaPropertyPath(BeanDescriptor<?> descriptor, String formula, String path) {
this.descriptor = descriptor;
this.formula = formula;
this.path = path;
int openBracket = formula.indexOf('(');
int closeBracket = formula.lastIndexOf(')');
@@ -94,6 +96,11 @@ class FormulaPropertyPath {
DeployPropertyParser parser = descriptor.parser().setCatchFirst(true);
String parsed = parser.parse(internalExpression);
if (path != null) {
// fetch("machineStats", "sum(hours), sum(totalKms)")
parsed = parsed.replace("${}", "${" + path + "}");
}
ElPropertyDeploy firstProp = parser.getFirstProp();
ScalarType<?> scalarType;