[query] Query projector is not handling NULL for aggregates over 0 rows #237

Open
opened 2020-08-06 16:57:08 +00:00 by gburd · 0 comments
gburd commented 2020-08-06 16:57:08 +00:00 (Migrated from github.com)

I have a query that looks like:

[:find
 (max ?at) .
 :in
 ?id
 :where
 [?c :credential/id ?id]
 [?l :login/credential ?c]
 [?l :login/at ?at]
]

That gets turned into the following SQL:

SELECT max(`?at`) AS `(max ?at)` FROM (SELECT DISTINCT `datoms02`.v AS `?at` FROM `datoms` AS `datoms00`, `datoms` AS `datoms01`, `datoms` AS `datoms02` WHERE `datoms00`.a = 65537 AND `datoms00`.v = $v0 AND `datoms01`.a = 65543 AND `datoms02`.a = 65542 AND `datoms02`.tx > 268435461 AND `datoms00`.e = `datoms01`.v AND `datoms01`.e = `datoms02`.e) LIMIT 1

The ScalarProjector has the following spec:

FindScalar(Aggregate(Aggregate { func: QueryFunction(PlainSymbol("max")), args: [Variable(var(?at))] }))

I get

Error(ProjectorError(DbError(BadSQLValuePair(Null, 4)))

and I surmise that the scalar projector either isn't handling zero rows correctly, or isn't handling a NULL result for aggregates correctly. Presumably NULL means no result for scalars, but it's less clear to me what should happen for a NULL aggregate for the other query types.

I have a query that looks like: ```edn [:find (max ?at) . :in ?id :where [?c :credential/id ?id] [?l :login/credential ?c] [?l :login/at ?at] ] ``` That gets turned into the following SQL: ``` SELECT max(`?at`) AS `(max ?at)` FROM (SELECT DISTINCT `datoms02`.v AS `?at` FROM `datoms` AS `datoms00`, `datoms` AS `datoms01`, `datoms` AS `datoms02` WHERE `datoms00`.a = 65537 AND `datoms00`.v = $v0 AND `datoms01`.a = 65543 AND `datoms02`.a = 65542 AND `datoms02`.tx > 268435461 AND `datoms00`.e = `datoms01`.v AND `datoms01`.e = `datoms02`.e) LIMIT 1 ``` The `ScalarProjector` has the following spec: ``` FindScalar(Aggregate(Aggregate { func: QueryFunction(PlainSymbol("max")), args: [Variable(var(?at))] })) ``` I get ``` Error(ProjectorError(DbError(BadSQLValuePair(Null, 4))) ``` and I surmise that the scalar projector either isn't handling zero rows correctly, or isn't handling a `NULL` result for aggregates correctly. Presumably `NULL` means no result for scalars, but it's less clear to me what should happen for a `NULL` aggregate for the other query types.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: greg/mentat#237
No description provided.