@@ -33,7 +33,7 @@ const canonical = (rows: ReadonlyArray<unknown>): Array<unknown> =>
3333const sorted = ( rows : Array < unknown > ) => rows . map ( ( r ) => JSON . stringify ( r ) ) . sort ( )
3434
3535const matchesModel = ( dialect : FuzzDialect , target : FuzzTarget , input : Plan , data ?: Fixture ) => {
36- const known = knownPlanIssue ( { target : target . name , plan : input } )
36+ const known = knownPlanIssue ( { target : target . name , plan : input , executed : true } )
3737 if ( known !== undefined ) skipKnown ( known )
3838 return checkRows ( target , input . orgId , evaluate ( input , target . semantics , data ) , compilePlan ( dialect , data === undefined ? dialect . context : fixtureContext ( dialect , data ) , input ) , compilePlan ( dialect , scopeContext ( dialect ) , input ) , input . where )
3939}
@@ -42,7 +42,7 @@ const unionMatchesModel = (dialect: FuzzDialect, target: FuzzTarget, input: Unio
4242 const knownUnion = knownUnionIssue ( { target : target . name , plan : input } )
4343 if ( knownUnion !== undefined ) skipKnown ( knownUnion )
4444 for ( const branch of input . branches ) {
45- const known = knownPlanIssue ( { target : target . name , plan : branch } )
45+ const known = knownPlanIssue ( { target : target . name , plan : branch , executed : true } )
4646 if ( known !== undefined ) skipKnown ( known )
4747 }
4848 return checkRows (
@@ -111,14 +111,22 @@ describe("generated fixture queries", () => {
111111 [ "empty orders" , { orders : [ ] , customers : [ ] } , undefined ] ,
112112 [ "empty inner join" , { orders : [ { OrgId : "org_1" , Id : 1 , Customer : "acme" , Amount : 0 , Status : "paid" , Note : null , Created : Date . UTC ( 2026 , 0 , 1 ) } ] , customers : [ ] } , "inner" ] ,
113113 ] as const ) {
114- it ( `constant division is excluded over ${ label } (${ target . name } )` , ( ) => {
115- const input : Plan = {
116- orgId : "org_1" , join, where : [ ] , wrap : false , crossTenant : false ,
117- shape : { k : "rows" , select : [ [ "id" , { k : "col" , col : "Id" } ] , [ "bad" , { k : "arith" , op : "div" , l : { k : "num" , v : 1 } , r : 0 } ] ] , distinct : false , orderBy : [ ] } ,
118- }
119- expect ( ( ) => evaluate ( input , target . semantics , data ) ) . toThrow ( Skip )
120- expect ( ( ) => evaluate ( input , target . semantics , data ) ) . toThrow ( "division by zero" )
121- } )
114+ for ( const [ what , bad ] of [
115+ [ "1 / 0" , { k : "arith" , op : "div" , l : { k : "num" , v : 1 } , r : 0 } ] ,
116+ // `(Id + 1) % 0` in the plan is `Id + 1 % 0` in the SQL: the constant `1 % 0` is only there once parsed.
117+ [ "Id + 1 % 0" , { k : "arith" , op : "mod" , l : { k : "arith" , op : "add" , l : { k : "col" , col : "Id" } , r : 1 } , r : { k : "num" , v : 0 } } ] ,
118+ // ClickHouse runs `%` on an empty block too, so a zero divisor fails with no rows to read.
119+ [ "Id % 0" , { k : "arith" , op : "mod" , l : { k : "col" , col : "Id" } , r : 0 } ] ,
120+ ] as const ) {
121+ it ( `constant division ${ what } is excluded over ${ label } (${ target . name } )` , ( ) => {
122+ const input : Plan = {
123+ orgId : "org_1" , join, where : [ ] , wrap : false , crossTenant : false ,
124+ shape : { k : "rows" , select : [ [ "id" , { k : "col" , col : "Id" } ] , [ "bad" , bad ] ] , distinct : false , orderBy : [ ] } ,
125+ }
126+ expect ( ( ) => evaluate ( input , target . semantics , data ) ) . toThrow ( Skip )
127+ expect ( ( ) => evaluate ( input , target . semantics , data ) ) . toThrow ( "division by zero" )
128+ } )
129+ }
122130 }
123131 it . skipIf ( ! target . available ) ( `empty generated tables (${ target . name } )` , ( ) => matchesModel ( dialect , target , {
124132 orgId : "org_1" , where : [ ] , shape : { k : "rows" , select : [ [ "id" , { k : "col" , col : "Id" } ] ] , distinct : false , orderBy : [ ] } , wrap : false , crossTenant : false ,
0 commit comments