DateHistogramAggregation
$aggregation,
QueryBuilder
$query,
EntityDefinition
$definition,
Context
$context ): void
{ $accessor =
$this->queryHelper->
getFieldAccessor($aggregation->
getField(),
$definition,
$definition->
getEntityName(),
$context);
if ($this->timeZoneSupportEnabled &&
$aggregation->
getTimeZone()) { $accessor = 'CONVERT_TZ(' .
$accessor . ', "UTC", "' .
$aggregation->
getTimeZone() . '")';
} $groupBy =
match ($aggregation->
getInterval()) { DateHistogramAggregation::PER_MINUTE => 'DATE_FORMAT(' .
$accessor . ', \'%Y-%m-%d %H:%i\')',
DateHistogramAggregation::PER_HOUR => 'DATE_FORMAT(' .
$accessor . ', \'%Y-%m-%d %H\')',
DateHistogramAggregation::PER_DAY => 'DATE_FORMAT(' .
$accessor . ', \'%Y-%m-%d\')',
DateHistogramAggregation::PER_WEEK => 'DATE_FORMAT(' .
$accessor . ', \'%Y-%v\')',
DateHistogramAggregation::PER_MONTH => 'DATE_FORMAT(' .
$accessor . ', \'%Y-%m\')',
DateHistogramAggregation::PER_QUARTER => 'CONCAT(DATE_FORMAT(' .
$accessor . ', \'%Y\'), \'-\', QUARTER(' .
$accessor . '))',
DateHistogramAggregation::PER_YEAR => 'DATE_FORMAT(' .
$accessor . ', \'%Y\')',
default =>
throw new \
RuntimeException('Provided date format is not supported'
),
};
$query->
addGroupBy($groupBy);