Skip to content

Support nested recursive CTEs #18955

@Tpt

Description

@Tpt

Is your feature request related to a problem or challenge?

SPARQL support nested property paths (i.e. regular expressions in the graph). For example (p1 / p2+)+ to state "follow and edge labeled p1 then any number of edges labeled p2, all of this any number of times".

This can be implemented in SQL using nested recursive CTEs like

WITH RECURSIVE outer_cte AS (
    SELECT start, end FROM graph WHERE label = 'p1' 
    UNION (
        WITH  RECURSIVE nested_cte AS (
           SELECT start, end FROM graph WHERE label = 'p2' 
           UNION
           SELECT nested_cte.start AS start, graph.end AS end FROM nested_cte, graph WHERE nested_cte.end = graph.start AND graph.label = 'p2'
         )
    SELECT outer_cte.start AS start, nested_cte.end AS end FROM outer_cte, nested_cte WHERE outer_cte.end = nested_cte.start
   )
) SELECT * FROM outer_cte;

where graph(start, label, end) is the edge table

Sadly, nested CTEs are not supported in DataFusion yet

Describe the solution you'd like

Enable nested recursive CTEs. A quick implementation might be to give each WorkSet plan node a name and use this name to allow the RecursiveQueryExec node to pick the correct WorkSetExec node to set

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions