Skip to content

SURF-768 Documentation for cardinality function#1574

Open
neo-harshg wants to merge 8 commits into
devfrom
SURF-768
Open

SURF-768 Documentation for cardinality function#1574
neo-harshg wants to merge 8 commits into
devfrom
SURF-768

Conversation

@neo-harshg

Copy link
Copy Markdown
Contributor

@neo-harshg neo-harshg force-pushed the SURF-768 branch 2 times, most recently from c8682c1 to 89d96ec Compare June 8, 2026 13:34
@gem-neo4j gem-neo4j self-assigned this Jun 9, 2026
Comment thread modules/ROOT/pages/functions/index.adoc Outdated
Comment thread modules/ROOT/pages/functions/scalar.adoc Outdated
| *Returns* 3+| `INTEGER`
|===

This function was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[] (optional GQL feature GF12, "CARDINALITY function").

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is needed, it offers new functionality unlike the alias ones you did, maybe Jens has an opinon on that though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - this is not necessary here.

Comment on lines +602 to +603
- For a `LIST<ANY>`, `cardinality()` returns the same result as xref:functions/scalar.adoc#functions-size[`size()`].
- For a `MAP`, it returns the same result as `size(keys(map))`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you switch the order to match the description?

- For a `PATH`, it returns the total number of nodes and relationships in the path.
- For a non-empty path, `cardinality(p) = 2 * length(p) + 1`.

Binding table reference values are not supported in Cypher, so this is an intentional subset of the full GQL cardinality expression.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not relevant here, it is most likely confusing to users who don't know GQL well


| `cardinality(null)` returns `null`.
| For a `LIST<ANY>`, only top-level elements are counted; nested lists count as a single element.
| `cardinality()` on values other than a `LIST<ANY>`, `MAP`, `PATH`, or `null` will fail the query.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true of all functions, I don't think we normally say that

Comment on lines +67 to +68
RETURN cardinality([1, 2, 3]);
MATCH p = (a)-[r]->(b) RETURN cardinality(p), length(p);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing the map case, also remove length as it isn't relevant here.

neo-harshg and others added 3 commits June 9, 2026 11:12
Co-authored-by: Gem Lamont <106068376+gem-neo4j@users.noreply.github.com>
Co-authored-by: Gem Lamont <106068376+gem-neo4j@users.noreply.github.com>
Comment thread modules/ROOT/pages/functions/index.adoc Outdated
Comment thread modules/ROOT/pages/functions/scalar.adoc Outdated
Comment thread modules/ROOT/pages/functions/scalar.adoc Outdated
Comment thread modules/ROOT/pages/functions/scalar.adoc Outdated
Co-authored-by: Jens Pryce-Åklundh <112686610+JPryce-Aklundh@users.noreply.github.com>
@neo4j-docops-agent

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants