|
|
|
@ -747,7 +747,8 @@ impl<'a> fmt::Display for SparqlExpression<'a> { |
|
|
|
|
SparqlExpression(&*b), |
|
|
|
|
SparqlExpression(cv) |
|
|
|
|
) |
|
|
|
|
}).unwrap_or_else(|| { |
|
|
|
|
}) |
|
|
|
|
.unwrap_or_else(|| { |
|
|
|
|
write!( |
|
|
|
|
f, |
|
|
|
|
"SUBSTR({}, {})", |
|
|
|
@ -1130,12 +1131,15 @@ impl<'a> fmt::Display for SparqlGraphPattern<'a> { |
|
|
|
|
SparqlGraphPattern(&*a), |
|
|
|
|
SparqlGraphPattern(&*b) |
|
|
|
|
), |
|
|
|
|
GraphPattern::Service(n, p, s) => if *s { |
|
|
|
|
GraphPattern::Service(n, p, s) => { |
|
|
|
|
if *s { |
|
|
|
|
write!(f, "SERVICE SILENT {} {{ {} }}", n, SparqlGraphPattern(&*p)) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "SERVICE {} {{ {} }}", n, SparqlGraphPattern(&*p)) |
|
|
|
|
}, |
|
|
|
|
GraphPattern::Data(bs) => if bs.is_empty() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
GraphPattern::Data(bs) => { |
|
|
|
|
if bs.is_empty() { |
|
|
|
|
Ok(()) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "VALUES ( ")?; |
|
|
|
@ -1154,7 +1158,8 @@ impl<'a> fmt::Display for SparqlGraphPattern<'a> { |
|
|
|
|
write!(f, ") ")?; |
|
|
|
|
} |
|
|
|
|
write!(f, " }}") |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
GraphPattern::AggregateJoin(GroupPattern(group, p), agg) => write!( |
|
|
|
|
f, |
|
|
|
|
"{{ SELECT {} WHERE {{ {} }} GROUP BY {} }}", |
|
|
|
@ -1301,7 +1306,8 @@ pub enum Aggregation { |
|
|
|
|
impl fmt::Display for Aggregation { |
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
|
match self { |
|
|
|
|
Aggregation::Count(e, distinct) => if *distinct { |
|
|
|
|
Aggregation::Count(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
e.as_ref() |
|
|
|
|
.map(|ex| write!(f, "COUNT(DISTINCT {})", ex)) |
|
|
|
|
.unwrap_or_else(|| write!(f, "COUNT(DISTINCT *)")) |
|
|
|
@ -1309,33 +1315,45 @@ impl fmt::Display for Aggregation { |
|
|
|
|
e.as_ref() |
|
|
|
|
.map(|ex| write!(f, "COUNT({})", ex)) |
|
|
|
|
.unwrap_or_else(|| write!(f, "COUNT(*)")) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Sum(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Sum(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "Aggregation(Distinct({}), Sum, {{}})", e) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "Aggregation({}, Sum, {{}})", e) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Min(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Min(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "Aggregation(Distinct({}), Min, {{}})", e) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "Aggregation({}, Min, {{}})", e) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Max(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Max(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "Aggregation(Distinct({}), Max, {{}})", e) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "Aggregation({}, Max, {{}})", e) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Avg(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Avg(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "Aggregation(Distinct({}), Avg, {{}})", e) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "Aggregation({}, Avg, {{}})", e) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Sample(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Sample(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "Aggregation(Distinct({}), Sum, {{}})", e) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "Aggregation({}, Sample, {{}})", e) |
|
|
|
|
}, |
|
|
|
|
Aggregation::GroupConcat(e, distinct, sep) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::GroupConcat(e, distinct, sep) => { |
|
|
|
|
if *distinct { |
|
|
|
|
sep.as_ref() |
|
|
|
|
.map(|s| { |
|
|
|
|
write!( |
|
|
|
@ -1345,7 +1363,9 @@ impl fmt::Display for Aggregation { |
|
|
|
|
s.escape() |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
.unwrap_or_else(|| write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e)) |
|
|
|
|
.unwrap_or_else(|| { |
|
|
|
|
write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
sep.as_ref() |
|
|
|
|
.map(|s| { |
|
|
|
@ -1356,8 +1376,11 @@ impl fmt::Display for Aggregation { |
|
|
|
|
s.escape() |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
.unwrap_or_else(|| write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e)) |
|
|
|
|
}, |
|
|
|
|
.unwrap_or_else(|| { |
|
|
|
|
write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1367,7 +1390,8 @@ struct SparqlAggregation<'a>(&'a Aggregation); |
|
|
|
|
impl<'a> fmt::Display for SparqlAggregation<'a> { |
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
|
match self.0 { |
|
|
|
|
Aggregation::Count(e, distinct) => if *distinct { |
|
|
|
|
Aggregation::Count(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
if let Some(e) = e { |
|
|
|
|
write!(f, "COUNT(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
} else { |
|
|
|
@ -1377,33 +1401,45 @@ impl<'a> fmt::Display for SparqlAggregation<'a> { |
|
|
|
|
write!(f, "COUNT({})", SparqlExpression(e)) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "COUNT(*)") |
|
|
|
|
}, |
|
|
|
|
Aggregation::Sum(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Sum(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "SUM(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "SUM({})", SparqlExpression(e)) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Min(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Min(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "MIN(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "MIN({})", SparqlExpression(e)) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Max(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Max(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "MAX(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "MAX({})", SparqlExpression(e)) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Avg(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Avg(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "AVG(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "AVG({})", SparqlExpression(e)) |
|
|
|
|
}, |
|
|
|
|
Aggregation::Sample(e, distinct) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::Sample(e, distinct) => { |
|
|
|
|
if *distinct { |
|
|
|
|
write!(f, "SAMPLE(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "SAMPLE({})", SparqlExpression(e)) |
|
|
|
|
}, |
|
|
|
|
Aggregation::GroupConcat(e, distinct, sep) => if *distinct { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Aggregation::GroupConcat(e, distinct, sep) => { |
|
|
|
|
if *distinct { |
|
|
|
|
if let Some(sep) = sep { |
|
|
|
|
write!( |
|
|
|
|
f, |
|
|
|
@ -1423,7 +1459,8 @@ impl<'a> fmt::Display for SparqlAggregation<'a> { |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
write!(f, "GROUP_CONCAT({})", SparqlExpression(e)) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|