Example #1
0
  private static String predicateToViewPredicate(F_PredicateInWhere pred, int viewIndex) {
    String newName1 = pred.getTable1() + pred.getCol1() + "_" + viewIndex;
    String newName2 = pred.getTable2() + pred.getCol2() + "_" + viewIndex;

    if (pred.lhsIsConst()) {
      newName1 = "'" + pred.getCol1() + "'";
    } else if (pred.rhsIsConst()) {
      newName2 = "'" + pred.getCol2() + "'";
    }
    return newName1 + pred.getOp() + newName2;
  }
Example #2
0
  private static String createBackRule(
      DBSchema baseSchema,
      QueryFeature addedSnippet,
      SymbolicDBView newView,
      SymbolicDBView underlyingView,
      int newViewIndex) {

    StringBuilder backrule =
        new StringBuilder(
            "CREATE RULE R_"
                + newView.getViewName()
                + " AS \n"
                + "ON INSERT TO "
                + newView.getViewName()
                + " DO INSTEAD \n");

    if (newViewIndex == 0) {
      F_TableInFrom addedTable = (F_TableInFrom) addedSnippet;
      backrule.append("INSERT INTO " + addedTable.getTableName() + " VALUES (");

      // cols from newly added table
      RelationSchema tableSchema = baseSchema.get(addedTable.getTableName());
      for (ColumnSchema col : tableSchema.getAttributes()) {
        backrule.append("NEW." + addedTable.getTableName() + col + "_" + newViewIndex + ",");
      }
      backrule.deleteCharAt(backrule.length() - 1); // remove last comma
      backrule.append(");");

    } else if (addedSnippet instanceof F_TableInFrom) {
      F_TableInFrom addedTable = (F_TableInFrom) addedSnippet;
      backrule.append("(INSERT INTO " + underlyingView.getViewName() + " VALUES (");

      // cols from underlying view
      for (String col : underlyingView.getColumnNames()) {
        backrule.append("NEW." + oldColNameToNewColName(col, newViewIndex) + ",");
      }
      backrule.deleteCharAt(backrule.length() - 1); // remove last comma
      backrule.append("); \nINSERT INTO " + addedTable.getTableName() + " VALUES(");

      // cols from newly added table
      RelationSchema tableSchema = baseSchema.get(addedTable.getTableName());
      for (ColumnSchema col : tableSchema.getAttributes()) {
        backrule.append("NEW." + addedTable.getTableName() + col + "_" + newViewIndex + ",");
      }
      backrule.deleteCharAt(backrule.length() - 1); // remove last comma
      backrule.append("));");
    } else if (addedSnippet instanceof F_PredicateInWhere) {
      F_PredicateInWhere addedPred = (F_PredicateInWhere) addedSnippet;

      backrule.append("(INSERT INTO " + underlyingView.getViewName() + " VALUES (");

      // cols from underlying view
      for (String col : newView.getColumnNames()) {
        backrule.append("NEW." + col + ",");
      }
      backrule.deleteCharAt(backrule.length() - 1); // remove last comma
      backrule.append(");");

      // add constraint

      if (addedPred.rhsIsConst()) {
        backrule.append("\nINSERT INTO Constraints VALUES(");
        backrule.append(
            "NEW."
                + addedPred.getTable1()
                + addedPred.getCol1()
                + "_"
                + newViewIndex
                + ",'"
                + addedPred.getOp()
                + addedPred.getCol2()
                + "')");
      } else if (addedPred.lhsIsConst()) {
        backrule.append("\nINSERT INTO Constraints VALUES(");
        backrule.append(
            "NEW."
                + addedPred.getTable2()
                + addedPred.getCol2()
                + "_"
                + newViewIndex
                + ",'"
                + "reverse("
                + addedPred.getOp()
                + ")"
                + addedPred.getCol1()
                + "')");
      } else {
        backrule.append("\nINSERT INTO VarConstraints VALUES(");
        backrule.append(
            "NEW."
                + addedPred.getTable1()
                + addedPred.getCol1()
                + "_"
                + newViewIndex
                + ","
                + "NEW."
                + addedPred.getTable2()
                + addedPred.getCol2()
                + "_"
                + newViewIndex
                + ",'"
                + addedPred.getOp()
                + "')");
      }

      backrule.append("); ");

    } else if (addedSnippet instanceof F_ColumnInSelect) {
      // direct backrule. since we ignore projects.
      backrule.append("INSERT INTO " + underlyingView.getViewName() + " VALUES (");

      // cols from underlying view
      for (String col : underlyingView.getColumnNames()) {
        backrule.append("NEW." + oldColNameToNewColName(col, newViewIndex) + ",");
      }
      backrule.deleteCharAt(backrule.length() - 1); // remove last comma
      backrule.append(");");
    }

    // problem: grouped by col1 [v1], and then we add col2 to the grouping[v2].
    // v2 can not be computed from v1.

    return backrule.toString();
  }