Skip to content

Commit

Permalink
feat: Add support for the remaining aggregate functions.
Browse files Browse the repository at this point in the history
See #519.
  • Loading branch information
michael-simons committed Oct 30, 2024
1 parent 46b1507 commit 7729ebd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,18 @@ else if (f instanceof QOM.Min<?> m) {
else if (f instanceof QOM.Max<?> m) {
return Cypher.max(expression(m.$field()));
}
else if (f instanceof QOM.Sum s) {
return Cypher.sum(expression(s.$field()));
}
else if (f instanceof QOM.Avg s) {
return Cypher.avg(expression(s.$field()));
}
else if (f instanceof QOM.StddevSamp s) {
return Cypher.stDev(expression(s.$field()));
}
else if (f instanceof QOM.StddevPop s) {
return Cypher.stDevP(expression(s.$field()));
}
else if (f instanceof QOM.Position p) {
return Cypher.call(FUNCTION_MAPPING.get("strpos"))
.withArgs(expression(p.$in()), expression(p.$arg2()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@ void simpleUpdateShouldWork() {
.isEqualTo("MATCH (a:Actor) WHERE id(a) = 4711 SET a.name = 'Foo'");
}

@ParameterizedTest
@CsvSource(delimiterString = "|", textBlock = """
SELECT name, count(*) FROM People p GROUP BY name|MATCH (p:People) RETURN p.name, count(*)
SELECT name, max(age) FROM People p GROUP BY name|MATCH (p:People) RETURN p.name, max(p.age)
SELECT name, min(age) FROM People p GROUP BY name|MATCH (p:People) RETURN p.name, min(p.age)
SELECT sum(age) FROM People p GROUP BY name|MATCH (p:People) RETURN sum(p.age)
SELECT avg(age) FROM People p GROUP BY name|MATCH (p:People) RETURN avg(p.age)
SELECT percentileCont(age) FROM People p GROUP BY name|MATCH (p:People) RETURN percentileCont(p.age)
SELECT percentileDisc(age) FROM People p GROUP BY name|MATCH (p:People) RETURN percentileDisc(p.age)
SELECT stDev(age) FROM People p GROUP BY name|MATCH (p:People) RETURN stDev(p.age)
SELECT stDevP(age) FROM People p GROUP BY name|MATCH (p:People) RETURN stDevP(p.age)
""")
void aggregates(String sql, String cypher) {

var translator = SqlToCypher.defaultTranslator();
assertThat(translator.translate(sql)).isEqualTo(cypher);

}

@Test
void outerSelectStarShouldBeRemoved() {

Expand Down

0 comments on commit 7729ebd

Please sign in to comment.