Giter Site home page Giter Site logo

Add support for UNION about queryparser HOT 3 OPEN

ianmcook avatar ianmcook commented on July 17, 2024 1
Add support for UNION

from queryparser.

Comments (3)

ianmcook avatar ianmcook commented on July 17, 2024

I think the best approach is to create a new sublist named secondary_queries which is a list containing one or more queries. This sublist should have an attribute named relationship which is a vector of character strings such as "union all" or "union distinct":

Option 3:

$select
$select[[1]]
x

$from
$from[[1]]
df1

$secondary_queries
$secondary_queries[[1]]
$secondary_queries[[1]]$select
$secondary_queries[[1]]$select[[1]]
x

$secondary_queries[[1]]$from
$secondary_queries[[1]]$from[[1]]
df2

attr(,"relationship")
[1] "union distinct"

This same structure could later support CTEs and subqueries (by naming the items in secondary_queries and then referring to those table names elsewhere in the query). I think it's best to use one unified structure like this to support set operations, CTEs, and subqueries.

from queryparser.

StevenHibble avatar StevenHibble commented on July 17, 2024

That may be tough to parse with complicated nesting structures. CTEs are particularly difficult because they may be seconday_queries to multiple levels. For example, in this query, some_cte is a subquery of both df1 (the main/leader set) and df2 (the secondary set):

WITH some_cte
     AS (SELECT ...)

  SELECT *
  FROM df1
  WHERE x IN (SELECT y from some_cte)
  UNION ALL
  SELECT *
  FROM df2
  WHERE x IN (SELECT y from some_cte)

If we keep the overall structure similar to the original query, it may be easier to parse. I'm not familiar with the changes that would need to be made in tidyquery, though.

from queryparser.

ianmcook avatar ianmcook commented on July 17, 2024

Yep, this will require some deeper thinking about the design before we make any decisions. I have some other urgent work to do in the next few weeks, so I can't commit much time to it now, but I'm happy to keep discussing ideas here.

I think the secondary_queries approach could handle cases like in your example above; when I get a chance, I'll describe how.

from queryparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.