Hi Albert,

On 12-Apr-16 8:21 PM, Albert Meroño Peñuela wrote:
Hi all,

I'm trying to implement a custom aggregate function in Virtuoso. Following the examples at [1] I've written something silly of the style

CREATE PROCEDURE DB.DBA.MyAggregate (IN X NUMERIC) {
  declare m numeric;
  m := m + X;
  return m;
};

With the intention of accumulating all bindings of X.The obvious problem with this procedure is that calling it from e.g. SPARQL will result in one result per variable binding

SQL> sparql select (sql:myAggreagate(?val)) where { [] ?var ?val .};

(Many rows)

while what I'm trying to achieve is to use all bindings of ?val to produce a resultset of exactly one row. There's seems to be an old related question [2], but I can't seem to find related documentation on this. Any help would be greatly appreciated!

Virtuoso supports SPARQL 1.1., so simply could be used the SUM function:

SELECT (SUM(?val) AS ?totalVAL)
WHERE {
   [] ?var ?val .
}

Another variant is to use the Virtuoso sum function -- http://docs.openlinksw.com/virtuoso/xpf_sum.html

SELECT (bif:sum(?val) AS ?totalVAL)
WHERE {
   [] ?var ?val .
}

If you however want to sum the values with a custom sql function instead, you can try these ones:

-- result: -- http://docs.openlinksw.com/virtuoso/fn_result.html
-- result_names: -- http://docs.openlinksw.com/virtuoso/fn_result_names.html
-- end_result: -- http://docs.openlinksw.com/virtuoso/fn_end_result.html


Best Regards,
Rumyana Kocis




Thanks,
Albert

[1] http://docs.openlinksw.com/virtuoso/rdfsparql.html#rdfsqlfromsparql
[2] https://www.mail-archive.com/virtuoso-users@lists.sourceforge.net/msg04826.html




------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z


_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users

Reply via email to