diff --git a/examples/json_queries/aggregates.json b/examples/json_queries/aggregates.json index 7eb2119..335ea14 100644 --- a/examples/json_queries/aggregates.json +++ b/examples/json_queries/aggregates.json @@ -4,9 +4,11 @@ "sum": "?v$sum", "min": "?v$min", "max": "?v$max", - "avg": "?v$avg$var:average" + "avg": "?v$avg$var:average", + "value_sum": "?value$sum" }, "$where": [ - "VALUES (?v) { (10.5) (20.5) }" + "VALUES (?v) { (10.5) (20.5) }", + "?id schema:value ?value" ] } diff --git a/examples/json_transformed/aggregates.json b/examples/json_transformed/aggregates.json index 0653bd5..929261d 100644 --- a/examples/json_transformed/aggregates.json +++ b/examples/json_transformed/aggregates.json @@ -4,6 +4,7 @@ "count": 2, "max": 20.5, "min": 10.5, - "sum": 31 + "sum": 31, + "value_sum": 42 } ] \ No newline at end of file diff --git a/examples/sparql_output/aggregates.json b/examples/sparql_output/aggregates.json index 8a5b06a..f777776 100644 --- a/examples/sparql_output/aggregates.json +++ b/examples/sparql_output/aggregates.json @@ -1,7 +1,7 @@ { "head": { "link": [], - "vars": ["total", "sum_v", "min_v", "max_v", "average"] + "vars": ["total", "sum_v", "min_v", "max_v", "average", "sum_value"] }, "results": { "distinct": false, @@ -31,6 +31,11 @@ "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#decimal", "value": "15.5" + }, + "sum_value": { + "type": "typed-literal", + "datatype": "http://www.w3.org/2001/XMLSchema#decimal", + "value": "42" } }] } diff --git a/examples/sparql_queries/aggregates.rq b/examples/sparql_queries/aggregates.rq index ee22a2e..713453e 100644 --- a/examples/sparql_queries/aggregates.rq +++ b/examples/sparql_queries/aggregates.rq @@ -1,4 +1,5 @@ - SELECT DISTINCT (COUNT(DISTINCT ?v) AS ?total) (SUM(?v) AS ?sum_v) (MIN(?v) AS ?min_v) (MAX(?v) AS ?max_v) (AVG(?v) AS ?average) + SELECT DISTINCT (COUNT(DISTINCT ?v) AS ?total) (SUM(?v) AS ?sum_v) (MIN(?v) AS ?min_v) (MAX(?v) AS ?max_v) (AVG(?v) AS ?average) (SUM(?value) AS ?sum_value) WHERE { - VALUES (?v) { (10.5) (20.5) } + VALUES (?v) { (10.5) (20.5) }. + ?id schema:value ?value } diff --git a/src/main.mjs b/src/main.mjs index 08a0fe4..b2f6412 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -326,7 +326,7 @@ function manageProtoKey(proto, vars = [], filters = [], wheres = [], const aggrWhat = is$ ? id : originalId; if (aggregate && !givenVar) { - id = is$ ? originalId : `?${aggregate}_${originalId.replace('?', '')}`; + id = `?${aggregate}_${aggrWhat.replace('?', '')}`; } // assign a clean id to the prototype