malloydata / malloy

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

Refinement with a "where" seems to obscure output space? #1775

Open bporterfield opened 3 months ago

bporterfield commented 3 months ago

What happens?

source: user is db.table('public.user') extend {
  primary_key: id
  measure: user_count is count()
}

source: chat is db.table('public.chat_message') extend {
    primary_key: id
    join_one: user on sender_id = user.id
    measure: chat_count is count()
}

query: user_chat_facts is user -> { 
    extend: {
        join_many: chat on chat.sender_id = id
    }
    group_by: id
    aggregate: lifetime_chats is count(chat.id::string)
}

run: user_chat_facts + { group_by: name, order_by: lifetime_chats } + { where: id::string = "test" }

The run query has an error "Unknown field lifetime_chats in output space". If I remove + { where: id::string = "test" }, this error goes away and the query runs correctly.

To Reproduce

see above

OS:

macOS

Malloy Client:

local VSCode

Malloy Client Version:

latest

Database Connection:

Postgres

mtoy-googly-moogly commented 3 months ago

Yeah @christopherswenson is the right place for this probably, but if he isn't around I could also look at this.