How to find the node with outgoing relationship but no relationship on 2nd degree nodes - cypher

One question, I have 15000 nodes, with relationships. suppose few of them look like this all have the same label like number but different properties. also the relationship type is the same. Now i want to see if there are any nodes where inter relationship does not exist.
N
|
L--F--M
/
H-B-G
/
A
\C-D
\E
like is there any query which will help me to find the nodes N,M,L related to F but no relationship with each other. start node is A. Can i check that with cipher query? i was trying with the path but it was giving me the path exist between two nodes which i define but not random n number of nodes connected to one x node.
thanks,

Related

How to get children of a node in redisgraph?

This is a directed unweighted graph
I created this directed unweighted graph in redisgraph but at the time of traversing I am not able to fetch the children of A. Is there any command in redisgraph to get the children of A? Since the graph is fully dynamic, I don't know the exact nature of children of A. After getting the list of children I can match their property and fetch perfect node.
The node 'A' needs to be identified somehow, e.g. an attribute.
Using the Cypher query language one can get A's children by issuing the query:
MATCH (A {id:'a'})-[]->(X) RETURN X
Assuming 'A' has an attribute 'id' with the value 'a' than X represent all of A's direct neighbours.

Roll up not working correctly when using custom key columns

I have a dimension that I flattened, the data looks like:
This is a simplification of the data, I actually have 7 "Detail" values that are the same for each PrimaryValue and 2 "SubDetail" values. Each SubValue has one blank (not a null, there are no nulls in the table) for each PrimaryValue.
I am trying to setup a hierarchy so the users see:
PrimaryValue
SubValue
The cube does not like the data and complains about duplicate keys so I changed the key columns and I got it to process but my hierarchy shows one PrimaryValue for each SubValue so It looks like this in the Browser:
ABC
this one is the blank value
ABC
A
ABC
Q
ABC
G
And so on. When I what I want is:
ABC
A
Q
G
XYZ
7
F
1E
I am new to cubes but I have tried everything I can think of and read about on the web. I think my issue is that I have multiple "Detail" and "SubDetail". I have the Hierarchy defined as:
PrimaryValue
SubValue
I setup the Attributes so PrimaryValue relates to SubValue and Detail1 and Detail2 I have SubValue relating to SubDetail1.
I have tried every KeyColumns combination I can think of and either the cube wont process due to duplicate key values, or it will process and I get the issue I am describing here or I get and error in the Browser "The key1 dimension attribute was not found"
I could not find anything on the web about this issue, I am probably wording it wrong. I have found a lot about setting up key columns but none address the extra detail fields in their examples or describe the rollup issues I am seeing.
This is a simple answer, I am surprised I could not find this error on the web. I had my attribute relationships backward. Should be most specific to most general but I had the most general (the one with the fewest unique values) to the most specific (the one with the most unique values). Surprised it worked at all!!
So in my example I should have had SubValue related to PrimaryValue.

ER diagram relationship and Bridge Tables

I have to design a database for buses timetables.
Entities:
Bus (idBus*)
Stop (idStop*,stopDescription)
Line (idLine*,lineDescription)
Position (lat,lon)
Some constraints are the following:
Multiple Buses may operate for one Line (therefore BUS:LINE = N:1)
One Line has many Stops , and from one Stop are passing many Lines (therefore STOP:LINE = N:N)
One Bus passes from many Stops and vice versa (therefore BUS:STOP = N:N)
A Stop has One Position (therefore STOP:POSITION = N:N)
A Bus has multiple Positions (therefore BUS:POSITION = 1:N)
E-R DIAGRAM
An example of modelling would be a bridging table for the STOP-POSITION relationship that would look like this:
STOP_POSITION(idStop*,lat,lon) whereas idStop is the Foreign Key.
In general:
If i have an idBus i would like to be able to get the associated idLine.
If i have an idBus and an idStop i would like to have info on the itinerary of the Bus (which is the next stop , time of arrival, direction)
If i have an idBus and an idLine i would like to get the itinerary of the Bus(all the Stops from where the Bus will pass and their order)
Questions
The problem arise when considering the BUS-STOP relationship, because when i consider to know the id of the Stop and the id of the Bus then i will know a number of attributes like Direction,ID of NextStop, TimeOfArrival..
How should i model those attributes?
For example, every Bus is passing from multiple Stops and the progression is denoted by an attribute (e.g progressiveStop). How should i model this attribute?
Does it really make sense modelling the association of LINE-STOP?
Does it really make sense storing dynamic data in the database? I am referring to the BUS-STOP relationship.

