malloy
malloy copied to clipboard
Feature: add assertions
What happens?
I'm new to the language, so please take this with a grain of salt. But even doing an initial "demo" project I found myself wanting to have some kind of assert
functionality to ensure that as I hacked the data I wasn't accidentally dropping rows.
IMO this should be put inside of run
and query
and would use something like implicit sources. This would have the added benefit of an error message being able to show the input data that caused the failure.
query: somethingWithPercents -> {
project: myPercent is somePerc + otherPerc, -- whoops, that's not right!
-- assertions expect an EMPTY result
assert: "expect percentages to be [0-100]" is -> {
where: not myPercent ? 0 to 100
}
}
Because the assert
expects an empty list it can helpfully show (a sample of) what caused the failure (nice!)
Folks could include fundamental invariant assertions directly in their queries, with more "quality check" assertions (that shouldn't cause immediate pipeline failure) put inside of run
statements in explicit test modules
To Reproduce
N/A
OS:
N/A
Malloy Client:
N/A
Malloy Client Version:
N/A
Database Connection:
N/A
Yes, there have been a number of requests for testing. For the moment we'd prefer that you handle it with convention.
source: foo is ... {
measure: myPercent is somePerc + otherPerc, -- whoops, that's not right!
query: my_query is {
group_by: something
aggregate: myPercent
}
query: assert_my_query is -> my_query refine { // should return no rows
having:
myPercent > 100
or somethingelse
}
}
That said, I do really like your idea about building assertions into the query itself...
I didn't know about refine
!
Reading the docs, I'm fairly confused about how it causes an assertion/failure to trigger though (?)
You would keep a list of queries to run and use our command line tool to run them. If any of the queries returned any data, it would be a failure.
On Sat, Aug 12, 2023, 6:04 PM Rett Berg @.***> wrote:
I didn't know about refine! I'm fairly confused about how it causes an assertion/failure to trigger though (?)
— Reply to this email directly, view it on GitHub https://github.com/malloydata/malloy/issues/1290#issuecomment-1676152616, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIK6UTCE67GTZ3P3IA73LDXVAKXZANCNFSM6AAAAAA3OE6YT4 . You are receiving this because you commented.Message ID: @.***>