Skip to content

Commit

Permalink
ISPN-15254 Support aggregation on entity with asterisk
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Nov 8, 2023
1 parent c8c7560 commit 298a15d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ setFunction
| ^(AVG { delegate.activateAggregation(AggregationFunction.AVG); } numericValueExpression)
| ^(MAX { delegate.activateAggregation(AggregationFunction.MAX); } numericValueExpression)
| ^(MIN { delegate.activateAggregation(AggregationFunction.MIN); } numericValueExpression)
| ^(COUNT (ASTERISK { delegate.activateAggregation(AggregationFunction.COUNT); } | (DISTINCT { delegate.activateAggregation(AggregationFunction.COUNT_DISTINCT); } | ALL { delegate.activateAggregation(AggregationFunction.COUNT); }) countFunctionArguments))
| ^(COUNT (ASTERISK { delegate.activateAsteriskAggregation(AggregationFunction.COUNT); } | (DISTINCT { delegate.activateAggregation(AggregationFunction.COUNT_DISTINCT); } | ALL { delegate.activateAggregation(AggregationFunction.COUNT); }) countFunctionArguments))
;
versionFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public String getOperator() {

void activateAggregation(AggregationFunction aggregationFunction);

void activateAsteriskAggregation(AggregationFunction aggregationFunction);

void deactivateAggregation();

void projectVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private enum Phase {

private final String queryString;

private boolean asteriskCount = false;

QueryRendererDelegateImpl(String queryString, ObjectPropertyHelper<TypeMetadata> propertyHelper) {
this.queryString = queryString;
this.propertyHelper = propertyHelper;
Expand Down Expand Up @@ -537,6 +539,12 @@ public void activateAggregation(AggregationFunction aggregationFunction) {
propertyPath = null;
}

@Override
public void activateAsteriskAggregation(AggregationFunction aggregationFunction) {
activateAggregation(aggregationFunction);
asteriskCount = true;
}

@Override
public void deactivateAggregation() {
aggregationFunction = null;
Expand Down Expand Up @@ -589,6 +597,19 @@ public void groupingValue(String collateName) {
groupBy = new ArrayList<>(ARRAY_INITIAL_LENGTH);
}
groupBy.add(resolveAlias(propertyPath));

if (!asteriskCount) {
return;
}
if (projections == null) {
projections = new ArrayList<>(ARRAY_INITIAL_LENGTH);
projectedTypes = new ArrayList<>(ARRAY_INITIAL_LENGTH);
projectedNullMarkers = new ArrayList<>(ARRAY_INITIAL_LENGTH);
}
projections.add(new CacheValueAggregationPropertyPath<>());
projectedTypes.add(null);
projectedNullMarkers.add(null);
asteriskCount = false;
}

private Object parameterValue(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public void test() {
query = queryFactory.create("select s.status, count(s) from org.infinispan.query.model.Sale s where s.day = :day group by s.status order by s.status");
query.setParameter("day", NUMBER_OF_DAYS / 2);
assertThat(query.list()).containsExactly(FULL_AGGREGATION_RESULT);
// no alias && count on entity
query = queryFactory.create("select status, count(*) from org.infinispan.query.model.Sale where day = :day group by status");
query.setParameter("day", NUMBER_OF_DAYS / 2);
assertThat(query.list()).containsExactly(FULL_AGGREGATION_RESULT);
}

public static HashMap<String, Sale> chunk(int day, Random random) {
Expand Down

0 comments on commit 298a15d

Please sign in to comment.