code: private MetricsAggregationBuilder getMetricsAggregation(Expression expression, EntityMetadata entityMetadata)
      {
          AggregateFunction function = (AggregateFunction) expression;
          MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                  entityMetadata.getPersistenceUnit());
          String jPAColumnName = KunderaCoreUtils.getJPAColumnName(function.toParsedText(), entityMetadata, metaModel);
  
          MetricsAggregationBuilder aggregationBuilder = null;
  
          switch (function.getIdentifier())
          {
          case Expression.MIN:
              aggregationBuilder = AggregationBuilders.min(function.toParsedText()).field(jPAColumnName);
              break;
          case Expression.MAX:
              aggregationBuilder = AggregationBuilders.max(function.toParsedText()).field(jPAColumnName);
              break;
          case Expression.SUM:
              aggregationBuilder = AggregationBuilders.sum(function.toParsedText()).field(jPAColumnName);
              break;
          case Expression.AVG:
              aggregationBuilder = AggregationBuilders.avg(function.toParsedText()).field(jPAColumnName);
              break;
          case Expression.COUNT:
              aggregationBuilder = AggregationBuilders.count(function.toParsedText()).field(jPAColumnName);
              break;
          }
          return aggregationBuilder;
      }
docs: Gets the aggregation.
  
  @param expression
  the expression
  @param entityMetadata
  the entity metadata
  @return the aggregation