Parent-child dimension - confused levels

I am running Analysis Services 2008 R2 and have come across some behavior that I really do not understand and I can't seem to get to the bottom of it. I have a dimension called Segment which is a simple Parent-child dimension where only one of the four top-level members has any children. This one member, has two children. Only leaf nodes have any values.
In the dimension I have used AttributeAllMemberName to allow "All Segments" to be used to refer to the top-level members. There are three dimensions used in the cube: Segment, Country and Year.
When I run:
SELECT {{Descendants([Country].[Global],, SELF_BEFORE_AFTER)}} ON ROWS,
{[Segment].[All Segments].children}*{[Measures].[Volume tonnes]} ON COLUMNS
FROM [Market]
WHERE [Year].[2012]
I see all members on the columns but the one node that has children has an empty column. My understanding is that "children" should show me only one level not two. If, on the other hand I run
SELECT {{Descendants([Country].[Global],, SELF_BEFORE_AFTER)}} ON ROWS,
{[Segment].[(all)].[All Segments].children}*{[Measures].[Volume tonnes]} ON COLUMNS
FROM [Market]
WHERE [Year].[2012]
I see exactly what I would expect; the four top-level children with correctly aggregated values for the one child that has its own children. No grand-children are shown. In either case the right number of rows are displayed.
The only difference between the two queries is that the "[(all)]" level has been explicitly listed in the second query. Given that the "all" member is defined as the only member of the "(all)" level set, these two queries should return the same values but they don't. I must be missing something in the dimension config, but what? Can someone point me in the right direction to fix this? I need the query to work properly without having to use "[(all)]".
To stop this post becoming too bloated, I have posted some screen-grabs of BIDS to my own website to show the configuration of the dimension. There are three attributes and the dimension itself that require configuration but I can only post two links so have linked them all in from this page: http://coolwire.co.uk/share/BIDS.html
The Hierarchy and the Ordering are related to the Key by rigid attribute-relationships.
It all looks okay to me but the problem must be in here somewhere.

How to only display a TreeView expand sign [+] if children exist

I've developed an application that populates a treeview from hierachical data in a database.
I've designed it to use lazy-loading so it only gets the child nodes when a node is expanded.
My problem is that obviously I don't know if a node has children unless I make a call to the database and look. Currently I have implemented a dummy child node, so that the [+] icon appears for all nodes, I then remove this dummy node and get the real child nodes in the BeforeExpand event.
This means I get a [+] icon for nodes that don't have child nodes, so the user clicks the expand icon and there's nothing show which looks a bit shoddy.
What is the preffrred method for handling child nodes in a lazy-load treeview? If I make a call to the database to see if there are child nodes then I might as well just load the child nodes and forget about lazy loading right?
One thought I had was to store a 'HasChildren' flag in the database, so I can selectively create my dummy child node only for the nodes that actually do have child nodes.
Sorry for rambling on, I'm very interested to see what other people think...
When you make a call, check for children along with the node data:
SELECT tp.*,
(
SELECT 1
FROM table tc
WHERE tc.parent = tp.id
LIMIT 1
) AS has_children
FROM table tp
You don't have to count, it may be long.
Just check that at least one child exists.
change your initial query to return all the same data, but also a count of children. when the children count is not zero show the [+]. post your schema and query for help getting the count
My preferred solution to this problem is to implement pre-ordered tree traversal on your set of hierarchical data. See http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ for an example implementation.
The point is that if you maintain a left and right value for each node, then if the left value and right value differ by more than one, that node has children.
The only notable downside of this approach is that you have to actively maintain those left and right values when altering the structure of the nodes.