From 9da605f84fe31752435eed0ce3a8d41fda3e63e4 Mon Sep 17 00:00:00 2001 From: Tpt Date: Sun, 5 Sep 2021 19:12:47 +0200 Subject: [PATCH] SPARQL: Use empty group by instead of the "1" constant --- spargebra/src/algebra.rs | 11 +++++++---- spargebra/src/parser.rs | 13 +------------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/spargebra/src/algebra.rs b/spargebra/src/algebra.rs index 43bcbda8..4a297cc5 100644 --- a/spargebra/src/algebra.rs +++ b/spargebra/src/algebra.rs @@ -729,16 +729,19 @@ impl fmt::Display for GraphPattern { by, aggregates, } => { - write!(f, "{{ SELECT")?; + write!(f, "{{SELECT")?; for (a, v) in aggregates { write!(f, " ({} AS {})", v, a)?; } for b in by { write!(f, " {}", b)?; } - write!(f, " WHERE {{ {} }} GROUP BY", inner)?; - for v in by { - write!(f, " {}", v)?; + write!(f, " WHERE {{ {} }}", inner)?; + if !by.is_empty() { + write!(f, " GROUP BY")?; + for v in by { + write!(f, " {}", v)?; + } } write!(f, "}}") } diff --git a/spargebra/src/parser.rs b/spargebra/src/parser.rs index c38f0282..79327521 100644 --- a/spargebra/src/parser.rs +++ b/spargebra/src/parser.rs @@ -451,18 +451,7 @@ fn build_select( //GROUP BY let aggregates = state.aggregates.pop().unwrap_or_else(Vec::default); if group.is_none() && !aggregates.is_empty() { - let const_variable = variable(); - group = Some(( - vec![const_variable.clone()], - vec![( - Literal::Typed { - value: "1".into(), - datatype: iri("http://www.w3.org/2001/XMLSchema#integer"), - } - .into(), - const_variable, - )], - )); + group = Some((vec![], vec![])); } if let Some((clauses, binds)) = group {