Skip to content

Instantly share code, notes, and snippets.

@valorkin
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valorkin/3bcd9bdf1eb76bfff806 to your computer and use it in GitHub Desktop.
Save valorkin/3bcd9bdf1eb76bfff806 to your computer and use it in GitHub Desktop.
cypher problem

Hello

Problem to solve, split collected data in independent rows

Setup data

create
 (gdp:Indicators{name: 'gdp'})-[:with_dimension]->(dygdp:Dimensions{name: 'years'}),
 (ldp:Indicators{name: 'ldp'})-[:with_dimension]->(dyldp:Dimensions{name: 'years'}),
 (gdp)-[:with_dimension]->(dcgdp:Dimensions{name: 'countries'}),
 (ldp)-[:with_dimension]->(dcldp:Dimensions{name: 'countries'}),
 (dygdp)-[:with_dimension_value]->(dvygdp0:DimensionValues{value: 1980}),
 (dygdp)-[:with_dimension_value]->(dvygdp1:DimensionValues{value: 1981}),
 (dyldp)-[:with_dimension_value]->(dvyldp0:DimensionValues{value: 1980}),
 (dyldp)-[:with_dimension_value]->(dvyldp1:DimensionValues{value: 1981}),
 (dcgdp)-[:with_dimension_value]->(dvcgdpm:DimensionValues{value: 'Morocco'}),
 (dcldp)-[:with_dimension_value]->(dvcldpm:DimensionValues{value: 'Morocco'}),
 (dvygdp0)-[:with_indicator_value]->(:IndicatorValues{value: '1'})<-[:with_indicator_value]-(dvcgdpm),
 (dvygdp1)-[:with_indicator_value]->(:IndicatorValues{value: '2'})<-[:with_indicator_value]-(dvcgdpm),
 (dvyldp0)-[:with_indicator_value]->(:IndicatorValues{value: '3'})<-[:with_indicator_value]-(dvcldpm),
 (dvyldp1)-[:with_indicator_value]->(:IndicatorValues{value: '4'})<-[:with_indicator_value]-(dvcldpm)
 return *

Working query, but need some tweak

// collected 2 indicators values - all relations
MATCH
(n:Indicators)-[:with_dimension]->(d:Dimensions{name: 'years'})-[:with_dimension_value]->(dv:DimensionValues),
(n:Indicators)-[:with_dimension]->(d1:Dimensions{name: 'countries'})-[:with_dimension_value]->(dv1:DimensionValues),
(dv)-[:with_indicator_value]->(iv:IndicatorValues)<-[:with_indicator_value]-(dv1)
where
n.name in  ['gdp', 'ldp']
return collect(n.name), dv.value, dv1.value, collect(iv.value)

What if want to achive

year country gdp ldp

1981

Morocco

2

4

1980

Morocco

1

3

Thanks for your help :)

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