/**
   * Parse tables and parameters
   *
   * @param root
   * @param db
   */
  @Override
  void parseTablesAndParams(VoltXMLElement stmtNode) {

    assert (stmtNode.children.size() > 1);
    tableList.clear();
    for (VoltXMLElement childSQL : stmtNode.children) {
      if (childSQL.name.equalsIgnoreCase(SELECT_NODE_NAME)) {
        AbstractParsedStmt childStmt = new ParsedSelectStmt(this.m_paramValues, this.m_db);
        childStmt.parseTablesAndParams(childSQL);
        m_children.add(childStmt);

        // So far T UNION T (as well as T JOIN T) are not handled properly
        // by the fragmentizer. Need to give an error if any table is mentioned
        // in the UNION TREE more than once.
        if (childStmt.scanColumns != null) {
          for (Table table : childStmt.tableList) {
            String tableName = table.getTypeName();
            if (m_uniqueTables.contains(tableName)) {
              // The table is not 'unique' across the union
              throw new PlanningErrorException(
                  "Table " + tableName + " appears more than once in the union statement");
            } else {
              m_uniqueTables.add(tableName);
            }
          }
        } else {
          throw new PlanningErrorException("Scan columns are NULL the UNION statement");
        }
        // Add statement's tables to the consolidated list
        tableList.addAll(childStmt.tableList);
      } else if (childSQL.name.equalsIgnoreCase(UNION_NODE_NAME)) {
        ParsedUnionStmt childStmt = new ParsedUnionStmt(this.m_paramValues, this.m_db);
        // Pass already accumulated unique tables to the child union
        childStmt.m_uniqueTables = m_uniqueTables;
        childStmt.parseTablesAndParams(childSQL);
        m_children.add(childStmt);
        // Add statement's tables to the consolidated list
        tableList.addAll(childStmt.tableList);
        // Child's unique tables now contains the consolidated list
        m_uniqueTables = childStmt.m_uniqueTables;
      } else {
        throw new PlanningErrorException("Unexpected Element in UNION statement: " + childSQL.name);
      }
    }
  }
Example #2
0
  /**
   * @param sql
   * @param xmlSQL
   * @param db
   */
  public static AbstractParsedStmt parse(
      String sql,
      VoltXMLElement stmtTypeElement,
      String[] paramValues,
      Database db,
      String joinOrder) {

    AbstractParsedStmt retval = null;

    if (stmtTypeElement == null) {
      System.err.println("Unexpected error parsing hsql parsed stmt xml");
      throw new RuntimeException("Unexpected error parsing hsql parsed stmt xml");
    }

    // create non-abstract instances
    if (stmtTypeElement.name.equalsIgnoreCase(INSERT_NODE_NAME)) {
      retval = new ParsedInsertStmt(paramValues, db);
    } else if (stmtTypeElement.name.equalsIgnoreCase(UPDATE_NODE_NAME)) {
      retval = new ParsedUpdateStmt(paramValues, db);
    } else if (stmtTypeElement.name.equalsIgnoreCase(DELETE_NODE_NAME)) {
      retval = new ParsedDeleteStmt(paramValues, db);
    } else if (stmtTypeElement.name.equalsIgnoreCase(SELECT_NODE_NAME)) {
      retval = new ParsedSelectStmt(paramValues, db);
    } else if (stmtTypeElement.name.equalsIgnoreCase(UNION_NODE_NAME)) {
      retval = new ParsedUnionStmt(paramValues, db);
    } else {
      throw new RuntimeException("Unexpected Element: " + stmtTypeElement.name);
    }

    // parse tables and parameters
    retval.parseTablesAndParams(stmtTypeElement);

    // parse specifics
    retval.parse(stmtTypeElement);

    // post parse action
    retval.postParse(sql, joinOrder);

    return retval;
  }