malloydata / malloy

Malloy is an experimental language for describing data relationships and transformations.
http://www.malloydata.dev
MIT License
2k stars 76 forks source link

Project incorrectly thinks something is a circular reference. #1213

Open lloydtabb opened 1 year ago

lloydtabb commented 1 year ago
source: airports is table('duckdb:data/airports.parquet') + {
  measure: 
    airport_count is count()

  query: by_elevation is {
    group_by: elevation is 
      pick '1 Low' when elevation < 100
      pick '2 Medium' when elevation < 1000
      else '3 High'
    aggregate: airport_count
  }
  -> {
    project:
      elevation is substr(elevation, 2)  // incorrectly thinks this is a circular reference.
      airport_count
      order is substr(elevation,1,1)
    order_by: order
  }
}
mtoy-googly-moogly commented 1 year ago

So the problem is the name space active for expressions is the output space ... layered on top of the input space, so while this is technically not a circular reference, the way we detect circular references ( which isn't really great) is kind of doomed to catch this.

The more correct fix is to allow circular references, so that

dimension: x is x + 1

would actually work, and then this would also work.