CS3223: Database Systems Implementation

Project Assignment 1: Non-equality predicates

 

SimpleDB implements only a tiny subset of standard SQL. See Appendix I for the grammar of this subset wrt querying. In particular, it only supports equality predicates. In other words, it cannot support the following predicates in the where clause:

·        SId >= 10

·        Sname != “joe”

·        SId < StudentId (join between tables Student and Enrol)

·        GradYear != YearOffered (join between Student and Section)

In this assignment, you will extend SimpleDB to support such non-equality predicates.  You should consider the following inequalities:

·        Less than: <

·        Less than or equal: <=

·        Greater than: >

·        Greater than or equal: >=

·        Not equal: != or <>

You will need to change the parser as well as how such inequality operators should be processed. [Hint: If you look at the grammar, the main part that needs to be changed is related to Term. The code can be found in subdirectory parse (Lexer.java, Parser.java, PredParser.java) and subdirectory query (Term.java). You should test that your extended SimpleDB works for both int and String.

Submit a report that describes the changes made to support non-equality predicates. Think of this as a documentation/manual of the steps (at a high-level without details) to be followed to implement non-equality predicates in SimpleDB.   It is sufficient to create a table as follows:

File to change

Changes (The statements below are just indicative of how you can describe your changes. It does not mean that you should do exactly as described)

simpledb/parse/Lexer.java

Added a new routine eatOpr() to “eat” the operators <, <=, … (no need to describe the details of what eatOpr() does)

Call eatOpr() from Term()

Simpledb/parse/Parser.java

Added routines  ….

Call from …

….

….

 

Appendix I: The “query” grammar for the SimpleDB subset of SQL

This grammar is extracted from Edward’s textbook Chapter 9. It can also be found in the code (file parse/Parser.java).

<Field> := IdTok

<Constant> := StrTok | IntTok

<Expression> := <Field> | <Constant>

<Term> := <Expression> = <Expression>

<Predicate> := <Term> [ AND <Predicate> ]

 

<Query> := SELECT <SelectList> FROM <TableList> [ WHERE <Predicate> ]

<SelectList> := <Field> [ , <SelectList> ]

<TableList> := IdTok [ , <TableList> ]