Hi everyone.
Welcome back.
In this lecture.
Let's understand the windows sliding gatherer in detail.
This gatherer is quite interesting because it helps us create overlapping groups or sliding windows
over the elements of the stream.
When we say overlapping windows, it means that each new window shares one or more elements with a previous
one.
So unlike windows fixed, which forms independent, non-overlapping batches, windows slide move the
window forward by one element at a time, keeping part of the previous window.
This allows us to continuously observe how the data evolves element by element.
For example, in this case we have a stream of four elements A, B, C, and d.
If we apply windows sliding to, this will produce the following windows AB, BC and CD.
You can see that from the first and second window, you have a B element that is being shared in both
the windows.
This is called overlapping windows.
This concept is achieved using the windows sliding gatherer, so this behavior is extremely useful when
you want to analyze sequences or patterns where context matters, not just individual elements.
For instance, if you're analyzing movie ratings over time, you can take every 2 or 3 consecutive movies
and calculate their average rating.
This gives you a sense of how ratings are changed gradually.
Instead of just looking at the movie, which is one movie at a time.
In summary, Windows Sliding helps us process data continuously with overlapping groups.
This is perfect for real time analytics, running averages or sequential comparisons in streams.
Let's go back to the code and explore this particular functionality.
So I'm back in the Stream Gatherer demo class.
So in this case I'm going to comment out the windows sliding function call so that we can actually look
at the data of windows sliding in detail.
So let's go back to this one.
It's going to be the same concept.
So in this case we are going to be doing movie stream dot stream.
And then we are going to be limiting to only five movies because we have 12 movies in the collection.
So using five will help you look at the data in a much clearer way.
So in this case I'm going to be doing the dot gather.
So I'm going to be calling the gatherers dot windows sliding okay.
And then I'm going to be giving the sliding window as two value so that you know what movies are going
to be part of each and every window.
So and then I'm going to be printing this value.
So I'm going to change this one to be a sliding window.
So in this case we have a stream of movie.
As you can see when it when this one happens you have a stream list of movies of size two.
Let me rename this one to be Sliding Window.
There you go.
And then we are going to be accessing those two movies and then printing them over here.
Okay.
Now let's execute this function and then look at the result to get a clearer picture of what this sliding
window creates.
Go to the top and then execute this function.
There you go.
So now you can see that the sliding window is created.
As you can see, we have limited the movie to five right.
Let's go back to the code.
So in here we are limited that to five.
So basically how many windows it created.
1234.
Right.
And if you take a look at it this is the first window which is The Godfather.
And then Shawshank Redemption.
In the second window you see that same movie that is being present.
The last movie in the previous window is a first element in the next window.
And then we have the pulp function, and the same is being repeated.
The last movie in the previous window is the first element in the next window.
So in this case let's go ahead and remove this limit.
Okay.
And then I'm going to change this to four.
Let's see what happens.
Let's rerun the program again.
Okay.
So there you go.
We have this whole sliding window created.
So in this case so you have the first window with four elements.
In the next window you can see that the top.
The last three elements are the first three elements in the next window, so it's always the first element
in the first window is not included.
The rest of the elements are going to be part of this one.
The same concept is repeated.
The last three in the top window is the first three in the next window.
So this concept is called window sliding, where we create overlapping windows of specific size.
And each window shares n elements with a window.
So that means it's going to be sharing the first elements or first windows N elements to the next window.
So in this case if you have to think about it.
So here we have four elements right.
And the next window is going to be holding on n minus one which is four minus one.
In this case the three elements.
That's what we see over here.
So this is all about the window sliding gatherer.
If you have a use case where you have to do a trend analysis, window sliding is a very handy operator
to use for that use case.
This marks the end of this lecture.
Thank you for watching.