@@ -11,7 +11,7 @@ import type { ColumnMeta, FilterOp, PageInfo, Row } from "./types.js";
1111import { NULL_SENTINEL } from "./types.js" ;
1212import type { QueryDescriptor } from "./client.js" ;
1313import type { WasmEngine } from "./wasm-engine.js" ;
14- import { canSkipPage , matchesFilter , decodePage } from "./decode.js" ;
14+ import { canSkipPage , matchesFilter , rowPassesFilters , decodePage } from "./decode.js" ;
1515import { decodeParquetColumnChunk } from "./parquet-decode.js" ;
1616
1717const _textEncoder = new TextEncoder ( ) ;
@@ -1053,8 +1053,8 @@ export class WindowOperator implements Operator {
10531053 if ( n > runMax ) runMax = n ;
10541054 }
10551055 switch ( fn ) {
1056- case "sum" : rows [ indices [ i ] ] [ alias ] = runSum ; break ;
1057- case "avg" : rows [ indices [ i ] ] [ alias ] = runCount === 0 ? 0 : runSum / runCount ; break ;
1056+ case "sum" : rows [ indices [ i ] ] [ alias ] = runCount === 0 ? null : runSum ; break ;
1057+ case "avg" : rows [ indices [ i ] ] [ alias ] = runCount === 0 ? null : runSum / runCount ; break ;
10581058 case "min" : rows [ indices [ i ] ] [ alias ] = runMin === Infinity ? null : runMin ; break ;
10591059 case "max" : rows [ indices [ i ] ] [ alias ] = runMax === - Infinity ? null : runMax ; break ;
10601060 case "count" : rows [ indices [ i ] ] [ alias ] = runCount ; break ;
@@ -1087,8 +1087,8 @@ export class WindowOperator implements Operator {
10871087 }
10881088
10891089 switch ( fn ) {
1090- case "sum" : rows [ indices [ i ] ] [ alias ] = sum ; break ;
1091- case "avg" : rows [ indices [ i ] ] [ alias ] = count === 0 ? 0 : sum / count ; break ;
1090+ case "sum" : rows [ indices [ i ] ] [ alias ] = count === 0 ? null : sum ; break ;
1091+ case "avg" : rows [ indices [ i ] ] [ alias ] = count === 0 ? null : sum / count ; break ;
10921092 case "min" : rows [ indices [ i ] ] [ alias ] = min === Infinity ? null : min ; break ;
10931093 case "max" : rows [ indices [ i ] ] [ alias ] = max === - Infinity ? null : max ; break ;
10941094 case "count" : rows [ indices [ i ] ] [ alias ] = count ; break ;
@@ -1354,28 +1354,7 @@ export class FilterOperator implements Operator {
13541354 }
13551355
13561356 private matchesRow ( row : Row ) : boolean {
1357- // AND filters must all pass
1358- const andPass = this . filters . every ( f => {
1359- const v = row [ f . column ] ;
1360- if ( f . op === "is_null" ) return v === null || v === undefined ;
1361- if ( f . op === "is_not_null" ) return v !== null && v !== undefined ;
1362- return v !== null && matchesFilter ( v , f ) ;
1363- } ) ;
1364- if ( ! andPass ) return false ;
1365-
1366- // OR groups: at least one group must pass (each group is AND-connected)
1367- if ( this . filterGroups && this . filterGroups . length > 0 ) {
1368- return this . filterGroups . some ( group =>
1369- group . every ( f => {
1370- const v = row [ f . column ] ;
1371- if ( f . op === "is_null" ) return v === null || v === undefined ;
1372- if ( f . op === "is_not_null" ) return v !== null && v !== undefined ;
1373- return v !== null && matchesFilter ( v , f ) ;
1374- } ) ,
1375- ) ;
1376- }
1377-
1378- return true ;
1357+ return rowPassesFilters ( row , this . filters , this . filterGroups ) ;
13791358 }
13801359
13811360 async nextColumnar ( ) : Promise < ColumnarBatch | null > {
0 commit comments