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

JdbcSortRule has a bug and it is never chosen

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: jdbc-adapter
    • Labels:
      None

      Description

      JdbcSortRule tries to push sort and limit operations to the database.
      Currently offset and limit operations are explicitly not pushed to the database (prevented by the rule) but even sort operations end up not being pushed.
      Checking how other adapters deal with this, like Mongo and Cassandra adapters, I realized that the convert function from JdbcSortRule is different from the others.
      Jdbc-adapter:

           if (sort.offset != null || sort.fetch != null) {
              // Cannot implement "OFFSET n FETCH n" currently.
              return null;
            }
            final RelTraitSet traitSet = sort.getTraitSet().replace(out);
            return new JdbcSort(rel.getCluster(), traitSet,
                convert(sort.getInput(), traitSet), sort.getCollation());
      

      mongodb-adapter:

            final RelTraitSet traitSet =
                sort.getTraitSet().replace(out)
                    .replace(sort.getCollation());
            return new MongoSort(rel.getCluster(), traitSet,
                convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)),
                sort.getCollation(), sort.offset, sort.fetch);
      

      By fixing JdbcSortRule so that it is just like those others and by removing the code that prevented the rule to match when limit or offset are used seems to solve the problem and JdbcSortRule now is being applied and both sort and limit are being pushed to the database.

        Attachments

          Activity

            People

            • Assignee:
              winipanda TANG Wen-hui
              Reporter:
              lfkauer Luis Fernando Kauer
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: