Skip to content

Commit

Permalink
allow functions in SELECT hader
Browse files Browse the repository at this point in the history
  • Loading branch information
Callidon committed Sep 7, 2018
1 parent 9ac9f60 commit b9de116
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/engine/executors/aggregate-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ class AggregateExecutor {
if ('having' in query) {
iterator = this._executeHaving(iterator, query.having, options)
}
// finally, apply each aggregate operation over the groups
iterator = query.aggregates.reduce((iter, agg) => {
return this._executeAggregate(iter, agg, options)
}, iterator)
return iterator
}
return source
Expand Down
10 changes: 9 additions & 1 deletion src/engine/plan-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SOFTWARE.

const { Parser } = require('sparqljs')
const { single } = require('asynciterator')
const AggregateOperator = require('../operators/aggregates/agg-operator.js')
const BindOperator = require('../operators/bind-operator.js')
const UnionOperator = require('../operators/union-operator.js')
const DistinctIterator = require('../operators/distinct-operator.js')
Expand Down Expand Up @@ -202,7 +203,7 @@ class PlanBuilder {
}

// Parse query variable to separate projection & aggregate variables
if (query.variables != null) {
if ('variables' in query) {
const [projection, aggregates] = _.partition(query.variables, v => _.isString(v))
// add aggregates variables to projection variables
query.variables = projection.concat(aggregates.map(agg => agg.variable))
Expand All @@ -212,6 +213,13 @@ class PlanBuilder {
// Handles Aggregates
graphIterator = this._aggExecutor.buildIterator(graphIterator, query, options)

// Handles transformers
if ('aggregates' in query) {
graphIterator = query.aggregates.reduce((iter, agg) => {
return new AggregateOperator(iter, agg, options)
}, graphIterator)
}

// Handles ORDER BY
if ('order' in query) {
graphIterator = new OrderByOperator(graphIterator, query.order, options)
Expand Down
7 changes: 6 additions & 1 deletion src/operators/expressions/sparql-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ class SPARQLExpression {
throw new Error(`Unsupported SPARQL aggregation: ${expression.aggregation}`)
}
const aggregation = aggregates[expression.aggregation]
return bindings => aggregation(expression.expression, bindings['__aggregate'], expression.separator)
return bindings => {
if ('__aggregate' in bindings) {
return aggregation(expression.expression, bindings['__aggregate'], expression.separator)
}
return bindings
}
}
throw new Error(`Unsupported SPARQL operation type found: ${expression.type}`)
}
Expand Down

0 comments on commit b9de116

Please sign in to comment.