Distinct types of all created nodes and relationships in Memgraph's database - graph-databases

Where can I find Memgraph's docs to list all distinct types of all created nodes and relationships from a graph in database? I found this: https://memgraph.com/docs/cypher-manual/connecting-nodes and if I create nodes and relationships using that - I'd like to know how to retrieve all distinct node types and relationships from that example.

You can get all the distinct labels with the following query:
MATCH (n) RETURN DISTINCT labels(n);
And you can get the relationship types with:
MATCH ()-[r]-() RETURN DISTINCT type(r);

Related

Convert a string to an array in Google Dataprep

I'm trying to denormalize data in Dataprep so that I can use it in BigQuery.
More specifically, I'd like to turn entries in an account_profile table linked to my account table with with foreign key 'account_id' into an array in my account table. (Account_profile stores contact methods... bad name, I know.)
In dataprep, I've
turned the rows in account_profile into json objects,
and then joined the two tables via account_id,
then grouped the rows by account_id and used the aggregate function LIST to convert all objects into an array of objects.
The problem is that when I try to unnest that column in BigQuery, or do any other array-like operation in BigQuery, I get an error like this: "Values referenced in UNNEST must be arrays."
My data looks good. For example, here is a row.
[{"profile_identifier":"ttcuongem+29#gmail.com","verification_code":"abc789","enabled":true,"id1":2818},{"profile_identifier":"xyz123,"enabled":false,"id1":2874}]
I can't find a way to make BigQuery see this as an array, nor can I find a way to make Dataprep create this kind of data as an array rather than a string. The only solutions people have posted are very specific hacks that wouldn't apply to this generic case.
I feel that I'm following denormalization best practices and am surprised that this gap exists in the Google ELT toolchain. What am I missing?
Below is for BigQuery Standard SQL
You can use recently introduced JSON_EXTRACT_ARRAY function for this as in example below
#standardSQL
WITH `project.dataset.table` AS (
SELECT '''[
{"profile_identifier":"ttcuongem+29#gmail.com","verification_code":"abc789","enabled":true,"id1":2818},
{"profile_identifier":"xyz123","enabled":false,"id1":2874}
]''' string_col
)
SELECT JSON_EXTRACT_ARRAY(string_col) AS arr_col
FROM `project.dataset.table`
with output
Row arr_col
1 {"profile_identifier":"ttcuongem+29#gmail.com","verification_code":"abc789","enabled":true,"id1":2818}
{"profile_identifier":"xyz123","enabled":false,"id1":2874}

How to write a scala program to find semantic matching between the attributes in two tables

I'm working on pre-processing techniques, in which I am concentrating on semantic matching between attributes of two tables. How to write a scala program to do such semantic matching?
Consider I am having two tables A and B
A has attributes (employee_id, DOB, salary)
B has attributes (emp_id, data_of_birth, sal)
I need to find most matching attributes in two tables, so that my output table will not have duplicate columns (example: emp_id and employee_id should be found similar and considered as single cloumn).
Scala collection has intersection, which will get the common elements of two sets.
ex: collecationA.intersect(collectionB)
however if you are coming from spark api, the schema level comparison we can perform(same as intersect )operator
Hope this helps !!

soql getting data via a junction object

I have the following three custom objects:
Order__c
Design__c (has a lookup to Order and a lookup to Location, so the design ojbect is the junction object)
Location__c
On the order page layout I want to add a blank section that contains a VF page in order to display the Location records for all the design records for an order.
An order can have many designs and a design can have many locations. I need a way to group and display each design/locations in the VF page on the Order.
How can I build this query and display the results on the VF page?
I was trying a query like this: Select Location_r.Name, Location_r.Mockup From Design_c where Order_c = 'xxxxxxxxxxxxxx'
Also, is there a better way to display the results besides a VF page section in a related list?
Thanks for any help!
Regards.
First things, first. since design is related to the other 2 objects via lookup, it is not a junction object. junction objects are only when it's 2 parents have a master-detail relationship with the child.
I think what you're trying to achieve is to traverse a parent-child-parent relationship. You'll need to use subqueries for the last half. From the documentation- here you go: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm
Query **child-to-parent relationships**, which are often many-to-one. Specify these relationships directly in the SELECT, FROM, or WHERE clauses using the dot (.) operator.
For example:
SELECT Id, Name, Account.Name
FROM Contact
WHERE Account.Industry = 'media'
This query returns the ID and name for only the contacts whose related account industry is media, and for each contact returned, the account name.
Query **parent-to-child**, which are almost always one-to-many. Specify these relationships using a subquery (enclosed in parentheses), where the initial member of the FROM clause in the subquery is related to the initial member of the outer query FROM clause. Note that for subqueries, you should specify the plural name of the object as that is the name of the relationship for each object.
For example:
SELECT Name,
(
SELECT LastName
FROM Contacts
)
FROM Account
The query returns the name for all the accounts, and for each account, the last name of each contact.

How to do an initial batch import of CSV / MySQL data into neo4j database

I am considering replacing a MySQL database with a neo4j database. I am a complete beginner with neo4j and would like to know how to go about doing a batch insert of my current MySQL data into the neo4j database so i can experiment and begin to learn about neo4j.
the relational database consists of 4 tables: Person, Organism, Story, Links.
Links describes relationships between rows in the other 3 tables.
Links:
ID, FromTable, FromID, ToTable, ToID, LinkType
Person:
ID, property_2, property_1, etc ...
Organism:
ID, property_A, property_B, etc ....
Story:
ID, property_x, property_y
each ID field is an auto incrementing integer starting from 1 for each table
In case it is not obvious, a link between say person with ID 3 and a story with ID 42 would have a row in the Links table ID=autoincrement, FromTable=Person, FromID=3, ToTable=Story, ToID=42.
Even though I am using the terms 'from' and 'to' the actual links are not really 'directed' in practice.
I have looked at Michael Hunger's batch-import but that seems to only work with a single table of nodes and one table of relationships, whereas I am looking to import three different types of nodes and one list of relationships between them.
I have got neo4j up and running,
Any advice to get me started would be greatly appreciated.
I am not familiar with Java, though I do use Python and bash shell scripts.
After initial import, I will be using the RESTful interface with Javascript.
Based on advice in the git repo. Using Michael Hunger's batch-import it is possible to import multiple node types from the one .csv file.
To quote Michael:
Just put them all into one nodes file, you can have any attribute not
having a value in a certain row, it will then just be skipped.
So the general approach i used was:
combine all the nodes tables into a new table called nodes:
Create a new table nodes with an auto incrementing newID field and a type field. the type field will record what table the node data came from
Add all the possible columns names from the 3 node tables allowing nulls.
INSERT INTO nodes the values from Person, then Organism, then Story, in addition to setting the type field to person, organism, or story. Leave any unrelated fields blank.
in another new table rels add the newly created newID indexes to the Links table based on a sql JOIN:
INSERT INTO rels
SELECT
n1.newID AS fromNodeID,
n2.newID AS toNodeID,
L.LinkType,
L.ID
FROM
Links L
LEFT JOIN
nodes n1
ON
L.fromID = n1.ID
AND
L.fromType = n1.type
LEFT JOIN
nodes n2
ON
L.toID = n2.ID
AND
L.toType = n2.type;
Then export these two new tables nodes and rels as Tab seperated .csv files, and use them with batch-import:
$java -server -Xmx4G -jar target/batch-import-jar-with-dependencies.jar target/graph.db nodes.csv rels.csv
As you say that you are happy working with python and shell scripts, you may also want to have a look at the command line tools which come with py2neo, in particular geoff. This uses a flat file format I put together for holding graph data so in your instance, you would need to build a flat file from your source data and insert this into your graph database.
The file format and server plugin are documented here and the py2neo module for the client application is here.
If anything is missing from the docs or you want more information about this then feel free to drop me an email
Nigel

Does any (R)DBMS exist that supports Linked Lists?

Are there any commercial databases that support data types pointing to the root node of say a linked list?
For example, I was thinking about the design for a basic ORDERS table (for an e-commerce site - say eBay or Amazon). In this case, a single order could contain multiple items and different quantities of each item. I thought I could represent this by having a linked list of items in the item column of the ORDERS table and a corresponding linked list for the quantity column.
So when total price of an order has to be established - simply multiply corresponding nodes of the linked lists and sum them up (of course you have a separate PRICE table that stores price of each item).
Why do you want to use a linked list for this?
Consider the following structure:
Table: ORDERS
OrderID
client, datestamp, status, ...
Table: ItemsInOrders
ID
REF_ORDER (FK OrderID)
REF_Item (FK ItemID)
Quantity
Table: Items
ItemID
Price
Description, image, ...
Konerak gave the proper solution to this problem.
If you need a linked list in a database you basically need a purely object-oriented database or some mixed solution, like object types in Oracle. Then you can implement this yourself on the database side.

Resources