Skip to content

Commit dd5d2f9

Browse files
Support specifying input expression when manually calling diffix_count.
1 parent 48ab801 commit dd5d2f9

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/OpenDiffix.Core.Tests/QueryEngine.Tests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ type Tests(db: DBFixture) =
200200
Rows = [ [| Integer 11L; Boolean false |] ]
201201
}
202202

203-
let queryResult = runQuery "SELECT diffix_count(id) AS dc, diffix_low_count(id) AS lc FROM products"
203+
let queryResult = runQuery "SELECT diffix_count(*, id) AS dc, diffix_low_count(id) AS lc FROM products"
204204
queryResult |> should equal expected
205205

206206
interface IClassFixture<DBFixture>

src/OpenDiffix.Core/Aggregator.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type private DiffixCount(minCount) =
118118
interface IAggregator with
119119
member this.Transition args =
120120
match args with
121+
| Value.List [] :: _ -> invalidArgs args
121122
| [ aidInstances; Null ] -> updateAidMaps aidInstances 0L
122123
| [ aidInstances ]
123124
| [ aidInstances; _ ] -> updateAidMaps aidInstances 1L
@@ -140,7 +141,7 @@ type private DiffixCountDistinct(minCount) =
140141
member this.Transition args =
141142
match args with
142143
| [ _aidInstances; Null ] -> ()
143-
| [ Value.List aidInstances; value ] ->
144+
| [ Value.List aidInstances; value ] when not aidInstances.IsEmpty ->
144145
let aidSets =
145146
match aidsPerValue.TryGetValue(value) with
146147
| true, aidSets -> aidSets
@@ -173,7 +174,7 @@ type private DiffixLowCount() =
173174
member this.Transition args =
174175
match args with
175176
| [ Null ] -> ()
176-
| [ Value.List aidInstances ] ->
177+
| [ Value.List aidInstances ] when not aidInstances.IsEmpty ->
177178
if isNull state then state <- emptySets aidInstances.Length
178179

179180
aidInstances

src/OpenDiffix.Core/Analyzer.fs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,22 @@ let private mapFunctionExpression rangeColumns fn parsedArgs =
4444
(match fn, parsedArgs with
4545
| AggregateFunction (Count, aggregateArgs), [ ParserTypes.Star ] -> //
4646
AggregateFunction(Count, aggregateArgs), []
47+
| AggregateFunction (DiffixLowCount, aggregateArgs), parsedAids ->
48+
let aids = parsedAids |> List.map (mapExpression rangeColumns)
49+
AggregateFunction(DiffixLowCount, aggregateArgs), [ ListExpr aids ]
50+
| AggregateFunction (DiffixCount, aggregateArgs), parsedArg :: parsedAids ->
51+
let aggregateArgs, args =
52+
match parsedArg with
53+
| ParserTypes.Star -> aggregateArgs, []
54+
| ParserTypes.Distinct parsedExpr ->
55+
{ aggregateArgs with Distinct = true }, [ mapExpression rangeColumns parsedExpr ]
56+
| parsedExpr -> aggregateArgs, [ mapExpression rangeColumns parsedExpr ]
57+
58+
let aids = parsedAids |> List.map (mapExpression rangeColumns) |> ListExpr
59+
AggregateFunction(DiffixCount, aggregateArgs), aids :: args
4760
| AggregateFunction (aggregate, aggregateArgs), [ ParserTypes.Distinct expr ] ->
4861
let arg = mapExpression rangeColumns expr
4962
AggregateFunction(aggregate, { aggregateArgs with Distinct = true }), [ arg ]
50-
| AggregateFunction (fn, aggregateArgs), parsedArgs when List.contains fn [ DiffixCount; DiffixLowCount ] -> //
51-
let args = parsedArgs |> List.map (mapExpression rangeColumns)
52-
AggregateFunction(fn, aggregateArgs), [ ListExpr args ]
5363
| _ ->
5464
let args = parsedArgs |> List.map (mapExpression rangeColumns)
5565
fn, args)

0 commit comments

Comments
 (0)