 Hello, welcome to SSUnitex to seal this site and this is container son of PySpark tutorial. So in this video we are going to see what is the difference between stuck type and map type. So in the earlier of this video series we have already seen about the stuck data type and map type. If you haven't watched those videos then I would strongly recommend to watch those videos before going forward. So first we will see about the stuck type and then we will see about the map type. Then what is the difference between these two? So the main difference between stuck type and map type is that stuck type we define all possible key in the schema and each value can have different values and in the other hand for the map type we define the type of key and value. This is the pair we have to define here. So when to use stuck and when to use map. So let's assume we are having the data set which is having two columns like address ID and address. Under the address we have like fixed columns like it will be having address 1, it will be having city and it will be having country. So we are having something kind of fixed so on those scenarios we can use the stuck type. But in the other hand you can see we are having an employee data set and on that data set we can see we have employee ID and the accessories that is issued for that particular employee. So here you could see we are having laptop, we are having mobile for employee ID 1 and we are having headphone but for employee 2 only laptop and mobile has been issued. So on those scenarios we cannot specify the stuck type here because it is going to vary person to person. So on those scenarios we could use the map type. So in the map type we will be going to specify the key and value data types. So here the key value data type will be string only because laptop is string and apple is string. So if you are having these two type of data sets only then you can use stuck type and map type and this is the only difference between these two. Let me quickly go inside the browser and we will try to see in practical. So here as we have already seen in the slide we are going to create one of the data frame and it could be having two columns with address ID and address. Under address it will be having additional three columns with address 1, city and country. So let me try to create this data frame and we will see the output of this. So it will be going to have two columns. First is address ID and second will be address. So here under the address we can see it is having address 1, city and noida. So similarly how we can get three columns from this. So how we can parse this json. So we can simply use like df data frame that we have created df st dot. Then we can go with the select. Let me select all the column first. In the second column we can specify df dot address then dot which column we want under the address we want to address one column. So let me put this into another data frame and let me use display of this data frame one. Let me execute and we will see the output of this. Okay it is saying it is not defined because this is not df this is df st for the stack type. Let me execute it again. So now we can see it is having one additional column here and it is fetching address one. We can also provide the alias name like dot alias and here we can specify like address one. So this is we can provide the alias name. On the same hand if we want city then instead of using this address one we can go with the city. So it will be fetching the city there. Similarly if you want country then we can specify country. So it will be going to fetch country there. Now you can see. So by using this we can simply parse this json. Let me quickly go for the map type. So as I told you we have to specify the map type because the items are not static. So the key pair could be going to increase or decrease person to person. So on those scenario it will be having two columns first will be employee ID and second will be item. And here under the item we are going to specify the map type of key and value pair. So here this will be map type and the key data type will be string and the value data type will be again string. So this is we could specify. Let me try to execute this and we will see the output of this. So now we can see it is having the output like this. So on those scenarios how we can parse this. So for parsing any map type column we could use the explode function. So df empty is the data frame dot let me select and here let me specify as tick. And so second we have to explore this items column. So before that we have to import the export function. So we can go with pyspark dot SQL dot functions then import and here we can go with explode. Now here we could use the explode function and which column we want to explore. So we want to explore this items column. So we can simply specify items here. Let me execute it. So let me use the display of this. So we'll see the output of this explode function. So it will be going to parse. Okay. So here let me remove this bracket and let me add the bracket here. Execute it again. So as you could see this has been passed. Now it is having two columns. One is the key and second is the value and ID one is having total three items. So it is repeated three times and ID two is having two items. So it is repeated two times. So I hope guys you have understood how we can use the stuck type and map type and what is the difference between those two and on which scenario we should be using the stuck type and on which scenario we could be using map type. So thank you so much for watching this video. If you like this video please subscribe our channel to get many more videos. See you in the next video.