Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-7812

Broken equals/hashcode contract

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.17.0
    • 1.19.0
    • None
    • None

    Description

      MaterializedField class has broken equals/hashCode contract:

      If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

      In our case equals() method depends on 2 fields: name and type. While hashCode() method depends on 3 fields: name, type and child. This is leading to serious bugs. For example, it can occurs in SortRecordBatchBuilder class there :

      if (batches.keySet().size() > 1) {
         throw UserException.validationError(null)
            .message("Sort currently only supports a single schema.")
            .build(logger);
      }
      

      Batches is ArrayListMultimap<BatchSchema, RecordBatchData> and when RecordBatchData is insert with BatchSchema key – occurs not expected behaivor, because RecordBatchData hashCode is based on hashCode of MaterializedField:

      @Override
      public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((fields == null) ? 0 : fields.hashCode());
        result = prime * result + ((selectionVectorMode == null) ? 0 : selectionVectorMode.hashCode());
        return result;
      }

      So RecordBatchData with equals BatchSchema are going to be add to ArrayListMultimap as different entries. It's not common situation, and most easily can be reproduced with json tables.

       

      Attachments

        Activity

          People

            mrymar Maksym Rymar
            mrymar Maksym Rymar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: