Aggregate Function Passdown
The Simba Neo4j JDBC Driver can pass certain queries down to the Neo4j server for execution. This improves the performance of the connector. Queries that are not passed down are executed by the connector.
Important:
The connector handles SUM(NULL) differently from the Neo4j server.
- The connector returns NULL for SUM(NULL)
- The Neo4j server returns 0 for SUM(NULL)
This might result in a discrepancy between queries that are passed down and queries that are resolved by the connector.
The connector supports a limited aggregate function passdown for simple queries. It enforces the following limitations:
- The supported expressions for the argument of an aggregate function are column references and literals.
-
The only supported expressions in the GROUP BY clause are column references.
- Aggregate functions must have 0 or 1 arguments.
- Aggregate functions are only supported in one level of any nested queries.
For example, the following queries can be passed down to the server:
- SELECT C1, C2, AVG(C3) + SUM(C4) FROM T1 GROUP BY C1, C2
- SELECT C1, SUM(1.1) FROM T1 GROUP BY C1
- SELECT SUM(C1) FROM T1
- SELECT SUM(1.1) FROM T1 GROUP BY C1
The following queries are not supported for aggregate function passdown:
- SELECT C1, SUM(C2 + C3) FROM T1 GROUP BY C1
- SELECT C1 + 1.0, SUM(C2) FROM T1 GROUP BY C1 + 1.0
- SELECT COUNT(*) FROM (SELECT C1, COUNT(*) AS test FROM T1 GROUP BY C1) Ta GROUP BY test
Important:
Aggregate values calculated by the server can be different than values calculated by the connector.
For example, the SQL query SELECT AVG(COL1) FROM t1, with COL1 containing the following values: 0.0, null, -0.0001, 4.9999, 99999.9999, 1.0, 1.0, 2.0, 3.0, 4.0, 5.0.
If the connector passes down the aggregation operation performed on COL1 to the Neo4j server, the aggregation result is determined to be 10002.099969999997. However, if the connector resolves the query and does not pass down the aggregation operation, the aggregation result is determined to be 10002.09997.