These questions are designed to help you to prepare for your work on the problems from Part II of Problem Set 3.
You should have already performed the tasks in the Getting started section of the problem set. In particular, you should have read the overview of the code framework.
While answering the questions below, you should consult the following resources:
dbms
code frameworkTable
and Column
classesThe Table
class is a blueprint for objects that represent one of the
tables in the database. The Column
class is a blueprint for objects
that represent one of the columns in a table.
Review:
Table
and Column
classesand answer the following questions:
What does a Table
object’s open()
method do? If you try to
call this method for a table that doesn’t exist, what does the
method return? How should your code deal with that return value?
What Table
method allows you to determine whether a table has a
primary key?
What Table
method allows you to obtain the columns associated
with the table? What method call would you use to obtain the
leftmost column in the table?
What Column
method allows you to determine the data type of the
column? What are its possible return values?
What Column
method allows you to determine the length of the values
that will go in that column? What does it return for VARCHAR
columns?
SQLStatement
class and its subclassesSQLStatement
is an abstract superclass that includes the fields and
methods needed by one or more types of SQL commands. Each type of SQL
command is represented by a different subclass of SQLStatement
, and
the subclasses inherit much of their functionality from
SQLStatement
.
Review:
SQLStatement
classand answer the following questions:
What method allows you to determine the table or tables on which a given SQL command should operate?
What methods allow you to obtain information about the other components of the command (e.g., the columns)?
As part of this assignment, you will implement code that marshalls one row of a table into a key/value pair. You will use the approach covered in lecture in which:
The key portion of the key/value pair holds the value of the primary-key column.
The value portion of the key/value pair begins with a table of offsets that is followed by the values of all columns except the primary key.
You will add code to the provided InsertRow
class to perform the
necessary marshalling. Every InsertRow
object includes fields for
two RowOutput
objects, which allow you to write values into an
underlying buffer (i.e., a byte array).
Review:
InsertRow
and RowOutput
classesand answer the following questions:
Every column will have an offset in the offset table. This includes the primary key–even though it will be stored in the value portion of the key/value pair. What offset should you use for the primary key?
What offset should you use for a NULL
value?
Consider the following sequence of SQL commands:
CREATE TABLE Foo (a INT PRIMARY KEY, b VARCHAR(20)); INSERT INTO Foo VALUES (1, 'hello'); INSERT INTO Foo VALUES (2, NULL);
Describe the key/value pairs that the marshalling scheme would create
for the two rows inserted by the INSERT
commands above. For each row,
what will the key look like and what will the value would look like?
Now consider the following sequence of SQL commands:
CREATE TABLE Bar (a INT, b CHAR(4) PRIMARY KEY, c VARCHAR(15), d REAL); INSERT INTO Bar VALUES (1, '1234', 'hello', 12.5); INSERT INTO Bar VALUES (2, '4567', 'wonderful', NULL);
Describe the key/value pairs that your marshalling scheme would create
for the two rows inserted by these INSERT
commands.
The RowOutput
methods that you will use for writing offsets and
column values are inherited from the DataOutputStream
class, so
you should make sure to review the
API of that class.
Which methods of this class will you use, and for what purpose will you use each method?
You will add code to the provided TableIterator
class to perform the
necessary unmarshalling. To do so, you will make use of RowInput
objects, which allow you to read values from an underlying buffer
(i.e., a byte array).
Review:
TableIterator
and RowInput
classesand answer the following questions:
How will you retrieve a particular column value from a row? In other words, will you go from a key/value pair to the value of a specific column?
What methods from the RowInput
class will you use to read a value
from the buffer that contains the marshalled values?
When unmarshalling, how will you determine the length of a VARCHAR
attribute so that you can read in the appropriate number of bytes?
In InsertStatement.java
, we have given you the beginning of the
execute()
method for INSERT
statements. How does the code that
we have given you make use of objects from the InsertRow
class
and their associated methods?
What remains to be done in the rest of the execute()
method, and
what Berkeley DB methods will you need to use in the code that you
write to complete that method?
In executing a SELECT *
statement, you will make use of the
printAll()
method for table iterators. We have given you this
method in the TableIterator
class, but it invokes a
method that you will need to implement. What method is it?
Last updated on October 19, 2024.