Aggregation not working

Created on 7 June 2018, about 6 years ago
Updated 24 April 2023, about 1 year ago

If you are trying to use views aggregation, the aggregation of expression fields doesn't work. It doesn't wrap the expression with aggregation functions such as SUM, and it incorrectly adds the field to the GROUP BY clause.

After looking at the views_handler_field_views_raw_sql.inc file

I realised that you have bypassed the boilerplate query code which handles parameters (which seem to be used by the aggregation feature), so if you make the following changes, it seems to work for all aggregation functions except COUNT (which does weird things):

  function query() {
    
    // Make sure the table is available, and get the alias.
    $table_alias = $this->ensure_my_table();
    
    // Boilerplate from views_handler_field->query().
    $params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();

    $this->field_alias = $this->query->add_field(NULL, $this->options['raw_sql'], 'raw_sql_field', $params);

    // More boilerplate.
    $this->add_additional_fields();

  } // query

When you try to use the COUNT function, the Raw SQL form is changed to the default form and the custom expression is lost. I haven't worked out why this is happening.

πŸ› Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom dmoore

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024