3

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?

closed as off-topic by Marcello Miorelli, Colin 't Hart, Racer SQL, SQLRaptor, Josh Darnell Aug 9 at 18:06

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Shopping list question - questions about which tool, library, product or resource you should use are off-topic here because they quickly become obsolete and often are just about the preferences of the answerer. If you have an issue with or a question about a specific tool, please revise your question to conform to that scope." – Marcello Miorelli, Josh Darnell
  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Racer SQL, SQLRaptor
If this question can be reworded to fit the rules in the help center, please edit the 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 :) – Philᵀᴹ 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
1

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();
        }
    }
}

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