Lab 1: Tuples

  • Course: COSC 460 Databases Fall 2018
  • Instructor: Michael Hay
  • Assignment: Lab 1: Tuples
  • Due: Mon, Sep 10 at 11:59 PM
  • Starter code: lab1.zip

Introduction

This lab is about representing database tuples as in-memory Java objects. It is also a chance to dust off your Java skills.

Environment setup

  • Register an account at Gradescope using the entry code 9XV4VR. I will be using Gradescope to collect/grade your work.
  • You are encouraged to develop your code using IntelliJ IDEA license. This software is installed on the lab machines and it is free to use, provided you register using your Colgate email address.
  • Download the starter files. Please be sure to save as a .zip file and do not open it (yet).
  • Unzip them:
    unzip lab1.zip
    
  • Create a project in IntelliJ for these files. You can follow these steps.
  • During the first lab, I will walk through how you configure your project, compile your code, run unit tests, and submit your work.

Assignment overview

Like most relational databases, ColgateDB stores data on disk. To manipulate the data, we must bring it into memory, translating bytes into Java objects. Those Java objects in turn must be capable of being translated back into bytes. We will get into this translation in great detail in a coming lab.

For this lab, we focus on the Java representation of data. Database concepts such as schema, tuples, and fields are represented as Java classes.

A Tuple in ColgateDB is quite basic. It consists of a collection of Field objects, one per field in the Tuple. Field is an interface that different data types (e.g.,integer, string) implement. Tuples also have a type (or schema), called a tuple descriptor, represented by a TupleDesc object. This object consists of a collection of TDItem objects, one per field in the tuple. Each TDItem specifies the field Type and the name of the Field.

It is possible to create a Tuple object by simply calling the constructor and setting each field using the setField method. In a later lab, you will parse data on disk to create tuples.

Starter code

You are expected to modify these files:

  • Tuple.java
  • TupleDesc.java

You are expected to read, use, but not modify the remaining files.

Tasks

Task 1 The code that you will write in this course will make heavy use of the object-oriented language features of Java. While I hope that many of the concepts it uses were covered in earlier classes, I realize that (a) your Java knowledge may be rusty and (b) perhaps some of the concepts were not covered in detail. Therefore, in these early labs I will ask you questions to refresh or add to your Java knowledge. Please answer these questions and turn in your answers on paper, at the end of lab or at the start of the following class.

  1. Give a specific example from the code where an interface is implemented by more than one class.
  2. Find two examples of enum types.
  3. When writing the toString method of Tuple your code should be taking advantage of polymorphism. Briefly (1-2 sentences) explain how it does.
  4. There is a method that can be called to create a new IntField object from bytes (well, more precisely, from a Java class that represents an input stream of bytes). What is it?
  5. There is a method that can be called to take an existing StringField object and write it out as bytes. What is it?

Task 2 Implement the methods in TupleDesc. You’ll notice that each method currently throws an UnSupportedOperationException. You can replace this line with your code. After you implement the methods in TupleDesc you should be able to pass the unit tests in TupleDescTest.

Task 3 Implement the methods in Tuple. After you implement the methods in Tuple you should be able to pass the unit tests in TupleTest.

Milestones

If the submitted code (see instructions above) passes the TupleDescTest and TupleTest and you have accurately answered the questions (Task 1), then you have completed the milestone for this lab.

Submission instructions

Upload your files to Gradescope.