WEBVTT

00:01.320 --> 00:02.160
Instructor: All right, you've listened to me

00:02.160 --> 00:03.840
talk about datasets long enough I think,

00:03.840 --> 00:05.220
it's time to get your hands dirty

00:05.220 --> 00:06.540
and try to use them yourselves.

00:06.540 --> 00:10.290
So let me give you your first challenge using datasets.

00:10.290 --> 00:13.260
Remember the Friends by Age Example that we did with RDD's?

00:13.260 --> 00:16.110
Well, I wanted to go back there and do it again

00:16.110 --> 00:18.930
but this time using datasets instead of RDD's.

00:18.930 --> 00:22.290
So just to review what that example's all about,

00:22.290 --> 00:25.320
we've provided a fakefriends Comma Separated Value file

00:25.320 --> 00:27.660
that contains data in this format.

00:27.660 --> 00:30.930
It's basically a user id, their name, their age,

00:30.930 --> 00:32.700
and the number of friends they have.

00:32.700 --> 00:35.580
And your task is to give me the average number

00:35.580 --> 00:37.260
of friends by age.

00:37.260 --> 00:38.400
So I wanna know, on average,

00:38.400 --> 00:40.170
how many friends does a 33 year old have?

00:40.170 --> 00:41.850
How many friends does a 55 year old have,

00:41.850 --> 00:42.870
and so on and so forth,

00:42.870 --> 00:47.340
for every age represented in my fakefriends.csv file.

00:47.340 --> 00:49.590
And it's called fakefriends because it's all fake data.

00:49.590 --> 00:51.060
It was all generated randomly.

00:51.060 --> 00:52.638
So they're not like,

00:52.638 --> 00:55.606
I'm not making a value judgment on your friends here.

00:55.606 --> 00:58.350
Anyway, some hints on how to get through this.

00:58.350 --> 01:00.570
So there is a fakefriends.csv file

01:00.570 --> 01:03.660
in your course materials that contains a header row.

01:03.660 --> 01:05.400
And as you've seen in our previous examples,

01:05.400 --> 01:07.200
using datasets that's going to be important

01:07.200 --> 01:11.610
for allowing Scala and Spark to infer the correct schema

01:11.610 --> 01:12.967
for that data.

01:12.967 --> 01:16.320
And a few commands here that might come in handy.

01:16.320 --> 01:18.300
Remember we can use these select command

01:18.300 --> 01:20.820
to extract given columns from a dataset

01:20.820 --> 01:23.430
and get a new one that just has the data we need.

01:23.430 --> 01:25.320
You might recall that when we did this with RDD's,

01:25.320 --> 01:27.870
we had a map function that actually did that for us.

01:27.870 --> 01:31.050
So this is gonna be a lot simpler using a select statement

01:31.050 --> 01:34.110
and you will need some other dataset functions,

01:34.110 --> 01:35.970
groupBy we've looked at before that will basically

01:35.970 --> 01:38.070
aggregate things by unique ages,

01:38.070 --> 01:40.050
kinda like a reduce operation.

01:40.050 --> 01:42.420
Show will show the final results and get them back.

01:42.420 --> 01:45.210
And what we didn't talk about was AVG for average.

01:45.210 --> 01:48.450
So after you've grouped things by ages,

01:48.450 --> 01:51.000
you will then want to get the average by age.

01:51.000 --> 01:54.240
So obviously the column names I put in here

01:54.240 --> 01:55.530
are for illustrative purposes.

01:55.530 --> 01:57.000
It's up to you to put the right ones in there

01:57.000 --> 01:59.070
and put them in the right order and whatnot.

01:59.070 --> 02:01.650
But those are the pieces you should need to do this.

02:01.650 --> 02:02.790
And you might wanna refer back

02:02.790 --> 02:06.120
to the DataFramesDataset.scala file for inspiration.

02:06.120 --> 02:07.560
And you don't have to do it this way either.

02:07.560 --> 02:09.150
You could just use a straight up SQL command

02:09.150 --> 02:09.990
if you want to as well.

02:09.990 --> 02:13.440
So it's kind of up to you what direction you want to go in.

02:13.440 --> 02:14.940
So go and give that a try,

02:14.940 --> 02:16.680
and when we come back to the next lecture,

02:16.680 --> 02:18.480
I'll show you my solution to it

02:18.480 --> 02:20.550
and also some ways of expanding on it

02:20.550 --> 02:22.770
to do some more interesting things with that data as well.

02:22.770 --> 02:25.590
So go give it a shot and see if you can get that working

02:25.590 --> 02:27.930
and then come back and I'll show you my solution.

02:27.930 --> 02:28.980
Don't peek at the solution.

02:28.980 --> 02:30.540
It is in there in your course materials.

02:30.540 --> 02:33.540
So make sure you create a new file that has some unique name

02:33.540 --> 02:35.940
and resist the temptation to peek guys

02:35.940 --> 02:38.090
and come back and we'll go over the answer.
