Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am participating in the Stanford Database Class, and there are some problem sets to be solved in "mathy" relational algebra syntax.

The course instructors demand from students to use this open-source, free jar file "ra.jar" to submit solutions via web forms.

RA: an interactive relational algebra interpreter
Version 2.1b by Jun Yang (junyang@cs.duke.edu)
>

I wonder if there is a better evaluator available? This one is pretty good but

  • on the command-line-interpreter prompt, the cursor position is hard to see

  • the tool translates relational alegbra experssions to SQL and submits them to SQLite. It does not show (return to the user) the intermediate steps. There should be a -log or verbose option to return the SQL generated. (The ra tool has a -v option to return the submitted ra query).

I want the CREATE VIEW.... and SELECT ... SQL statements that the jar file generates and sends to SQLite. Alternatively, can I configure SQLite to echo/log all sql commands submitted to it? Is there an option for the .properties file?

share|improve this question
1  
Why do you need the SQL? You can use the SQLite command line tool to look at any data stored in the generated datafile. I do hope you're not somehow trying to cheat the course :) –  FreshPhilOfSO Feb 3 '13 at 13:03
    
I don't really "need" it, I just want to now what is generated (are "exists" or "in" clauses used, or how a set difference is realized etc) I know what's inside the datafile. And someone else helped a bit by putting the solutions on github. And I know how I can add a logger object to the java code, but maybe someone has done this already. –  knb Feb 3 '13 at 13:48
add comment

1 Answer

That RA tool does not have an option to output the SQL queries.

However, the mapping from relational algebra to SQL is pretty much trivial (except for division), can be easily found with a web search, and is something you should have learned in your course.

If you want to find out how RA handles this, look into the file RAXNode.java. The various classes derived from RAXNode each implement one relational algebra operation; the method toPrintString shows the RA operation, while genViewDef generates the corresponding SQL command. For example:

public static class PROJECT extends RAXNode {
    public String toPrintString() {
        return "\\project_{" + _columns + "}";
    }
    public String genViewDef(DB db) {
        return "SELECT DISTINCT " + _columns + " FROM " + getChild(0).getViewName();
    }
}
...
public static class INTERSECT extends RAXNode {
    public String toPrintString() {
        return "\\intersect";
    }
    public String genViewDef(DB db) {
        if (db.getDriverName().equals("com.mysql.jdbc.Driver")) {
            // MySQL doesn't support INTERSECT, so we need a workaround.
            ...
        } else {
            return "SELECT * FROM " + getChild(0).getViewName() +
                " INTERSECT SELECT * FROM " + getChild(1).getViewName();
        }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.