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

Howto aggregate on full data set in Spring Batch jobs?
Creating an aggregate function fails
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

Categories

HOME
gcc
kendo-ui-angular2
virtual-machine
salesforce
service
arcgis
crash
css-selectors
powerquery
foreach
promotions
coding-style
urllib2
guidewire
captcha
drush
yui
turn.js
bug-reporting
include-path
coccinelle
klipfolio
matlab-gui
ecmascript-2017
bootstrap-accordion
deployment-descriptor
gulp-jshint
hierarchical-data
custom-fields
paper-trail-gem
edirectory
apm
lines
mplab
jsonapi-resources
powerbi-embedded
geocomplete
certbot
framebuffer
queryover
server-side-swift
collation
bzip2
piranha-cms
spring-ide
stream-socket-client
jsfl
google-cloud-shell
kendo-scheduler
typewriter
cc
petapoco
scanf
msiexec
stringbuilder
firebase-polymer
mongodb-3.3
joystick
konakart
shtml
usps
nd4j
periodic-processing
hana-sql-script
ooad
encode
computability
mojolicious
personality-insights
jain-sip
om
syncano
web-standards
data-representation
applinks
jsonmodel
report-builder2.0
go-gin
javacompiler
nest-initiative
atg-dynamo
dateadd
satisfiability
autofilter
mahara
mobile-robots
zend-db-table
violation
wpd
mysql2
rbm
blackberry-eclipse-plugin
reflexil
datasheet
pinchzoom
copyfile
qvariant
sessiontracking
onunload
s60
text-manipulation
subdirectories
nyromodal
google-local-search

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