|
|
@ -747,7 +747,8 @@ impl<'a> fmt::Display for SparqlExpression<'a> { |
|
|
|
SparqlExpression(&*b), |
|
|
|
SparqlExpression(&*b), |
|
|
|
SparqlExpression(cv) |
|
|
|
SparqlExpression(cv) |
|
|
|
) |
|
|
|
) |
|
|
|
}).unwrap_or_else(|| { |
|
|
|
}) |
|
|
|
|
|
|
|
.unwrap_or_else(|| { |
|
|
|
write!( |
|
|
|
write!( |
|
|
|
f, |
|
|
|
f, |
|
|
|
"SUBSTR({}, {})", |
|
|
|
"SUBSTR({}, {})", |
|
|
@ -1130,31 +1131,35 @@ impl<'a> fmt::Display for SparqlGraphPattern<'a> { |
|
|
|
SparqlGraphPattern(&*a), |
|
|
|
SparqlGraphPattern(&*a), |
|
|
|
SparqlGraphPattern(&*b) |
|
|
|
SparqlGraphPattern(&*b) |
|
|
|
), |
|
|
|
), |
|
|
|
GraphPattern::Service(n, p, s) => if *s { |
|
|
|
GraphPattern::Service(n, p, s) => { |
|
|
|
write!(f, "SERVICE SILENT {} {{ {} }}", n, SparqlGraphPattern(&*p)) |
|
|
|
if *s { |
|
|
|
} else { |
|
|
|
write!(f, "SERVICE SILENT {} {{ {} }}", n, SparqlGraphPattern(&*p)) |
|
|
|
write!(f, "SERVICE {} {{ {} }}", n, SparqlGraphPattern(&*p)) |
|
|
|
} else { |
|
|
|
}, |
|
|
|
write!(f, "SERVICE {} {{ {} }}", n, SparqlGraphPattern(&*p)) |
|
|
|
GraphPattern::Data(bs) => if bs.is_empty() { |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
write!(f, "VALUES ( ")?; |
|
|
|
|
|
|
|
for var in bs.variables() { |
|
|
|
|
|
|
|
write!(f, "{} ", var)?; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
write!(f, ") {{ ")?; |
|
|
|
} |
|
|
|
for values in bs.values_iter() { |
|
|
|
GraphPattern::Data(bs) => { |
|
|
|
write!(f, "( ")?; |
|
|
|
if bs.is_empty() { |
|
|
|
for val in values { |
|
|
|
Ok(()) |
|
|
|
match val { |
|
|
|
} else { |
|
|
|
Some(val) => write!(f, "{} ", val), |
|
|
|
write!(f, "VALUES ( ")?; |
|
|
|
None => write!(f, "UNDEF "), |
|
|
|
for var in bs.variables() { |
|
|
|
}?; |
|
|
|
write!(f, "{} ", var)?; |
|
|
|
} |
|
|
|
} |
|
|
|
write!(f, ") ")?; |
|
|
|
write!(f, ") {{ ")?; |
|
|
|
|
|
|
|
for values in bs.values_iter() { |
|
|
|
|
|
|
|
write!(f, "( ")?; |
|
|
|
|
|
|
|
for val in values { |
|
|
|
|
|
|
|
match val { |
|
|
|
|
|
|
|
Some(val) => write!(f, "{} ", val), |
|
|
|
|
|
|
|
None => write!(f, "UNDEF "), |
|
|
|
|
|
|
|
}?; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
write!(f, ") ")?; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
write!(f, " }}") |
|
|
|
} |
|
|
|
} |
|
|
|
write!(f, " }}") |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
GraphPattern::AggregateJoin(GroupPattern(group, p), agg) => write!( |
|
|
|
GraphPattern::AggregateJoin(GroupPattern(group, p), agg) => write!( |
|
|
|
f, |
|
|
|
f, |
|
|
|
"{{ SELECT {} WHERE {{ {} }} GROUP BY {} }}", |
|
|
|
"{{ SELECT {} WHERE {{ {} }} GROUP BY {} }}", |
|
|
@ -1301,63 +1306,81 @@ pub enum Aggregation { |
|
|
|
impl fmt::Display for Aggregation { |
|
|
|
impl fmt::Display for Aggregation { |
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
Aggregation::Count(e, distinct) => if *distinct { |
|
|
|
Aggregation::Count(e, distinct) => { |
|
|
|
e.as_ref() |
|
|
|
if *distinct { |
|
|
|
.map(|ex| write!(f, "COUNT(DISTINCT {})", ex)) |
|
|
|
e.as_ref() |
|
|
|
.unwrap_or_else(|| write!(f, "COUNT(DISTINCT *)")) |
|
|
|
.map(|ex| write!(f, "COUNT(DISTINCT {})", ex)) |
|
|
|
} else { |
|
|
|
.unwrap_or_else(|| write!(f, "COUNT(DISTINCT *)")) |
|
|
|
e.as_ref() |
|
|
|
} else { |
|
|
|
.map(|ex| write!(f, "COUNT({})", ex)) |
|
|
|
e.as_ref() |
|
|
|
.unwrap_or_else(|| write!(f, "COUNT(*)")) |
|
|
|
.map(|ex| write!(f, "COUNT({})", ex)) |
|
|
|
}, |
|
|
|
.unwrap_or_else(|| write!(f, "COUNT(*)")) |
|
|
|
Aggregation::Sum(e, distinct) => if *distinct { |
|
|
|
} |
|
|
|
write!(f, "Aggregation(Distinct({}), Sum, {{}})", e) |
|
|
|
} |
|
|
|
} else { |
|
|
|
Aggregation::Sum(e, distinct) => { |
|
|
|
write!(f, "Aggregation({}, Sum, {{}})", e) |
|
|
|
if *distinct { |
|
|
|
}, |
|
|
|
write!(f, "Aggregation(Distinct({}), Sum, {{}})", e) |
|
|
|
Aggregation::Min(e, distinct) => if *distinct { |
|
|
|
} else { |
|
|
|
write!(f, "Aggregation(Distinct({}), Min, {{}})", e) |
|
|
|
write!(f, "Aggregation({}, Sum, {{}})", e) |
|
|
|
} else { |
|
|
|
} |
|
|
|
write!(f, "Aggregation({}, Min, {{}})", e) |
|
|
|
} |
|
|
|
}, |
|
|
|
Aggregation::Min(e, distinct) => { |
|
|
|
Aggregation::Max(e, distinct) => if *distinct { |
|
|
|
if *distinct { |
|
|
|
write!(f, "Aggregation(Distinct({}), Max, {{}})", e) |
|
|
|
write!(f, "Aggregation(Distinct({}), Min, {{}})", e) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
write!(f, "Aggregation({}, Max, {{}})", e) |
|
|
|
write!(f, "Aggregation({}, Min, {{}})", e) |
|
|
|
}, |
|
|
|
} |
|
|
|
Aggregation::Avg(e, distinct) => if *distinct { |
|
|
|
} |
|
|
|
write!(f, "Aggregation(Distinct({}), Avg, {{}})", e) |
|
|
|
Aggregation::Max(e, distinct) => { |
|
|
|
} else { |
|
|
|
if *distinct { |
|
|
|
write!(f, "Aggregation({}, Avg, {{}})", e) |
|
|
|
write!(f, "Aggregation(Distinct({}), Max, {{}})", e) |
|
|
|
}, |
|
|
|
} else { |
|
|
|
Aggregation::Sample(e, distinct) => if *distinct { |
|
|
|
write!(f, "Aggregation({}, Max, {{}})", e) |
|
|
|
write!(f, "Aggregation(Distinct({}), Sum, {{}})", e) |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
write!(f, "Aggregation({}, Sample, {{}})", e) |
|
|
|
Aggregation::Avg(e, distinct) => { |
|
|
|
}, |
|
|
|
if *distinct { |
|
|
|
Aggregation::GroupConcat(e, distinct, sep) => if *distinct { |
|
|
|
write!(f, "Aggregation(Distinct({}), Avg, {{}})", e) |
|
|
|
sep.as_ref() |
|
|
|
} else { |
|
|
|
.map(|s| { |
|
|
|
write!(f, "Aggregation({}, Avg, {{}})", e) |
|
|
|
write!( |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 { |
|
|
|
|
|
|
|
sep.as_ref() |
|
|
|
|
|
|
|
.map(|s| { |
|
|
|
|
|
|
|
write!( |
|
|
|
f, |
|
|
|
f, |
|
|
|
"Aggregation(Distinct({}), GroupConcat, {{\"separator\" → \"{}\"}})", |
|
|
|
"Aggregation(Distinct({}), GroupConcat, {{\"separator\" → \"{}\"}})", |
|
|
|
e, |
|
|
|
e, |
|
|
|
s.escape() |
|
|
|
s.escape() |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.unwrap_or_else(|| write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e)) |
|
|
|
.unwrap_or_else(|| { |
|
|
|
} else { |
|
|
|
write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e) |
|
|
|
sep.as_ref() |
|
|
|
}) |
|
|
|
.map(|s| { |
|
|
|
} else { |
|
|
|
write!( |
|
|
|
sep.as_ref() |
|
|
|
f, |
|
|
|
.map(|s| { |
|
|
|
"Aggregation({}, GroupConcat, {{\"separator\" → \"{}\"}})", |
|
|
|
write!( |
|
|
|
e, |
|
|
|
f, |
|
|
|
s.escape() |
|
|
|
"Aggregation({}, GroupConcat, {{\"separator\" → \"{}\"}})", |
|
|
|
) |
|
|
|
e, |
|
|
|
}) |
|
|
|
s.escape() |
|
|
|
.unwrap_or_else(|| write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e)) |
|
|
|
) |
|
|
|
}, |
|
|
|
}) |
|
|
|
|
|
|
|
.unwrap_or_else(|| { |
|
|
|
|
|
|
|
write!(f, "Aggregation(Distinct({}), GroupConcat, {{}})", e) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1367,63 +1390,77 @@ struct SparqlAggregation<'a>(&'a Aggregation); |
|
|
|
impl<'a> fmt::Display for SparqlAggregation<'a> { |
|
|
|
impl<'a> fmt::Display for SparqlAggregation<'a> { |
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
match self.0 { |
|
|
|
match self.0 { |
|
|
|
Aggregation::Count(e, distinct) => if *distinct { |
|
|
|
Aggregation::Count(e, distinct) => { |
|
|
|
if let Some(e) = e { |
|
|
|
if *distinct { |
|
|
|
write!(f, "COUNT(DISTINCT {})", SparqlExpression(e)) |
|
|
|
if let Some(e) = e { |
|
|
|
|
|
|
|
write!(f, "COUNT(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
write!(f, "COUNT(DISTINCT *)") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if let Some(e) = e { |
|
|
|
|
|
|
|
write!(f, "COUNT({})", SparqlExpression(e)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
write!(f, "COUNT(DISTINCT *)") |
|
|
|
write!(f, "COUNT(*)") |
|
|
|
} |
|
|
|
} |
|
|
|
} else if let Some(e) = e { |
|
|
|
} |
|
|
|
write!(f, "COUNT({})", SparqlExpression(e)) |
|
|
|
Aggregation::Sum(e, distinct) => { |
|
|
|
} else { |
|
|
|
if *distinct { |
|
|
|
write!(f, "COUNT(*)") |
|
|
|
write!(f, "SUM(DISTINCT {})", SparqlExpression(e)) |
|
|
|
}, |
|
|
|
} else { |
|
|
|
Aggregation::Sum(e, distinct) => if *distinct { |
|
|
|
write!(f, "SUM({})", SparqlExpression(e)) |
|
|
|
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)) |
|
|
|
write!(f, "MIN(DISTINCT {})", SparqlExpression(e)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
write!(f, "MIN({})", SparqlExpression(e)) |
|
|
|
write!(f, "MIN({})", SparqlExpression(e)) |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
Aggregation::Max(e, distinct) => if *distinct { |
|
|
|
Aggregation::Max(e, distinct) => { |
|
|
|
write!(f, "MAX(DISTINCT {})", SparqlExpression(e)) |
|
|
|
if *distinct { |
|
|
|
} else { |
|
|
|
write!(f, "MAX(DISTINCT {})", SparqlExpression(e)) |
|
|
|
write!(f, "MAX({})", SparqlExpression(e)) |
|
|
|
} else { |
|
|
|
}, |
|
|
|
write!(f, "MAX({})", SparqlExpression(e)) |
|
|
|
Aggregation::Avg(e, distinct) => if *distinct { |
|
|
|
} |
|
|
|
write!(f, "AVG(DISTINCT {})", SparqlExpression(e)) |
|
|
|
} |
|
|
|
} else { |
|
|
|
Aggregation::Avg(e, distinct) => { |
|
|
|
write!(f, "AVG({})", SparqlExpression(e)) |
|
|
|
if *distinct { |
|
|
|
}, |
|
|
|
write!(f, "AVG(DISTINCT {})", SparqlExpression(e)) |
|
|
|
Aggregation::Sample(e, distinct) => if *distinct { |
|
|
|
} else { |
|
|
|
write!(f, "SAMPLE(DISTINCT {})", SparqlExpression(e)) |
|
|
|
write!(f, "AVG({})", SparqlExpression(e)) |
|
|
|
} else { |
|
|
|
} |
|
|
|
write!(f, "SAMPLE({})", SparqlExpression(e)) |
|
|
|
} |
|
|
|
}, |
|
|
|
Aggregation::Sample(e, distinct) => { |
|
|
|
Aggregation::GroupConcat(e, distinct, sep) => if *distinct { |
|
|
|
if *distinct { |
|
|
|
if let Some(sep) = sep { |
|
|
|
write!(f, "SAMPLE(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
write!(f, "SAMPLE({})", SparqlExpression(e)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Aggregation::GroupConcat(e, distinct, sep) => { |
|
|
|
|
|
|
|
if *distinct { |
|
|
|
|
|
|
|
if let Some(sep) = sep { |
|
|
|
|
|
|
|
write!( |
|
|
|
|
|
|
|
f, |
|
|
|
|
|
|
|
"GROUP_CONCAT(DISTINCT {}; SEPARATOR = \"{}\")", |
|
|
|
|
|
|
|
SparqlExpression(e), |
|
|
|
|
|
|
|
sep.escape() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
write!(f, "GROUP_CONCAT(DISTINCT {})", SparqlExpression(e)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if let Some(sep) = sep { |
|
|
|
write!( |
|
|
|
write!( |
|
|
|
f, |
|
|
|
f, |
|
|
|
"GROUP_CONCAT(DISTINCT {}; SEPARATOR = \"{}\")", |
|
|
|
"GROUP_CONCAT({}; SEPARATOR = \"{}\")", |
|
|
|
SparqlExpression(e), |
|
|
|
SparqlExpression(e), |
|
|
|
sep.escape() |
|
|
|
sep.escape() |
|
|
|
) |
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
write!(f, "GROUP_CONCAT(DISTINCT {})", SparqlExpression(e)) |
|
|
|
write!(f, "GROUP_CONCAT({})", SparqlExpression(e)) |
|
|
|
} |
|
|
|
} |
|
|
|
} else if let Some(sep) = sep { |
|
|
|
} |
|
|
|
write!( |
|
|
|
|
|
|
|
f, |
|
|
|
|
|
|
|
"GROUP_CONCAT({}; SEPARATOR = \"{}\")", |
|
|
|
|
|
|
|
SparqlExpression(e), |
|
|
|
|
|
|
|
sep.escape() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
write!(f, "GROUP_CONCAT({})", SparqlExpression(e)) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|