hydrateRangeAggregation example

$min = $rows[0][$name . '.min'] ?? null;
                $max = $rows[0][$name . '.max'] ?? null;
                $avg = isset($rows[0][$name . '.avg']) ? (float) $rows[0][$name . '.avg'] : null;
                $sum = isset($rows[0][$name . '.sum']) ? (float) $rows[0][$name . '.sum'] : null;

                return new StatsResult($aggregation->getName()$min$max$avg$sum);

            case $aggregation instanceof EntityAggregation:
                return $this->hydrateEntityAggregation($aggregation$rows$context);
            case $aggregation instanceof RangeAggregation:
                return $this->hydrateRangeAggregation($aggregation$rows);
            default:
                throw new InvalidAggregationQueryException(sprintf('Aggregation of type %s not supported', $aggregation::class));
        }
    }

    /** * @param array<array<string, mixed>> $rows */
    private function hydrateEntityAggregation(
        EntityAggregation $aggregation,
        array $rows,
        


                return $this->hydrateAggregation($nested$nestedResult$context);

            case $aggregation instanceof DateHistogramAggregation:
                return $this->hydrateDateHistogram($aggregation$result$context);

            case $aggregation instanceof TermsAggregation:
                return $this->hydrateTermsAggregation($aggregation$result$context);

            case $aggregation instanceof RangeAggregation:
                return $this->hydrateRangeAggregation($aggregation$result);

            default:
                throw new \RuntimeException(sprintf('Provided aggregation of class %s is not supported', $aggregation::class));
        }
    }

    private function hydrateEntityAggregation(EntityAggregation $aggregation, array $result, Context $context): EntityResult
    {
        if (\array_key_exists($aggregation->getName()$result)) {
            $result = $result[$aggregation->getName()];
        }

        
Home | Imprint | This part of the site doesn't use cookies.