Hi everyone.
Welcome back.
In this lecture we will go and learn about how to combine multiple gatherers together and execute a
business functionality.
So here is a use case.
The first step is we would like to filter the movies that have a rating greater than eight, and then
group the filtered results with a window size of two, and have this logic as part of gatherer one.
So that is the first part of the logic.
The next thing is we need to calculate the average of each window using the scan operation.
So we are going to combine these two gatherers.
And the concept of combining these two gatherers is called a composite gatherer.
Let's go back to the code and start coding this one.
So there you go I'm back in the code.
So what I'm going to do is I'm going to comment out these two things.
And I have this demonstrate composite gatherers.
So if we go here so this is what the code is.
It is an empty function.
So now what I'm going to leverage is that I'm going to leverage the a coding assistant since we have
already explored the windows fixed and scan operation using stream gatherers, I'm going to use the
prompt to make the changes for me.
So I'm going to go back to the Stream Gatherers demo and you will have something called The Composite
Gatherers.
Let's go to that one.
And in here we can see that it says like create a method demonstrating how to combine multiple gatherer
operations in sequence.
So this is the input for that function.
And we are printing the section header.
And the first gatherer.
As you can see this is our code.
This is a filter.
High rated movies and group the filtered movies into fixed windows of size two.
So that's what we are saying over here.
So filter the movie and then group them by a windows of two.
And then apply scanning to calculate average duration.
Right.
So we know this scanning operator.
This produces the intermediate results after each accumulation of results.
And then display the average duration in this format, which is high rated movie window, average duration,
which is this and this minutes.
So what we'll do is we'll copy this prompt, and then we are going to be creating a new chat and then
ask you to create it for me.
And the model that I'm using is called sonnet 4.5 and agent mode.
If you don't have this model, use the other models.
You are welcome to try it out, but different module produces different results.
So I'm expecting the code changes to be done over here.
Now let's go ahead and press enter.
So it is first reading the movie Java.
And then it's going to be implementing the demonstrate composite gatherers.
So basically it is able to identify the function where it's going to make the change.
And it's going to edit the changes for us.
There you go.
It made the change for me.
So here we have a gather on the top which takes care of actually applying the filtered movies which
are of greater than 8.0 and grouped them into window size of two.
And then we have the scan operation, where once the results are grouped, it's going to be computing
the average duration and then printing the results in the console.
So this is the beauty of using gatherers and combining them in your whole code logic.
So if we take a look at the code.
So this is how the code looks like.
And we created this whole code logic, writing almost 10 to 15 lines of code by just prompting, okay,
so now what I'm going to do, I'm going to be running this code.
So it has the ability to run the code also for you.
Click on continue over here.
Now what this is going to do.
This is going to be running the program for you.
As you can see, you don't have to go and click on the run button.
You can actually run the program also directly from the console.
But I believe this needs to be changed to Java 25.
Let me see what is a Java version that I'm using?
Okay, I'm using Java 25.
For some reason it gave me an error.
So what I'm going to do, I'm going to ask you to look into this error.
So I'm going to pass this error back.
Or it might be already trying to do some other activity here.
So if you go here so let's compile and run the code directly.
Let's give it a try one more time.
If it doesn't work then we will go ahead and manually execute the program.
I'm going to continue okay.
So now it compile the program.
The next step is to run the compiled stream demo class.
To test the Demonstrate Composite Gatherers method click on continue.
So now you can see that right.
We were able to run the actual code directly over here.
So there you go.
This is a composite gatherers chaining operation.
And it gave you that high rated movie average duration.
That's over here.
So this is again you have the ability to create the program, execute the program and test the result
directly from our AI coding assistant.
So it said that perfect the implementation is working correctly.
Let me verify the output to ensure everything meets the requirement.
So let's continue this.
So it's going to actually look into the console and then validate the result.
So now it actually looked into the console, gathered the result, and then finally the agent also showed
up over here.
That means that this is the output that's been shown in the console.
And this implementation successfully demonstrate how multiple gather operations can be chained together
to create a sophisticated data processing pipelines.
So this is a lecture where we completely leveraged the AI coding assistant to write the logic for us.
All we did was we started with the prompt, and then we were able to execute the prompt.
And also we were able to successfully implement the logic, validate the logic by running the code through
the AI assistant.
So this is a power of this AI coding assistant where you can actually instruct and watch the code changes
that's been made.
If the code looks good, then you approve and ship the feature as a deliverable in your application.
Well, this marks the end of this lecture.
Thank you for watching.