# Behaviour of MIN() & MAX() if not bound?

**URL:** <https://community.stardog.com/t/behaviour-of-min-max-if-not-bound/474>\
**Category:** Support\
**Created:** [July 21, 2017, 2:15am UTC](https://community.stardog.com/t/behaviour-of-min-max-if-not-bound/474 "2017-07-21T02:15:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![conranc](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@conranc](https://community.stardog.com/u/conranc)\
**Post date:** [July 21, 2017, 2:15am UTC](https://community.stardog.com/t/behaviour-of-min-max-if-not-bound/474/1 "2017-07-21T02:15:21Z")

</div>

Using Stardog 5.0  
I have a query that is performing aggregate functions over a subset of data.  
eg (not actual code…)  
SELECT (MAX(?headcount) as ?maxHeadCount) (MAX(?sales) as ?maxSales)  
WHERE {  
?entity xx:hasPostCode “1234”.  
OPTIONAL {?entity xx:hasSalesValue ?sales.}  
OPTIONAL {?entity xx:hasHeadCount ?headcount .}  
}

I have one particular subset where the property (eg ?headcount) to be aggregated has no values instantiated.

- there are 176 ?entity instances, some have ?sales values but none of them have ?headcount values.

I would expect the MAX function to return nothing since there’s no values.  
However what happens is that the server gets a nullPointerException.  
MIN has the same problem. AVG & SUM are unaffected.

Bug or as expected?

Thanks,  
Chris

Stack trace in server log:  
ERROR 2017-07-21 11:49:56,946 [XNIO-1 task-4] com.complexible.stardog.protocols.http.server.StardogHttpServiceLoader:accept(228): An unexpected exception was handled by the server  
org.openrdf.query.QueryEvaluationException: null  
at com.complexible.common.rdf.query.IteratorAsTupleQueryResult.hasNext(IteratorAsTupleQueryResult.java:81) ~[stardog-utils-rdf-5.0.jar:?]  
at org.openrdf.query.QueryResults.report(QueryResults.java:158) ~[sesame-query-4.0.0.jar:?]  
at org.openrdf.query.resultio.QueryResultIO.writeTuple(QueryResultIO.java:449) ~[sesame-queryresultio-api-4.0.0.jar:?]  
at com.complexible.stardog.protocols.http.server.ProtocolUtils.executeReadQuery(ProtocolUtils.java:474) ~[stardog-protocols-http-server-5.0.jar:?]  
at com.complexible.stardog.protocols.http.annex.QueryPanelService.executeQuery(QueryPanelService.java:195) ~[stardog-webconsole-annex-5.0.jar:?]  
at com.complexible.stardog.protocols.http.annex.QueryPanelService.post(QueryPanelService.java:120) ~[stardog-webconsole-annex-5.0.jar:?]  
at com.stardog.http.server.undertow.jaxrs.ExtractRoutes.lambda$handleIt$91(ExtractRoutes.java:186) ~[stardog-protocols-http-server-5.0.jar:?]  
at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120) ~[shiro-core-1.2.3.jar:1.2.3]  
at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108) ~[shiro-core-1.2.3.jar:1.2.3]  
at com.stardog.http.server.undertow.ErrorHandling.lambda$safeDispatch$46(ErrorHandling.java:70) ~[stardog-protocols-http-server-5.0.jar:?]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0\_131]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0\_131]  
at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_131]  
Caused by: java.lang.NullPointerException  
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) ~[guava-18.0.jar:?]  
at com.complexible.stardog.dht.dictionary.HashDictionary.getOrAddID(HashDictionary.java:553) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.dht.dictionary.HashDictionary.getID(HashDictionary.java:547) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.index.dictionary.DelegatingMappingDictionary.getID(DelegatingMappingDictionary.java:59) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.index.dictionary.QueryMappingDictionary.getID(QueryMappingDictionary.java:86) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.index.dictionary.QueryMappingDictionary.add(QueryMappingDictionary.java:70) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.GroupOp$StreamingAggregatedSequenceBuilder.build(GroupOp.java:241) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.EagerUnsortedGroupify.groupify(GroupifyAlgorithms.java:105) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.AbstractGroupOp.buildGroups(AbstractGroupOp.java:164) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.GroupOp.buildGroups(GroupOp.java:106) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.AbstractGroupOp.computeNext(AbstractGroupOp.java:130) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.AbstractGroupOp.computeNext(AbstractGroupOp.java:31) ~[stardog-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:83) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:33) ~[stardog-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.DistinctOp.computeNext(DistinctOp.java:53) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.DistinctOp.computeNext(DistinctOp.java:21) ~[stardog-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SliceOp.\_hasNext(SliceOp.java:87) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SliceOp.computeNext(SliceOp.java:95) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SliceOp.computeNext(SliceOp.java:26) ~[stardog-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:112) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:25) ~[stardog-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:143) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:130) ~[stardog-utils-common-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:110) ~[stardog-5.0.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:34) ~[stardog-5.0.jar:?]  
at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) ~[guava-18.0.jar:?]  
at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) ~[guava-18.0.jar:?]  
at com.complexible.common.rdf.query.IteratorAsTupleQueryResult.hasNext(IteratorAsTupleQueryResult.java:77) ~[stardog-utils-rdf-5.0.jar:?]  
… 12 more

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [July 21, 2017, 6:20am UTC](https://community.stardog.com/t/behaviour-of-min-max-if-not-bound/474/2 "2017-07-21T06:20:44Z")

</div>

This looks like a bug. Thanks for the detailed report, this will be fixed in the next release.

Best,  
Pavel

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [August 4, 2017, 6:20am UTC](https://community.stardog.com/t/behaviour-of-min-max-if-not-bound/474/3 "2017-08-04T06:20:45Z")

</div>

Closed on August 4, 2017, 6:20am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
