Anda di halaman 1dari 4

CIS 550, Database and Information Systems Homework 1 (Due on Sept 29th in class)

Problem 1: ER Diagram Design [15 points]


Design an ER diagram for PennPhoto, a social network photo-sharing site, according to its application requirements. In PennPhoto, there are users who can upload their own photos and can connect to other users to form friends and circles. (A circle, as on Google+, is a group of friends with a name. Circles must have unique names, but dierent circles can have overlapping sets of members.) More specically, your ER diagram must address the following requirements: Each user is identied by a unique ID. Users also have full name, email address, age, and gender stored in the system. Users can connect to other users who are friends. A user also has a set of circles (groups of friends), each with a unique name dened by the user. A circle contains zero or more friends of the owners. A users friend must belong to at least one of the users circles. In PennPhoto, a user is either a professor or a student. A professor has his oce room number, research area and title. A student has his current year and major. In addition, each student has exactly one advisor who is a professor. Users can upload photos to PennPhoto. Each photo is uniquely identied by its ID. Users can can add tags and descriptions for their photos. Users can view photos uploaded by other users. In this case, a user can give a particular rating score to that photo. PennPhoto stores the score information. Some of the above requirements need the concept of class hierarchy, which we have not covered in lecture but which is simple. Roughly speaking, class hierarchy is similar to inheritance in Java. Please refer to Section 2.4.4 and Section 3.5.6 in the textbook. Given the above requirements, design an ER diagram for the system. Please indicate various constraints in your diagram, including but not limited to attributes, keys, weak entities, and participation constraints.

Problem 2: Relational Queries [50 points]


Consider the following partial schema for PennPhoto: Student(studentID: int, name: string, email: string, GPA: double) Professor(staID: int, name: string, researchArea: string) Advises(staID: int, studentID: int, yearsAdvised: int) Friend(userID: int, friendID: int, privacyLevel: int) Photo(userID: int, photoID: int, averageScore: double, tag: string) As stated in the previous question, both students and professors are users. They can friend other users and upload photos. Assume that the friend relationships are symmetric: if A is a friend of B, then B is a friend of A. Please note that this partial schema has nothing to do with the correct ER diagram in the previous question. It is designed for this question only. Express the following queries in (a) the relational algebra and (b) the tuple relational calculus (TRC):

1. Find the photoIDs of photos with tag Philadelphia and with averageScore higher than 3.5. 2. Find the names and emails of students whose advisors have Database as their research area. 3. Find the names of each professor and names of each student, who has at least one photo with averageScore higher than 4.5. 4. Find the studentIDs of each student whose advisor has been advising her for more than three years and is not yet her friend in PennPhoto. 5. Find the studentIDs of students with the highest GPA value.

Problem 3: Explaining Queries [8 points]


Explain in English what the following queries compute. We use the schema dened in Problem 2. 1. {Q | P1 P hoto.(P1 .userID = Q.id P1 .averageScore = Q.rating (P2 P hoto, P2 .averageScore > Q.rating))} 2. u,v,x (z=u (userIDu,f riendIDv (userID,f riendID (F riend)) v=w (userIDw,f riendIDx (userID,f riendID (F riend))) x=y (userIDy,f riendIDz (userID,f riendID (F riend)))))

Problem 4: Short Questions [12 points]


1. Let K be a candidate key for relation R. Is K the primary key? Is K a superkey? 2. Let K be a superkey for relation R. Is K a candidate key? Is K the primary key? 3. We say that a query language is procedural if the user instructs a sequence of operations to be performed on the data to compute the results. We say that a query language is declarative if the user only describes the desired information without explicitly specifying a procedure. Is relational algebra procedural or declarative? What about tuple relational calculus? 4. In relational algebra, assume that we have selection, projection, set union, set dierence, product, and rename as primitive operators. Let R and S be two disjoint relations without common attributes. Let be the join predicate in the form of R.A = S.B. Rewrite R S using only the primitive operators.

Problem 5: Programming Tasks [15 points]


