How to get children of a node in redisgraph? - cypher

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.

Related

Verify if parent and child , Heirarchy, hql

I have a case where I am given 2 IDs and there are 2 columns,assuming names'subj'and 'obj' in a table.If the Id's dont match in a single row, then i have to take the obj value and search for its entry in some other row in the subj column and then try to match the object iteratively. the search ends when there is no subject entry for a particular object. There is no with clause in hql and hence this question.
Example lets say i am given 1,100. Then i have to search for 1 and then get its object entry, if it is not 100 and lets say it is 20, i have to take that 20 and search for 20,100 , and once again it is not 100 in object entry, i have to repeat the process. This is possible in sql, but since there is no with clause in HQL i need suggestions.
I can always do it in the application but i am looking for another answer! The search ends when there is no corresponding subject entry for an object entry, or when it matches.
You need recursion for this, which is supported by some database implementations, but not by hql
HQL recursion, how do I do this?

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

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,

Filter by dimension member only without sub-nodes

I need to query a cube by a ragged dimension (parent-child). The filter can be multiple nodes at any level.
This works in that it restricts the results to just the 2 supply chains I want...
SELECT [Measures].[Total Revenue] ON COLUMNS
, [Product].[Products].Members ON ROWS
FROM myCube
WHERE
(
{
[Supply Chain].[SupplyChains].&[{c0c62bda-0369-4591-be85-3a7078bc3352}]
, [Supply Chain].[SupplyChains].&[{aca836e9-22ac-4952-8809-3f50aeda6891}]
}
)
I know, guid keys, not my design! The problem is that data that isn't assigned to a specific supply chain is assigned to the top node. If I add the top node to the list, then all data will be returned (since all data is subordinate to it).
Is there a way to return values with a specific member and ignore its children? I'd like to say "return all data assigned exactly to the top node or to the listed supply chains and their children).
Thanks FrankPI, your comment pointed me in the right direction.
I ended up replicating the query in Excel and then examining the generated MDX using the OLAP PivotTable Extensions. Excel allows you to set filters on sub-nodes like what I was trying to do.
What it does is create a set of all nodes that don't have filtered sub-nodes to get everything else. Then for the parents of the nodes with filtered sub-nodes (and all its parents up to the root) it adds to the set those nodes but with the .DataMember function so that only the node value is included (but not its sub nodes). So basically instead of saying what NOT to get, it explicitly says what TO get, listing all other nodes which can be a bit cumbersome but works.

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.