DataJunction / dj

A metrics platform.
http://datajunction.io
MIT License
34 stars 15 forks source link

Building columns outside of select #523

Open CircArgs opened 1 year ago

CircArgs commented 1 year ago

There seems to be a bug with columns that appear in Query but not in Query.select. For example, if you have a column in an ORDER BY:

Expected

SELECT 
  default_DOT_dispatcher.company_name, 
  ...
ORDER BY 
  default_DOT_hard_hat.country 

Built

SELECT 
  default_DOT_dispatcher.company_name, 
  ...
ORDER BY 
  hard_hat.country 
CircArgs commented 1 year ago

I think there are a couple of problems and a couple of potential solutions:

Problems:

  1. The build step is still a little "legacy" in that it is using logic based on the old ast (pre-antlr parser) where virtually everything could be based around Select but now the ast is more modeled after the grammar so visiting is more straightforward and so there are some things outside of Select such as Organization and limit which contain expressions that may need examination during build
  2. during build, we do an extraction of the necessary parts but this focuses on Select
  3. We process each Select and do the necessary replacements, but this does not factor in anything in the parent Query

Possible solutions:

  1. Refactor to bring organization into Select
    • this would mean changes to the visitors and ast at least
  2. refactor the build
shangyian commented 1 year ago

By "refactor the build", do you mean that we can do something like modify it so that it checks organization and limit` for expressions and then builds those appropriately?