The goal of this problem is to implement and execute a relational expression based on our given code. You will create relations, insert data and implement the relational algebra expression for Problem 2.2. Here are the instructions that get you started: 1. Download our virtual machine and decompress it; it should produce a subdirectory called cis550-vm. If possible, you should use VMWare Player (free on Windows or Linux). If you use Mac or Linux, you can use VirtualBox to import it as well. VMWare Player is available from www.vmware.com and VirtualBox is available from www.virtualbox.org. 2

2. Launch VMWare or VirtualBox and open the cis550-ubuntu/Ubuntu-cis550-vm.vmx le. In VMWare, choose Play virtual machine. When it asks you, answer that you copied the virtual machine. 3. A window should open with a Linux desktop. Log in with cis550 as ID (there should be no password). 4. Double-click on eclipse. You will see a loaded project in the workspace, called cis-550-hw1. 5. Try running the project: click on the triangle next to cis-550-hw1, then src, then edu.upenn.cis.cis550.hw1 to expand it, then right-click on Cis 550 hw1.gwt.xml and choose Run As. Choose Web Application. 6. When you see Cis 550 hw1.gwt.xml in the Development Mode window, enlarge the window or scroll down until you see a line starting with http://127.0.0.1. Double-click on this line. Firefox should launch, and a fter a while you should see a dialog box pop up with CIS 550 HW1 - Query Results. The output should be a relation schema and a single line of a table. 7. You can close Firefox and come back to Eclipse. Click on the red square for Stop in the Development mode pane, to end the Web server. 8. Now you should take a look at the project. Roughly speaking, there are three main parts to a Gogogle Web Toolkit project: code that runs on the server (in ...cis550.hw1.server), code that runs in the browser (in ...cis550.hw1.client), and code that gets passed from server to client and vice versa (in ...cis550.hw1.shared). 9. For the most part, you can just leave the code alone except on the server-side. The server side includes a series of data objects for Relations, Schemas, and the like in ...cis550.hw1.shared); a series of relational algebra operator classes in ...cis550.hw1.server.relalgebra; and a couple of classes for Boolean predicate evaluation in ...cis550.hw1.server.expressions. You will be making use of these to dene tables and query expressions. 10. For the most part, you can focus on the server code that actually creates the table to return to the Web browser this is QueryTablesImpl in ...cis550.hw1.server. Here we have some sample code for you to get started (this is what returns results when you run the current program). The methods createS() and createR() generate two simple relations. (You may easily add more.) In addition, the method getRelation() is the one that creates a Relation expression for the Web server. It currently composes a simple query out of Select, Project, and Join operators. You will need to compose a dierent expression. 11. We have already created the Student relation and inserted 100 tuples for you. You are required to create the relation Professor and the relation Advises. 12. You are required to insert tuples into relations Professor and Advises. You need to create ten professors with staIDs ranging from 10001 to 10010. Each professor has a name which is a string equals to the reverse of his staID. Professors with staID 10001, 10002, and 10003 have Database as their research areas. In addition, for each student with studentID i, create the following tuple in Advises t = {< 10001 + (i mod 10), i, (i mod 4) >}. You are not allowed to modify the Student relation. 13. Modify the getRelation() method so that it corresponds to your relational algebra expression in Problem 2.2. 14. Run your project as web application, as described above. You should see a webpage with the query results. It should match your expectations based on your understanding of the relational algebra and the data. 15. Finally, submit your QueryTablesImpl.java le to us using turnin. You can do this as follows: 3

(a) Open Terminal on the virtual machine desktop. (b) Type cd workspace/cis-550-hw1/src/edu/upenn/cis/cis550/hw1/server. (c) Type scp QueryTablesImpl userid @eniac.seas.upenn.edu where userid is your username on eniac. Log in with your password, and the le should be copied to your home directory. (d) Type ssh userid @eniac.seas.upenn.edu. Then type turnin -ccis550 -phw1 QueryTablesImpl.java. Then type exit to log out. Your grades will be based on correctness, implementation and style. You are not allowed to hard code the results.

Anda mungkin juga menyukai