logo Use SA10RAM to get 10%* Discount.
Order Now logo

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

expert
Kate DuggannMathematics
(5/5)

951 Answers

Hire Me
expert
Aunty DonnaEngineering
(5/5)

681 Answers

Hire Me
expert
Aditi ToshniwalMarketing
(/5)

920 Answers

Hire Me
expert
Henry SimmonsEnglish
(5/5)

820 Answers

Hire Me
Python Programming

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.

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

294 Experts Online