logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Python program to perform query using Chinook Database and Download the database file Chinook_Python.py

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

CPSC 531 - Advanced Databases - Fall 2019

RDBMS and Database

The database is Luis Rocha’s Chinook Database, modified for use with Python.

Platforms

You may use any platform to develop and test your code, but note that per the Syllabus the test environment for projects in this course is a Tuffix 2019 Edition r2 Virtual Machine with Python 3.6.8. It is your team’s responsibility to ensure that your code runs on this platform.

Loading the Database

Download the database file Chinook_Python.py and place it in directory where you will develop your Python code. The database can be loaded with the following command:

from Chinook_Python import *

You will find variables named Artist, Album, Customer, etc. containing sets of namedtuple objects.

Note: an earlier version of Chinook_Python.py did not export the InvoiceLine relation by default. You can import it explicitly (e.g., from Chinoook_Python import InvoiceLine), or use the link above to download an updated version.

Relational Operators

Implement the following functions in Python:

  • select(relation, predicate)
  • project(relation, columns)
  • rename(relation, new_columns=None, new_relation=None)
  • cross(relation1, relation2)
  • theta_join(relation1, relation2, predicate)

The predicate for select() should be a function that takes a single namedtuple as an argument and returns True or False.

The predicate for theta_join() should take two namedtuples and return a bool.

The new_columns and new_relation parameters to rename() are optional. if neither argument is provided, return the original relation.

Extra Credit

Implement natural_join(relation1, relation2).

Queries

The file queries.py contains four variations of the first query from Project 1:

  1. Combining 𝜎 and ⨯ to implement 𝜃-join
  2. Performing 𝜎 after 𝜃-join
  3. Performing 𝜎 before 𝜃-join
  4. Natural join (Run this If you did the extra credit.)

All of the queries above should return the following set:

{Result(Title='Blood Sugar Sex Magik'),

 Result(Title='By The Way'),

 Result(Title='Californication')}

When the relational operators are implemented and the queries above work correctly, write code to run the last query from Project 1.

Performance Measurement

As a rough approximation of the processing required for each query, instrument your functions to measure the cardinality of the result set for each relational operator. When a query completes, print the total number of tuples returned during processing.

  1. What do you observe about the queries listed above?
  2. Can you rewrite the last query from Project 1 to minimize the number of tuples processed?

Python Tips

If you are new to Python, see A Whirlwind Tour of Python.

You may find the following useful:

  • Lambda expressions can be used to write predicates succinctly.
  • Named tuples include a ._fields attribute.
  • Use next(iter(relation)) to retrieve the first named tuple in a relation.
  • Use tuple.attribute to access fields of named tuples directly.
  • Use getattr(tuple, attribute_name) to access a field of a named tuple given the name of the attribute as a string.
  • A list of arguments can be unpacked for a function call requiring separate positional arguments.
  • Set comprehensions can use a syntax similar to list comprehensions to construct sets concisely without loops.
(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

627 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

523 Answers

Hire Me
expert
Husnain SaeedComputer science

566 Answers

Hire Me
expert
Atharva PatilComputer science

804 Answers

Hire Me