Part I due by 11:59 p.m. on Tuesday, September 17, 2024
Part II due by 11:59 p.m. on Tuesday, October 1, 2024
If you haven’t already done so, you should complete Lab 0 before beginning this assignment.
In your work on this assignment, make sure to abide by the collaboration policies of the course.
If you have questions, please come to office hours, post them on
Piazza, or email cs460-staff@cs.bu.edu
.
Make sure to submit your work on Gradescope, following the procedures found at the end of Part I and Part II.
30 points total
If you haven’t already created a folder named cs460
for your
work in this course, follow these
instructions to do so.
Then create a subfolder called ps1
within your cs460
folder,
and put all of the files for this assignment in that folder.
The problems from Part I will all be completed in a single PDF file. To create it, you should do the following:
Access the template that we have created by clicking on this link and signing into your Google account as needed.
When asked, click on the Make a copy button, which will save a copy of the template file to your Google Drive.
Select File->Rename, and change the name of the file to
ps1_partI
.
Add your work for the problems from Part I to this file.
Once you have completed all of these problems, choose
File->Download->PDF document, and save the PDF file in your
ps1
folder. The resulting PDF file (ps1_partI.pdf
) is the one that
you will submit. See the submission guidelines at the end of Part I.
10 points total
Important
This problem, like most of the problems in this assignment, is individual-only. In general, unless a problem or section of an assignment is explicitly labeled as pair-optional, you should assume that it is individual-only. See our collaboration policies for details about both types of problems.
Before going any further, make sure to follow the instructions above to create your own copy of the Google Drive document that you should use for Part I of the assignment.
The ER diagram shown below is part of the design of a database that
includes information about actors and the parts that they perform in
plays, musicals, movies and TV shows. Each actor has a name and a unique id.
Each part can be uniquely identified by the combination of the id of the
corresponding show and the name of the role, and the database also keeps
track of how many lines of dialogue that each part has (the attribute called
line count
).
In the above version of the ER diagram, there are no constraints on the relationships between actors and parts.
In the ps1_partI
template that we’ve provided on Google Drive (see
above), we’ve included the beginnings of three separate versions of
this ER diagram.
(2 points) Edit the first version of the diagram, adding the connections needed to create an ER diagram whose only constraint is that every actor performs at least one (i.e., 1 or more) part. To do so, you should:
Click on the diagam and then click the Edit link that appears below the diagram.
From the collection of eight connectors that we have provided below the diagram, select the appropriate connectors and use them to connect the two entity sets to the relationship set. Adjust the connectors as needed to make the connections.
Click the Save & Close button.
(2 points) Edit the second version of the diagram, adding the connections needed to create an ER diagram whose only constraint is that every part is performed by exactly one actor.
(2 points) Edit the third version of the diagram, adding the connections needed to create an ER diagram whose only constraints are (1) that every actor performs at most one part, and (2) that every part is performed by at least one actor.
(4 points) Consider your answer to part 1—the ER diagram for the situation in which every actor has at least one part.
Is it possible to convert that diagram into a relational schema that has only two tables/relations, or would three be needed? Explain your answer briefly, and then specify the schema of the two or three tables.
Give the schema of each table in the form relation_name(attr_name1, attr_name2, ...).
Indicate the primary-key attribute(s) of each relation by underlining them.
12 points total
The ER diagram shown below in Figure 2-1 represents a music database – one that stores information about recording artists, recording labels (e.g., EMI or Sony), songs, and albums.
Figure 2-1:
Artists can sing songs and belong to recording labels, labels can produce albums, and songs can appear on albums.
(2 points) At least one of the relationship sets captures a many-to-one relationship. Which one(s)? In your answer, you should specify the direction of each such relationship (e.g., ________ is many-to-one from _________ to ___________).
(4 points) Fill in the table that we have provided to describe, for each relationship set in the diagram, any constraints on the relationships associated with that relationship set. Use words that describe the problem domain (e.g., Each course meets in at most one room...) rather than technical terminology.
(6 points) Transform this diagram into a relational schema by following the procedure discussed in lecture and fill in the table that we have provided. Here are some additional guidelines:
When appropriate, you should combine relations as discussed in lecture.
In the first column of the table, give the schema of each relation in the form relation_name(attr_name1, attr_name2, ...). Feel free to rename attributes as needed to make them easier to understand.
Indicate the primary-key attribute(s) of each relation by underlining them.
If a relation has one or more foreign-key attributes, specify them in the second column of the table, and specify which attribute each foreign key refers to. For example, if you were working with the MajorsIn relation from the university database covered in lecture, its foreign keys would be specified as follows:
8 points total; 2 pts. each part
We will cover the material needed for this problem in lecture on Wednesday, September 11.
Relation R has attributes a, b and c. Relation S has attributes d, a, and b. You are given the following instances of these relations:
Relation R
a |
b |
c |
---|---|---|
1 |
2 |
3 |
3 |
4 |
6 |
5 |
6 |
1 |
Relation S
d |
a |
b |
---|---|---|
3 |
2 |
1 |
5 |
3 |
4 |
6 |
1 |
2 |
For each of the following questions, use the Insert->Table menu option in Google Drive to insert an appropriately sized table for the answer, and then fill in the cells of the table with the correct values.
Make sure that each table includes a header row with appropriate column names.
Once you have completed Part I in Google Drive, choose
File->Download->PDF document, and save the resulting file
(ps1_partI.pdf
) in your ps1
folder.
Login to Gradescope by clicking the link in the left-hand navigation bar. When logging in, make sure that you use the School Credentials option and select Boston University.
Once you are in logged in, click on the box for CS 460. (If
you don’t see that box, email cs460-staff@bu.edu
ASAP and ask to
be added to the course on Gradescope. If the deadline is fast
approaching and you don’t have access to CS 460 on Gradescope,
email your PDF to cs460-staff@cs.bu.edu
before the
deadline.)
Click on the name PS 1: Part I in the list of assignments. You should see a pop-up window labeled Submit Assignment. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
Choose the Submit PDF option, and then click the Select PDF
button and find the ps1_partI.pdf
that you created in step 1.
Then click the Upload PDF button.
You should see a question outline along with thumbnails of the pages from your uploaded PDF. For each question in the outline:
As you do so, click on the magnifying glass icon for each page and doublecheck that the pages that you see contain the work that you want us to grade.
Once you have assigned pages to all of the problems in the question outline, click the Submit button in the lower-right corner of the window. You should see a box saying that your submission was successful.
You can use the Resubmit button at the bottom of the page to resubmit your work as many times as needed before the final deadline.
Important
It is your responsibility to ensure that the correct version of a file is on Gradescope before the final deadline. We will not accept any file after the submission window for a given assignment has closed, so please check your submission carefully using the steps outlined above.
If you are unable to access Gradescope and there is enough
time to do so, wait an hour or two and then try again. If you
are unable to submit and it is close to the deadline, email
your homework before the deadline to
cs460-staff@cs.bu.edu
70 points total
The problem domain for this assignment is movie trivia.
Before you get started, you should carefully read over the full description of the database. Please do so now!
Go to sqlitebrowser.org/dl.
Find the appropriate download link for your machine/operating system, and download and install that version of DB Browser for SQLite.
If you have a Mac, you should download the appropriate Mac .dmg file. Double-click on the file, which will open up a window. Then drag the application’s icon to your Applications folder.
If you have a Windows machine, you should download the Standard installer for 64-bit Windows (which is an .msi file). Double-click on the file to run the installer. You should be able to use all of the default options.
If you are unable to install DB Browser on your own machine, you can use it on the virtual desktop.
Download the following files into your ps1
folder:
If your browser doesn’t allow you to specify where the file should be saved, try right-clicking on the link above and choosing Save as... or Save link as..., which should produce a dialog box that allows you to choose the correct folder for the file.
Launch the program.
Click the Open Database button, and find and open the movie.sqlite
database file that you downloaded above.
To explore the schema of the database, click on the Database Structure tab, and then click on the arrows to the left of the table names.
To explore the contents of the tables, click on the Browse Data tab, and then choose the appropriate table from the drop-down menu.
Use the Execute SQL tab to perform queries on the database. Enter your SQL command in the space provided, and press F5 or Ctrl-R to run it. (There is also a small button that you can click; it has a triangular shape that looks like the Play button of a music player.)
ps1_queries.py
is a Python file, so you could use a Python IDE
to edit it, but a regular text editor like TextEdit or Notepad++
would also be fine. However, if you use a text editor, you must
ensure that you save it as a plain-text
file.
Construct the SQL commands needed to solve the problems given below. Test each SQL command in DB Browser for SQLite to make sure that it works.
Once you have finalized the SQL command for a given problem, copy
the command into your ps1_queries.py
file, putting it between
the triple quotes provided for that problem’s variable. We have
included a sample query to show you what the format of your
answers should look like.
Unless otherwise stated, each of the problems must be solved by means of a single query (i.e., each query should have a single semi-colon). Use nested subqueries as needed.
Your queries should not use a LIMIT
clause.
Your queries should only use the keyword DISTINCT
if it is
necessary to obtain the correct results. Similarly, you should
only use an outer join when it is strictly necessary.
Make sure that the results produced by your queries contain exact answers to the problems. We should not have to infer the answer from the results. For example, if we ask you how many movies meet a given criterion, we want a number, not a list of the movies. In addition, your results should not include any extraneous information.
5 points
Make sure to read the important guidelines above before you get started!
Da’Vine Joy Randolph won an Oscar this year for her work in The Holdovers. Write a query to determine the names and dates of birth of all people in the database whose name includes “Joy” somewhere in their name – it doesn’t matter where. Use pattern-matching with an appropriate pattern. The result of your query should be tuples of the form (name, date of birth).
5 points
The Holdovers is set in the Boston area. Another movie from the past decade that is also set here is Spotlight. Write a single query that finds the runtimes of those two movies. The result of the query should be two tuples of the form (name, runtime).
Hint: If your initial query does not produce any results, you may want to reconsider the logical operator (AND, OR, NOT) that you are using in your WHERE clause.
5 points
Robert Downey Jr. won a Best Supporting Actor Oscar this year for his work in Oppenheimer. Write a query to find the names of all movies in our database in which he has acted. Note: Downey’s name does not include a comma before the “Jr.”.
5 points
Casey Affleck was born in Massachusetts, and he won a Best Actor Oscar for his performance in the movie Manchester by the Sea. Find the number of Oscar winners in our database who were born in Massachusetts. You may assume that all such people have a place of birth that ends with “Massachusetts, USA”. The result of your query should be a single number.
5 points
Do movies with certain ratings tend to be more profitable? For each movie rating that occurs in the 200 top-grossing movies (i.e., movies with an earnings rank of less than or equal to 200), find the number of top-grossing movies with that rating, and the earnings rank of the most profitable movie with that rating. The result of the query should be tuples of the form (rating, number of top grossers, earnings rank of most profitable movie).
Hint: Don’t forget that the smaller a movie’s earnings rank, the more profitable it is. For example, the movie that has made the most money has an earnings rank of 1.
5 points
Write a query to find the oldest animated movie(s) in the database, making use of the fact that all animated movies have the letter N somewhere in the value of their genre attribute. For example, The Lion King has a genre value of ‘VNCFL’, with the N indicating that it is animated. If multiple animated movies are tied for being oldest, they should all be included. The result of the query should be one or more tuples of the form (movie name, year).
Important
For full credit, your answer must use a subquery. Although SQLite provides a way to solve this problem without a subquery, that technique is not standard SQL, and thus it should not be used as part of your answer.
5 points
Find the names of all people that have won at least 3 of the Oscars in the database. The result of the query should be tuples of the form (name, number of Oscars). Sort the results in descending order by the number of Oscars won. If multiple people are tied for number of Oscars, sort them in ascending order by name.
Note: For the purposes of this query, you should assume that person names are unique.
5 points
Write a query that summarizes the number of Oscars won by movies in the database that were released in 2023. The result of the query should be tuples of the form (movie name, number of Oscars). If a movie has won no awards, it should still appear in the table with a value of 0 for the number of Oscars. You may assume that all movies from 2023 have a unique name.
5 points
Write a query to determine the number of actors in the database who have not appeared in any of the movies in the database from the last 10 years (i.e., 2014 or later). The result of the query should be a single number.
5 points
Write a query that determines, for each type of Oscar included in the database, the average runtime of movies associated with that Oscar. The result of the query should be six tuples of the form (oscar type, average runtime).
5 points
Write a single query to find both the oldest and youngest persons in the database. If multiple people are tied for being either youngest or oldest, they should all be included. The result of the query should be tuples of the form (name, date of birth).
5 points
Timothee Chalamet starred in two of the most successful movies of the
past year: Wonka and Dune: Part Two. He is in our database, but
his dob and pob values are currently NULL
. Write a SQL command to
add the facts that he was born on December 27, 1995 (i.e.,
'1995-12-27'
) in New York City (i.e., 'New York, New York,
USA'
). This is the only question from this section that does not
call for a SELECT command. You will need to figure out the correct
type of SQL command to use.
Note: You may assume that there is only one person named Timothee Chalamet in the database.
10 points total; pair-optional
This is the only problem of the assignment that you may complete with a partner. See the rules for working with a partner on pair-optional problems for details about how this type of collaboration must be structured.
Getting started
Your work on this problem should go in a separate PDF file called
ps1_problem16.pdf
. To create it, you should:
Access the template that we have created by clicking on this link and signing into your Google account as needed.
When asked, click on the Make a copy button, which will save a copy of the template file to your Google Drive.
Select File->Rename, and change the name of the file to
ps1_problem16
.
Add your work for this problem to this file.
When you are finished, choose File->Download->PDF document, and
save the PDF file on your machine. The resulting PDF file
(ps1_problem16.pdf
) should be submitted following the
instructions below.
The problems
Write a relational-algebra query for each of the following
problems. Above, you will write a SQL query for these problems;
here you should solve them using relational algebra instead.
See below for some additional guidelines.
(3 points) problem 6 (Movies starring Robert Downey Jr.).
Make sure to follow the guidelines below.
(4 points) problem 11 (2023 movies and Oscars), but instead of
producing counts, your query should produce tuples of the form
(movie name, award type). If a given movie won multiple awards, it
should have one tuple for each award; if it did not win any of the
awards in the database, it should have a single tuple in which the
second value of the tuple is NULL
.
(3 points) problem 12 (Haven’t seen them in a decade), but
instead of producing a count, your query should produce the ids
of the actors. Hint: Take advantage of the set difference
operator (-
).
Additional guidelines
To form your queries, you should use the templates that we have
provided for each of the relational-algebra operators at the top
of ps1_problem16
. Copy the appropriate template(s), and replace
the placeholders with the appropriate expressions, attributes
and/or predicates to form each query. We have provided an example
in ps1_queries
of using two of the templates to form a single
query.
For a given problem, you are allowed to perform a sequence of two
or more queries in which the results of a given query are assigned
to a variable using the assignment operator (<–), and then that
variable is used in a subsequent query. We have provided an
example of this in ps1_queries
, and we recommend that you do
this whenever a given query would otherwise become too long or
difficult to read.
Note that using a sequence of queries is not allowed in your SQL answers, but it is allowed here.
You will make submissions to two separate assignments on Gradescope. The steps needed for the two submissions are different, so please make sure to follow carefully the procedures outlined below.
PS 1: Problems 4-15
Submit your ps1_queries.py
file using these steps:
Click on the name of the assignment in the list of assignments. You should see a pop-up window with a box labeled DRAG & DROP. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
Add your file to the box labeled DRAG & DROP. You can either drag and drop the file from its folder into the box, or you can click on the box itself and browse for the file.
Click the Upload button.
You should see a box saying that your submission was successful.
Click the (x)
button to close that box.
The Autograder will perform some tests on your file. Once it is done, check the results to ensure that the tests were passed. If one or more of the tests did not pass, the name of that test will be in red, and there should be a message describing the failure. Based on those messages, make any necessary changes. Feel free to ask a staff member for help.
Notes:
You will not see a complete Autograder score when you submit. That is because additional tests for at least some of the problems will be run later, after the final deadline for the submission has passed. For such problems, it is important to realize that passing all of the initial tests does not necessarily mean that you will ultimately get full credit on the problem. You should always run your own tests to convince yourself that the logic of your solutions is correct.
If you get a message saying that the Autograder failed to
execute correctly, it is likely the case that one of your
queries is taking too long to execute. Make sure that you have
checked each query in DB Browser to ensure that it executes
correctly, and that you have copied the correct query into
your ps1_queries.py
file. If you have a query that is
causing DB Browser to hang, you should either remove that
query from your file before submitting it, or you should
comment it out by putting a #
symbol at the beginning of
each of line of the query.
If needed, use the Resubmit button at the bottom of the page to resubmit your work.
Near the top of the page, click on the box labeled Code. Then click on the name of your file to view its contents. Check to make sure that it contains the queries that you want us to grade.
PS 1: Problem 16
IMPORTANT: If you chose to work on problem 16 with a partner, only one person from the pair should submit the file, and that person should add the other person as a group member following step 6 below.
Submit your ps1_problem16.pdf
file using these steps:
If you still need to create a PDF file, open your file
on Google Drive, choose File->Download->PDF document, and
save the PDF file in your ps1
folder.
Click on the name of the assignment in the list of assignments on Gradescope. You should see a pop-up window labeled Submit Assignment. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
Choose the Submit PDF option, and then click the Select PDF button and find the PDF file that you created. Then click the Upload PDF button.
You should see a question outline along with thumbnails of the pages from your uploaded PDF. For each question in the outline:
As you do so, click on the magnifying glass icon for each page and doublecheck that the pages that you see contain the work that you want us to grade.
Once you have assigned pages to all of the questions in the question outline, click the Submit button in the lower-right corner of the window. You should see a box saying that your submission was successful.
If you worked with a partner and you are the one who is submitting the file:
Click on the Group Members link that appears at the bottom of the page.
In the pop-up box that appears, click on the Add Student drop-down menu.
Type your partner’s name or choose it from the drop-down menu.
Click the Add button.
Check to ensure that your partner’s name now appears along with your name under the Group heading in the upper-right corner of the page.
Important
It is your responsibility to ensure that the correct version of every file is on Gradescope before the final deadline. We will not accept any file after the submission window for a given assignment has closed, so please check your submissions carefully using the steps outlined above.
If you are unable to access Gradescope and there is enough
time to do so, wait an hour or two and then try again. If you
are unable to submit and it is close to the deadline, email
your homework before the deadline to
cs460-staff@cs.bu.edu
Last updated on September 24, 2024.