Filter a CSV file and re-arrange it by category

The CSV file below has 4 columns: idSale (id), Movie (movie name), Genre and Director:

idSale,Movie,Genre,Director

100,Inception,Sci-Fi,Christopher Nolan

101,Man of Steel,Action,Steven Spielberg

102,Interstellar,Sci-Fi,Christopher Nolan

103,The Matrix,Sci-Fi,Steven Spielberg

104,Memento,Thriller,Christopher Nolan

105,Gladiator,Action,Steven Spielberg

106,Dunkirk,War,Christopher Nolan

107,The Godfather,Drama,Steven Spielberg

108,Tenet,Sci-Fi,Christopher Nolan

109,Pulp Fiction,Drama,Steven Spielberg

110,Insomnia,Thriller,Christopher Nolan

111,Fight Club,Drama,Steven Spielberg

112,Following,Thriller,Christopher Nolan

113,The Shawshank Redemption,Drama,Steven Spielberg

114,The Prestige,Drama,Christopher Nolan

115,Forrest Gump,Drama,Steven Spielberg

116,Batman Begins,Action,Christopher Nolan

117,The Lion King,Animation,Steven Spielberg

118,The Dark Knight,Action,Christopher Nolan

119,The Avengers,Action,Steven Spielberg

Use Java to implement a task: filter the file using Director as the argument, group it by Genre, and print data in the order of genre and then movie names. For example, when argument is set as Christopher Nolan, we have the following result:

Genre: Action

Batman Begins

The Dark Knight

Genre: Drama

The Prestige

Genre: Sci-Fi

Inception

Interstellar

Tenet

Genre: Thriller

Memento

Insomnia

Following

Genre: War

Dunkirk

Here is SPL script:


A

B

1

=T("movies.csv").select(Director==arg_director)


2

for A1.group(Genre)

=output("Genre:",A2.Genre)

3


>A2.run(output(Movie))

A1: Open the CSV file and filter it by director.

A2: Group the file by Genre and loop to compute one group each time.

Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.

Source: https://stackoverflow.com/questions/76789813/java-search-csvfile-using-arrays