aggregate-functions


Binding the Result of an Aggregate Function to a Projected Variable


I am trying to count the number of values for a given property and output each of the retrieved resources along with that number. I am trying to use BIND to store the result value of the COUNT function in a variable and project that variable to my results. However, that value seems to be empty and I do not understand why that is.
My query currently looks like this:
SELECT DISTINCT ?a ?c
WHERE {
?a <http://www.w3.org/2000/01/rdf-schema#label> ?b.
BIND(COUNT(?b) AS ?c).
}
LIMIT 100
I think I will have to group by ?a, though I am not sure yet how to proceed when I want to do that for several properties, but that is not the concern of this question: For now, I simply want to find out why ?c appears to be empty.
Shouldn't - for now - there be exactly one label per resulting row? If so, why isn't the literal 1^^xsd:integer bound to ?c - or at least some high number representing the total (ungrouped) number of labels (similarly to what happened here) -, for example on the following endpoints:
Austrian Ski Team
UniProt
Europeana/Forest
I am aware the feature I am looking for may not be supported by some or all of these implementations - but if so, it seems unusual that the COUNT is simply "swallowed" without an error message (I did get an error message on some other endpoints for the syntax).
Thus, my question is: Why is the return value of COUNT empty?
Is the COUNT function in that position not recognized by the endpoints?
As it seems to be syntactically valid there, is that a shortcoming of current SPARQL engines, or is that by design?
Is the COUNT function evaluated only later (and if so, why doesn't it at least return something like 0)?
Your query isn't actually legal. There's a SPARQL query validator at sparql.org, and it reports a syntax error on count:
Syntax error:
Line 4, column 8: Aggregate expression not legal at this point
I can't speak as to why some engines aren't choking on it. A number built in SPARQL functions can produce errors, and that typically ends up binding variables to seemingly empty results. Perhaps some SPARQL engine developers took this one step farther and make calls to missing functions return an error (which looks like an unbound variable). That's probably going to be a case by case investigation, and you'll need to contact developers of those products separately.
At any rate, you probably want to end up writing a query more or less like the following. You can use (aggregate-function(args) as variable) in the projection portion of the query, and that's how you can bind the number of ?bs per ?a to ?c once you've grouped by ?a.
select distinct ?a (count(?b) as ?c)
where { ?a rdfs:label ?b }
group by ?a

Related Links

Necessity of declaration of function in c and cpp
Calculate window average in tableau
Complexity asymptotic relation (theta, Big O, little o, Big Omega, little omega) between functions
What are TOP_COUNT and TOP_MAXCOUNT in BigQuery?
marklogic need advise for approach to aggregate documents
multiply(num) aggregate function in postgresql
Binding the Result of an Aggregate Function to a Projected Variable
tableau aggregate data based on dimension
where clause and aggregate functions
Is there such a thing as a join() aggregate function that concatentates field values at a specific character?
Aggregation of an expression in Django query spanning multiple tables
How to aggregate / roll up percentile measures
A peer-to-peer and privacy-aware data mining/aggregation algorithm: is it possible?
Multiple aggregates in SPARQL
SAP BO XI Desktop Intelligence Aggregate Calculations
Mondrian: Help picking the right aggregator for Measures?

Categories

HOME
logging
kendo-ui-angular2
swift3
bigtable
singleton
crash
autocad
virtualhost
segmentation-fault
wkhtmltopdf
rename
resharper
expo
github-flavored-markdown
infopath
brightway
amazon-data-pipeline
simd
ibatis
openam
wallet
audio-streaming
glibc
gomobile
xna
rndis
smart-device
units-of-measurement
slim-lang
favorites
certbot
multi-user
outlook-2010
stochastic-process
instances
mediastream
glide-image-library
web-technologies
peerjs
bootstrap-carousel
html-entities
denodo
monaca
extjs3
seyren
trusted-computing
google-scholar
huawei
x12
jspx
kik
stdlist
abstract
ooad
wonderware
imageicon
autoscaling
joomla3.3
tokudb
tidesdk
mergecursor
optimistic-locking
quickfixn
dojox.grid
jsonschema2pojo
apache-pivot
nsurlrequest
triplestore
jsmpp
pidgin
sqldatasource
nop
wpa
jython-2.5
antixsslibrary
libx264
github-archive
django-1.4
joomla1.7
isgl3d
windows-xp-embedded
meego-harmattan
nscharacterset
html-help-workshop
moores-law

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App