Hello guys.
So we are going to continue the discussion with respect to our graph database.
Now we are going to see some more amazing examples which will be intermediate to advanced level.
And we will try to see that how we can upload this particular data in the graph database itself.
Right.
So uh, here you will be able to see that I've created a GitHub link where I have uploaded some of the
database like uh, data sets, like movies, dot CSV posts, dot CSV ratings, dot CSV.
And then we will take all the CSV file and we'll try to upload this particular data set inside this
graph database itself.
So for that what kind of queries will be required.
All those things we will be discussing.
So the kind of use case that I'm actually going to show you, it is something related to social media
platform.
You know.
So you know that you will be posting your post.
There will be various users.
And based on that, you may be liking a specific post, you know, and you may also have some of the
friends in your social media platform.
So considering this, you can see these are some of the important CSV files.
So here is one user underscore social dot csv.
So here you have user id name age and city.
So these are all the details.
And it is a comma separated file.
Then uh you have this user ID user ID two type like uh 1 to 2.
Uh, who all are friends, right.
Based on the user ID.
So here you can see if 1 to 2 friend is there.
So John and Sarah is actually a friend.
Right.
And similarly 1 to 3 is a friend then 4 to 1.
So fourth ID is basically liking the post of the first ID uh, in terms of the user.
Right.
So all these information is there.
Other than that, you also have some post ID content, user ID and time stamp.
So there is also a post dot csv file.
Here you have posted something with respect to the time stamp and you have all the information.
Now what we are going to do.
First of all, we will insert all the specific data, uh, inside my graph database.
So how do we insert a data.
So for this we will be using a inbuilt function which is called as load CSV.
Right.
So here I'll say load CSV with headers.
Okay.
So I'll say hey with headers we are going to load all the CSV file.
Then uh it will ask me where the CSV file is available.
Right.
So uh right now I have used this.
So here you'll be able to see that I will be copying this entire link.
I'll be pasting it over here okay.
So this will be the link, uh, where my CSV file is present.
So I will just go ahead and create as a temporary variable called as row.
Okay.
This row will be making sure that it will have all rows.
It will basically iterate to all the records that are available inside the CSV file.
Okay.
Then we'll go to the next line and then we will go ahead and create all these users.
Okay.
Now here what exactly we have specifically done.
It's just like you are loading this entire CSV file.
You are running a for loop on each and every records.
Okay, so I hope this is very much visible.
Okay, so I'll be just writing it in this way.
Now what I will do, I will go ahead and say for every row let's create a user okay I know so there
is a specific user over here.
And if you probably click this user, there are some of the users that you will be able to see.
Okay.
And uh, let me just zoom out, okay.
And right now the user is just in this ID format.
Okay.
So it was the previous data itself.
Uh, so what I will do is that I will just delete this user, okay.
In order to delete it, you just need to instead of writing return and I will go ahead and delete it.
Delete n okay.
So just by using this delete n and no need to write limit 25, you'll be able to delete the entire node.
So once I execute it here you can see deleted five nodes.
Now you can't you can't see any users over here as the nodes.
Right.
So uh, try to do it in that way.
Now I will go ahead and create my user.
Okay.
Now when we are creating this specific user here, I will also go ahead and specify my user ID.
So let's go ahead and specify my user ID.
This user id will basically be my properties right here.
I will be using two integer.
Now see this.
Once we use two integer, that basically means what we are doing for every row.
Whatever will be the ID over there, right?
So right now this is the user ID right?
By default when we read it this will be in string.
But we will try to convert this into an integer.
So here I'm going to write row dot user id okay.
So row dot user id will be the thing.
Then after that let's go ahead and create my name row like a name property.
So it will be again row dot name okay.
And finally you have this age which will be again two integer.
We will use two integer to float whatever numbers you want.
And here I'm going to basically write row dot age.
So this way we are actually going to create all our properties right.
And finally after this we will also create one more.
That is nothing but city Rho dot city.
Okay.
So I hope uh, every user should be getting created directly from the CSV file.
Okay.
so now what I'm going to do I'll close this.
And now let's execute it and let's see whether everything is working fine or not.
So here you can see hey amazing.
It has created five nodes 20 properties and added five labels right now.
Uh, obviously the label is nothing but user.
And here are all your you have all the element, all the people name like Sarah, John, Mike.
Right.
David and Linda.
Right.
So all this information is specifically there.
Perfect.
So these are the people who are specifically using the social media platform over here right now.
Coming to the next one.
For the next one, I will just go back to my post dot CSV.
And these are the information that are posted with respect to the post ID.
And here you can see mapping is also there with respect to the user ID okay.
Okay.
So let's go ahead and upload this specific file.
Now what you do is that just pause the video and just try to see that how you will be able to load this
particular file.
Okay.
Now I'm going to probably write down the query over here.
So here I'm going to say load CSV with headers okay.
Then I'm going to use from and let me just go ahead and use my URL.
Okay.
And here is the URL.
Please try to understand the syntax okay.
So the syntax is very much simple.
We are just using load CSV with headers from this particular URL.
And here also I will just go ahead and use Azure.
Okay.
And uh with respect to the Azure or what we are going to do is that we are going to write this in my
next query, I will say, hey, go ahead and do the matching.
And this time when you are doing the matching, please, first of all, let's go ahead and match the
user.
So I will write you colon user okay u colon user.
And again I will go ahead and say, hey, use this user ID whichever property we have actually created,
let me make some space over here so that it looks good and I'll say, hey, the user ID will try to
convert this into integer, okay.
And then we'll say row dot user id you'll understand what we are exactly doing.
We are matching all the users based on the user ID which we are retrieving it from row dot user id okay,
after doing this particular match, what we have to do is that we have to create a relation.
Now let's go ahead and create this.
I will say, hey, create this user and create a relation, something like Dash.
And let's keep that relation as something like posted okay.
So here I'm going to create my relation as posted.
And this posted should have a relation with what with obviously post.
So this will basically be my label right with post.
Oh let me just go ahead and write posts right.
And here we are going to use some properties like post ID okay.
What will be the post ID that I have.
ID okay it will be again two integer.
And here I'm going to use row dot post id because from this row I will be able to access all the post
id, so I will just go ahead and write row dot post id right?
So let's see what are the post IDs there.
So I will copy this over here.
All right.
Perfect.
Similarly uh the next field that I have is nothing but content.
So I'll go ahead and write.
Content is equal to row dot content.
Right.
Because that is my sorry row dot content not raw.
Row dot content.
Right.
So this is what is my content is there.
Then I have my user ID okay.
So let's go ahead and write the user ID.
But the user id we have already done the mapping.
So I will just go ahead and put the timestamp right.
So here the next thing that I'm actually going to use is time stamp.
Now inside this time stamp I'll use date time.
Right.
So date time is obviously there.
See over here itself because we need to convert that into date time.
So here I have a namespace called as date time.
And here we are going to just go ahead and write row dot time stamp.
Perfect.
And then we will close this entire query.
Step by step.
See here we are matching with respect to user ID and the row user id right.
So user id this two rows user id.
So then mapping has specifically done.
And we are creating a relationship called as posted.
So once I execute this here you can see five nodes is specifically there.
And if I click on post amazing.
See all the posts are there.
Right.
So this is my uh ID also it is mapped right?
My first post my timestamp.
So Mike has posted this third and Linda has posted this other post.
David has posted this right.
All this information is John has posted this right.
So this posting has been done.
And here we can just go ahead and check match P is equal to some blank space Like give nothing over
here and try to see like where is this specific relation.
Once I click on this posted you are able to see this.
Okay now let's do one more thing.
There is also one called as relation dot csv.
Right?
We need to understand who are whose friends right.
So for this we need to load this entire relationship dot dot csv file.
Again let's go ahead and write it down.
So I'll write load underscore CSV with headers.
Okay.
From my file name.
File name is nothing.
But where is my relationship file.
So it is present in this GitHub location.
And here also I will just go ahead and create a temporary row and let's press enter okay.
Now this is just a simple match query.
First of all we need to match with the user ID with row is your ID then YouTube user with a user id
two.
See there are two users ID right over here.
See this user id one.
User id two.
User id one to user id two.
What type the friends are.
Right.
So this is the kind of mapping that you will be able to see.
So that is the reason we made two mappings.
One is UU1 with user id, one uh user id and then YouTube u2 with user id where we are mapping user
id to user id two, and then we are mapping this user id to user id one.
Okay.
Then we are creating this called as create U1 friends friends relationship likes relationship with U1
to U2.
Okay, so just go ahead and explore this.
You will get a complete idea what exactly we have done over here.
So once I execute this So created 22 relationships.
This is amazing.
Right?
So, uh, if you go ahead and see.
Friends see nicely.
All the graph is basically coming.
Sarah is a friend of Mike.
John is a.
Friend of Mike.
Then.
And remember this user ID and user one uh, user ID is basically getting mapped.
Right 1 to 2.
Right 1 to 2 basically means one is the friend of two.
So one is John is friend of Sarah.
So if you go ahead and see John is a friend of Sarah, then Sarah is a friend of Mike.
This entire friend circle is basically getting created perfect.
So, uh, I hope you have understood of probably creating all the tables and how you can basically define
all the relationships.
Now it's time we start retrieving like start.
Let's start from some basic queries.
We will go ahead and retrieve all users.
So for this I'm going to write my match keyword.
Let me go ahead and write you colon user okay.
This will basically be user.
And let's return return you okay.
So once I execute this here you will be able to see that I'm able to get all the users over here Sara,
John, David Linda and Mike.
Okay.
Now the next one, what I will do is that I will retrieve all the post.
Okay, so here again we will use a match query.
Let me go ahead and write P colon post post okay.
And here we are going to return P okay.
Sorry we have to use this capital letter.
It's good return p.
P.
So I'm just trying to check which all posts are there.
So so many different posts are there.
Love New York beautiful.
And this is basically given with the help of this post ID okay, perfect.
Now let's retrieve a friend of a specific user.
Okay.
If I say hey for this user John who is the friend.
So here what I'm actually going to do again, I'll go ahead and write my match query.
And with respect to this match query again I will go and write u is equal to u colon user.
Okay.
And then I will go ahead and use the property name colon name colon.
Nothing but John.
Okay.
So once I do this and now I need to probably create that relation.
The relation is very simple friend.
Right.
So I will use this I will write colon friend okay.
And then I will say hey give me f user.
Okay.
I'm just creating this another label.
So here let me go ahead and write F user.
This will be another label.
This will be another label to distinguish between them.
Right.
And then we are just going to return f dot name.
So once I do this you will be able to see that you'll be getting all the f uh f dot names over here.
So David, Sara, Mike, Linda are the friends of John.
And if you don't believe me, see David, Sara, Mike and Linda.
So if I go and click on friend David.
Uh, David is the friend.
Sara is the friend.
Mike is the friend.
Right?
And Linda is also a friend.
Right.
All this information is basically getting extracted and that is how you are able to see to it right
now.
Uh, let's go ahead and see how many, uh, let's see the post made by the friends of a specific user.
Okay.
So here you will be able to see that I will go ahead and write my match query.
I will say, hey, let's go ahead and create this.
You label user.
Uh, sorry user is my label.
And then I am just going to write you is just a node okay.
Name with respect to John.
Okay.
Now we know that John, first of all we need to retrieve all the friends right.
So I will go ahead and write friend okay.
And then I will create another label F colon user okay.
And I'll say hey let's go ahead with posted.
Right.
So here I'm going to write.
It's just a posted one Okay, I now see there will be a little bit of confusion with respect to the
queries, but you need to practice these things, right?
But this is very simple when compared to MySQL I feel still this is very very comfortable.
Very very much easy.
Yeah.
Then you can go ahead and write p colon post.
Right.
So here what we are doing.
We are basically matching first of all user name who is a friend of the other user like of the same
user with respect to comparing with all the other users, then we are basically considering whether
they have actually posted, right?
So posted is one of the relationship with respect to P is equal to post.
Okay.
And here I will just go ahead and write return f dot name and p dot content is just like inner queries
right.
So now if I just go ahead and execute this, you'll be able to see David has posted San Francisco is
amazing.
Sarah has posted my first post.
Mike has posted beautiful day in Chicago.
Linda love New York and all right, um, this is, uh, how you can basically do this.
But again, here the main aim is not to become pro in Cypher Query language.
This is just for your purpose to show you because later on we will be when we implementing or when we
are creating our generative AI applications with the help of Lang Chain right there, we will be using
all this kind of queries.
Some of the queries will be using in order to insert the data and all.
So guys now let's go ahead and see one more example where we are going to find users who likes a specific
user post.
So here you will be able to see uh with respect to the post, right?
How many people have liked it.
Right.
4 to 1, 4 to 5, 1 to 5 like that.
Right.
So we will try to create another relationship with respect to that.
Right.
So uh, let's go over here and let's see how to probably write this.
So here I'm going to write a match keyword again u colon user okay.
And uh, let's say the user name is John.
So I will just go ahead and write John okay.
And here we will go ahead and write colon posted.
Oops.
Colon posted relation okay.
Um then this will be mapped to p colon post P colon push.
And with respect to this I will also go ahead and specify my likes.
So let's go ahead and see with respect to likes okay.
Because we are comparing inside this p post itself we have this specific likes okay.
Uh see when you give this kind of direction that basically means we are just trying to find out the
relationship we are traversing the relationship between this user and post and inside this post, you
know that, uh, there are something called as likes, right?
So we are just going to use a reverse direction right where we are saying this as likes.
And this is another relationship that we are trying to create.
Okay.
And this likes will be with respect to another user, another user.
Uh uh, I can just consider another user label.
Right.
And then we will go ahead and return L dot name.
Along with this we will also return p dot content.
So this way you will be able to see everything as such.
Let's execute this.
So it says uh no changes, no records.
No records has been found.
Um, let's again see this.
Uh, you can see user with respect to name is equal to John.
Okay.
And whatever John has specifically posted with respect to that particular post and likes has been compared
with L dot user over here.
And then we are returning L dot name.
So right now no match is specifically happening.
Um, so with respect to any John post, uh, I think this is there.
Let's verify the ID itself.
Okay?
So I will just, uh, make sure to copy the same thing.
Let's execute it.
So it says John posted p post.
So, uh, John is over here with respect to John one comma, user id comma user id one, comma user
id two right.
With respect to likes.
So I think there will be no record that is specifically matching.
Okay, let's try one more query over here.
Let's count the number of friends each user has.
And now I'm going to use this specific query I'm writing match u colon user with respect to friend f
colon user.
Again F is another label uh another node written u dot name count f as number of friends.
See all the inbuilt function like how we use in uh, MySQL and all.
Similarly, we are able to do this.
So order by number of friends describing.
So it will just show you that David has five friends.
Sarah has five friends, John has four friends, Mike has four friends, and Linda has four friends.
Right.
Um, these are some of the good examples that I've actually shown you guys.
Uh, but again, it is up to you to go ahead and try it out again here.
The main intention of creating this module is not to become perfectionist in a cypher query languages,
because obviously there are different different scenarios, but you can see just the power of this,
right?
Our main aim of understanding this was that we should be able to work with long chain whenever we are
creating a generative AI application.
So yes, uh, this was it from my side.
I hope you liked this particular video.
I will be see you all in the next video.
Thank you.
Take care.