Data Warehousing Lab sheets
  • CITS3401/5504 Lab Sheets
  • Week 1 - Introduction (Self-Reading)
  • Week 2 - Software Setup
  • Week 3 - Extract, transform, and load (ETL)
    • Task Demonstration Video
  • Week 4 - Designing a New Data Warehouse
  • Week 5 - Mini End-to-End Data Warehouse Project
  • Week 6 - Association Rules Mining
  • Week 8 - Neo4j
  • Week 9 - Import data from a relational database into Neo4j
  • Week 10 - Cypher Queries
    • Week 10 Sample Solution
  • Week 11 - Advanced Cypher and APOC
    • Week 11 Sample Solution
  • Week 12 - Graph Data Science
    • Week 12 Sample Solution
Powered by GitBook
On this page
  • C.3. List and Pattern Comprehension
  • C.4. Virtual Relationships and Virtual Nodes (Graph Projections)
  1. Week 11 - Advanced Cypher and APOC

Week 11 Sample Solution

Sample solution for Week 11 lab

C.3. List and Pattern Comprehension

Combine the two above into one block of queries to reduce redundant code.

MATCH (jobi:Cook {name: 'Jobi'})
WITH jobi, [(jobi)-->(b:Person) | b.occupation] AS jobi_circle_occupation
UNWIND jobi_circle_occupation AS occupation
WITH jobi, collect(DISTINCT occupation) AS distinct_occupations
SET jobi.circle_occupations = distinct_occupations
RETURN jobi

Modify the third code chunk and try to list the people with the number of occupation types related to them in desending order. e.g. (if the circle_occupation of Alice is ["Mechanic", "Actor"], the result should be Alice 2)

MATCH (n:Person)
WITH n, [(n)-->(b:Person) | b.occupation] AS my_circle_occupations
UNWIND my_circle_occupations AS occupations
WITH collect(DISTINCT occupations) AS distinct_occupations, n
SET n.num_circle_occupations = SIZE(distinct_occupations)
RETURN n.name,n.num_circle_occupations
ORDER BY n.num_circle_occupations DESC

C.4. Virtual Relationships and Virtual Nodes (Graph Projections)

Adapt the above code to create such virtual nodes for all cities.

MATCH (p:Person)-[:LIVES_IN]->(c:City)
WITH c, collect(p.name) AS residents, count(p) AS count
CALL apoc.create.vNode(residents,{name: residents}) YIELD node AS a
CALL apoc.create.vRelationship(a, "LIVES_IN", {count: count}, c) YIELD rel
RETURN a, c, rel
PreviousWeek 11 - Advanced Cypher and APOCNextWeek 12 - Graph Data Science

Last updated 1 year ago