Skip to content

Problem using aggregation functions (string_agg), hasDQLFunction too restrictive #637

Open
@plfort

Description

@plfort

Hello,
How do you use the "string_agg" function with Postgresql ?
I tried like this :

 @GRID\Source(columns="id,tag,description,roles.role:string_agg:,",filterable=true,groupBy={"id"})
 @GRID\Column(title="rolesstring",field="roles.role:string_agg:,")

or

 @GRID\Source(columns="id,tag,description,roles.role:string_agg:','",filterable=true,groupBy={"id"})
 @GRID\Column(title="rolesstring",field="roles.role:string_agg:','")

It requires the glue character at second argument like ',' ';' or what ever, but the pattern described in hasDQLFunction only accept "word" as second argument :

    public function hasDQLFunction(&$matches = null)
    {
        $regex = '/(?P<all>(?P<field>\w+):(?P<function>\w+)(:)?(?P<parameters>\w*))$/';

        return ($matches === null) ? preg_match($regex, $this->field) : preg_match($regex, $this->field, $matches);
    }

Moreover, the generated alias triggers DQL error :

//APY\DataGridBundle\Grid\Source\Entity line 170
 $alias = str_replace('.', '::', $column->getId());

QueryException: [Syntax Error] line 0, col 60: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got ':'

SELECT _a.id, _a.tag, _a.description, _roles.role:string_agg:';' as roles::role:string_agg:';' FROM Options _a LEFT JOIN _a.roles _roles  GROUP BY _a.id ORDER BY _roles.role:string_agg:';' asc

I think it would be great to force the alias with annotation or improve the generation mechanism,
and modify the regex to allow other characters than word.

I did some tests to allow second parameter between quote with this regex :

 $regex = '/(?P<all>(?P<field>\w+):(?P<function>\w+)(:)?([\'"]?)(?P<parameters>[^\5]*)\5)$/';

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions