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. If you have access to the book, read Chapter 9 on Parsing. Looking at the grammar, the main part that needs to be changed is related to Term. The code that need to be changed can be found in subdirectory parse (Lexer.java, Parser.java) and subdirectory query (Term.java) You should test that your extended SimpleDB works for both int and String.
In the parse subdirectory, you will find several test programs. You can modify them to test the changes you make progressively (LexerTest.java, ParserTest.java, PredParserTest.java, TokenizerTest.java).
In the query subdirectory, you will also find several test programs that you can use to test your code (ScanTest1.java, ScanTest2.java). You can also try out the SimpleIJ.java demo program.
Submit a report that describes the changes made to support non-equality predicates. Include a few sample queries that your engine can support now. 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> ]