Last modified: 2014-09-23 19:44:55 UTC
Created attachment 6728 [details] Patch to implement query aggregate functions The attached patch implements a limited set of aggregate functions for the SMW Query. The syntax implemented at the moment puts the aggregate function in parenthesis immediately following the "?" in the ask statement thus: ?hasCity=city would return a list of cities ?(count)hasCity=city count would return the number of cities in the list. We have implemented the following functions count - number of entries countp - number of entries if > 0, blank otherwise exist, exists - "true" if number of entries > 0, "false" otherwise existt - "true" if entries exist, blank otherwise existf - "false" if no entries exist, blank otherwise" We are using these functions locally and would like to propose this patch as generic solution or a guide about how one might go about implementing a similar generic solution.
Yes, this looks useful. The new printout parameters of SMW could actually help to integrate this feature. The syntax in #ask will be slightly different. "count" would clearly be a "format" for individual printouts. I am less sure about the others. For one thing, they are not known as formats for queries in general yet, where one achieves this behavior with other parameters. There are at least three approaches one could take: 1) Introduce "exists" et al. as new formats as you suggest. In this case, I am inclined to also provide these formats for queries in general, to ensure that all printout formats work for queries as well (the other direction makes less sense, obviously). 2) The "exists" functionality could be provided in a similar fashion like the existing "?Category:Foo" printouts; e.g. one could have "?Property::+" in these cases. The advantage is that the formatting could be controlled completely, and in a way that is already implemented. 3) "exists" could be achieved by using "limit=0" together with a suitable value for "intro" ("true") and "default" ("false"). This requires these additional parameters to work for printouts, but this might be useful anyway. I will take a closer look at the code to decide which of those (or which others) to implement.
*Bulk BZ Change: +Patch to open bugs with patches attached that are missing the keyword*
It looks like Markus reviewed this patch, so I am adding the "reviewed" keyword.
Removing as blocker for 1.9 Removing Markus as assignee and setting to new, as he is clearly not working on this