Csc 1302, Honors Principles of Computer Science II (Fall 2021)
Week 9-14 (22 October 2021 to end of semester)
Relational Algebra Query Interpreter
For the rest of the semester you will build a Relational Algebra Query Interpreter using ANTLR4. Here is the grammar for Relational Algebra Queries:
query : expr SEMI
expr :
factor UNION expr
| factor MINUS expr
| factor INTERSECT expr
| factor
factor :
term TIMES expr
| term JOIN expr
| term
term :
NAME
| PROJECT LBRACKET alist RBRACKET LPAREN expr RPAREN
| RENAME LBRACKET alist RBRACKET LPAREN expr RPAREN
| SELECT LBRACKET condition RBRACKET LPAREN expr RPAREN
| LPAREN expr RPAREN
alist :
NAME
| alist COMMA NAME
condition :
simplecondition
| condition AND simplecondition
simplecondition :
operand COMPARISON operand
operand :
NAME
| STRING
| NUMBER
fragment VALID_NAME_START : ('a'..'z') | ('A'..'Z');
fragment VALID_NAME_CHAR : VALID_NAME_START | ('0'..'9') | '_';
LBRACKET : '[';
RBRACKET : ']';
LPAREN : '(';
RPAREN : ')';
SEMI : ';';
COMMA : ',';
UNION : 'UNION' | 'union';
MINUS : 'MINUS' | 'minus';
INTERSECT : 'INTERSECT' | 'intersect';
TIMES : 'TIMES' | 'times';
JOIN : 'JOIN' | 'join';
PROJECT : 'PROJECT' | 'project';
SELECT : 'SELECT' | 'select';
RENAME : 'RENAME' | 'rename';
AND : 'AND' | 'and';
NUMBER : ('0'..'9')+ | ('0'..'9')* '.' ('0'..'9')+;
STRING : '\'' (~[\r\n'] | '\'\'')* '\'';
COMPARISON : '< | '< | '>' | '>=' | '=' | '<>';
NAME : VALID_NAME_START VALID_NAME_CHAR*;
WS : [ \r\n\t]+ -> skip;
Download the files and implement the following 3 methods in RANode.java:
public String semanticCheckAndSetSchemaAndDataTypes(Database db) {
// Task 1: check for semantic errors; if error return error message
// otherwise return "OK"
// Task 2: set values for the following three variables:
// public ArrayList joinColumns; // used to remember JOIN columns
// public ArrayList<String> schemaColumns;
// public ArrayList<String> schemaDataTypes;
}
public void setRelationNames(AtomicInteger globalInt) {
// set unique relation names for every interior node in the tree
// public String relationName; // used to name interior nodes with tempN; relation name at leaf
}
public Relation evaluate(Database db) {
// evaluate and return relation object for node
}