liveBook · Manning

Data aggregation

As explained in Graph Algorithms for Data Science

An aggregation is a query operation that combines values from multiple rows into summarized results.

Data aggregation summarizes rows returned by a Cypher query. It starts with counts of nodes, relationships, values, and graph patterns, then uses those summaries to describe a graph dataset or answer an analysis question. section 4.2 section 4.4

Use aggregation to:

  • Distinguish count(*)—all produced rows—from count(expression), which ignores null values. Comparing them exposes missing property values. section 4.2
  • Group counts by node labels or relationship types to summarize graph structure. section 4.2
  • Calculate ratios carefully: cast an integer to float before division when a fractional percentage is needed. section 4.2
  • Control intermediate cardinality between MATCH clauses. Aggregate with WITH before another match to avoid multiplying rows and producing incorrect counts. section 4.5
  • Count a node's matching pattern with count {} when multiple aggregations would otherwise increase the main query's cardinality. section 4.4

Checking registration-date completeness

Match User nodes, count all rows, and count u.registeredAt. The difference identifies users without a registration date; casting the non-null count to float before division yields the percentage present. section 4.2

Counting users and tweets safely

Two independent MATCH clauses can form a 3,594-by-12,060 row product. Count users in a WITH clause first, reducing the intermediate result to one row before matching tweets. section 4.5

Listing 4.4 Calculating the ratio of non-null values of registeredAt node property
MATCH (u:User)                                                            #1
WITH count(*) AS numberOfRows,
     count(u.registeredAt) AS usersWithRegisteredAtDate                   #2
RETURN toFloat(usersWithRegisteredAtDate) / numberOfRows * 100 AS result  #3

This query shows the complete pattern for counting non-null values and converting one count to float before calculating a percentage. section 4.2

How Graph Algorithms for Data Science covers it

How deep it goes
Explains count variants, null handling, percentages, grouping, and cardinality control, without detailing aggregation algorithms.
Examples
Uses User registration dates, node labels, relationship types, mentioned users, tweets, and hashtag-network components.
What it assumes
Introduces counting from Cypher query results; prior SQL experience is helpful but not required.
What you can do after
Apply it via Cypher to count graph data, measure missing values, and prevent misleading sequential-query totals.
How it connects
Connects Cypher aggregation to MATCH, WITH, OPTIONAL MATCH, WHERE, count {}, and query cardinality.

Also explained in

Compare how 19 books explain data aggregation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.