Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5796

DELETE statement is not effective

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • core, linq4j
    • None

    Description

      I try to use `DELETE FROM t`, but the table was not affected.

       

      static void erase(SqlIdentifier name, CalcitePrepare.Context context) {
        // Generate, prepare and execute an "DELETE FROM table" statement.
        // (It's a bit inefficient that we convert from SqlNode to SQL and back
        // again.)
        final FrameworkConfig config = Frameworks.newConfigBuilder()
            .defaultSchema(context.getRootSchema().plus())
            .build();
        final Planner planner = Frameworks.getPlanner(config);
        try {
          final StringBuilder buf = new StringBuilder();
          final SqlWriterConfig writerConfig =
              SqlPrettyWriter.config().withAlwaysUseParentheses(false);
          final SqlPrettyWriter w = new SqlPrettyWriter(writerConfig, buf);
          buf.append("DELETE FROM ");
          name.unparse(w, 0, 0);
          final String sql = buf.toString();
          final SqlNode query1 = planner.parse(sql);
          final SqlNode query2 = planner.validate(query1);
          final RelRoot r = planner.rel(query2);
          final PreparedStatement prepare =
              context.getRelRunner().prepareStatement(r.rel);
          int rowCount = prepare.executeUpdate();
          Util.discard(rowCount);
          prepare.close();
        } catch (SqlParseException | ValidationException
                 | RelConversionException | SQLException e) {
          throw Util.throwAsRuntime(e);
        }
      } 

       

      Because we use `EnumerableDefaults#remove()` to delete target rows. 

      The rows is object array, they can't match.

      Attachments

        Activity

          People

            jiajunbernoulli Jiajun Xie
            jiajunbernoulli Jiajun Xie
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: