private String constructIRRequest(ISQLNode sql)
            throws Exception {

        switch(sql.getType()) {
            case Root: {

                SQLRoot root = (SQLRoot) sql;

                // Root can be ignored so just
                // return the input relation
                // request from the child node.
                return constructIRRequest(
                        root.getChild());
            }
            case Projection: {

                SQLProjection projection
                        = (SQLProjection) sql;

                // Projection can be ignored so
                // just return the input relation
                // request from child node.
                return constructIRRequest(
                        projection.getChild());
            }
            case Selection: {

                SQLSelection selection
                        = (SQLSelection) sql;

                return String.format("SELECT * FROM ( %s ) WHERE %s",
                        constructIRRequest(selection.getChild()),
                        constructConditionString(selection.getCondition()));
            }
            case Minus: {

                SQLMinus minus = (SQLMinus) sql;

                break;
            }
            case Union: {

                SQLUnion union = (SQLUnion) sql;

                break;
            }
            case NJoin: {

                SQLNJoin njoin = (SQLNJoin) sql;

                return String.format("SELECT * FROM (%s) NATURAL JOIN (%s)",
                        constructIRRequest(njoin.getLeftChild()),
                        constructIRRequest(njoin.getRightChild()));

            }
            case IJoin: {

                // Cast to the specific type.
                SQLIJoin ijoin = (SQLIJoin) sql;

                return String.format("SELECT * FROM (%s) INNER JOIN (%s) ON %s",
                        constructIRRequest(ijoin.getLeftChild()),
                        constructIRRequest(ijoin.getRightChild()),
                        constructConditionString(ijoin.getCondition()));
            }
            case Relation: {

                SQLRelation relation
                        = (SQLRelation) sql;

                String selectAttrs = "";

                for(Attribute attr: relation.getAttributes())
                    selectAttrs += attr + ",";

                //selectAttrs += "E#BID AS E#BID" + relation.getQueryId() + ", ";
                //selectAttrs += "E#TID AS E#TID" + relation.getQueryId() + ", ";
                //selectAttrs += "E#PROB AS E#PROB" + relation.getQueryId();

                return String.format("SELECT %s FROM %s",
                        selectAttrs, relation.getName());
            }
        }

        throw new Exception(String.format(
                "Can't construct the input relation request. " +
                        "The node type %s is unknown.", sql.getType()));
    }