public boolean equals()

in pinot-common/src/main/java/org/apache/pinot/common/datablock/DataBlockEquals.java [151:399]


    public boolean equals(DataBlock left, DataBlock right) {
      DataBlock.Type leftType = left.getDataBlockType();
      DataBlock.Type rightType = right.getDataBlockType();
      if (leftType == DataBlock.Type.METADATA) {
        if (rightType != DataBlock.Type.METADATA) {
          if (_failOnFalse) {
            throw new IllegalArgumentException("Different types: " + leftType + " and " + rightType);
          }
          return false;
        }
        if (!Objects.equals(left.getExceptions(), right.getExceptions())) {
          if (_failOnFalse) {
            throw new IllegalArgumentException("Different exceptions: " + left.getExceptions() + " and "
                + right.getExceptions());
          }
          return false;
        }
        if (!Objects.equals(left.getStatsByStage(), right.getStatsByStage())) {
          if (_failOnFalse) {
            throw new IllegalArgumentException("Different statsByStage: " + left.getStatsByStage() + " and "
                + right.getStatsByStage());
          }
          return false;
        }
      } else {
        if (rightType == DataBlock.Type.METADATA) {
          if (_failOnFalse) {
            throw new IllegalArgumentException("Different types: " + leftType + " and " + rightType);
          }
          return false;
        }

        DataSchema dataSchema = left.getDataSchema();
        assert dataSchema != null;
        if (!dataSchema.equals(right.getDataSchema())) {
          if (_failOnFalse) {
            throw new IllegalArgumentException("Different data schemas: " + dataSchema + " and "
                + right.getDataSchema());
          }
          return false;
        }

        if (left.getNumberOfRows() != right.getNumberOfRows()) {
          if (_failOnFalse) {
            throw new IllegalArgumentException("Different number of rows: " + left.getNumberOfRows() + " and "
                + right.getNumberOfRows());
          }
          return false;
        }
        int numRows = left.getNumberOfRows();
        if (left.getNumberOfColumns() != right.getNumberOfColumns()) {
          if (_failOnFalse) {
            throw new IllegalArgumentException("Different number of columns: " + left.getNumberOfColumns() + " and "
                + right.getNumberOfColumns());
          }
          return false;
        }

        DataSchema.ColumnDataType[] colTypes = dataSchema.getColumnDataTypes();
        String[] colNames = dataSchema.getColumnNames();
        for (int colId = 0; colId < colNames.length; colId++) {
          RoaringBitmap leftNulls = left.getNullRowIds(colId);
          RoaringBitmap rightNulls = right.getNullRowIds(colId);
          if (!Objects.equals(leftNulls, rightNulls)) {
            if (_failOnFalse) {
              throw new IllegalArgumentException("Different nulls for column: " + colNames[colId]
                  + " left: " + leftNulls + " right: " + rightNulls);
            }
            return false;
          }

          switch (colTypes[colId]) {
            case INT:
            case BOOLEAN:
              for (int did = 0; did < numRows; did++) {
                if (left.getInt(did, colId) != right.getInt(did, colId)) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getInt(did, colId) + " right: " + right.getInt(did, colId));
                  }
                  return false;
                }
              }
              break;
            case LONG:
            case TIMESTAMP:
              for (int did = 0; did < numRows; did++) {
                if (left.getLong(did, colId) != right.getLong(did, colId)) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getLong(did, colId) + " right: " + right.getLong(did, colId));
                  }
                  return false;
                }
              }
              break;
            case FLOAT:
              for (int did = 0; did < numRows; did++) {
                if (left.getFloat(did, colId) != right.getFloat(did, colId)) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getFloat(did, colId) + " right: " + right.getFloat(did, colId));
                  }
                  return false;
                }
              }
              break;
            case DOUBLE:
              for (int did = 0; did < numRows; did++) {
                if (left.getDouble(did, colId) != right.getDouble(did, colId)) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getDouble(did, colId) + " right: " + right.getDouble(did, colId));
                  }
                  return false;
                }
              }
              break;
            case STRING:
            case JSON:
              for (int did = 0; did < numRows; did++) {
                if (!left.getString(did, colId).equals(right.getString(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getString(did, colId) + " right: " + right.getString(did, colId));
                  }
                  return false;
                }
              }
              break;
            case BYTES:
              for (int did = 0; did < numRows; did++) {
                if (!left.getBytes(did, colId).equals(right.getBytes(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getBytes(did, colId) + " right: " + right.getBytes(did, colId));
                  }
                  return false;
                }
              }
              break;
            case BIG_DECIMAL:
              for (int did = 0; did < numRows; did++) {
                if (!left.getBigDecimal(did, colId).equals(right.getBigDecimal(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getBigDecimal(did, colId) + " right: " + right.getBigDecimal(did, colId));
                  }
                  return false;
                }
              }
              break;
            case OBJECT:
              for (int did = 0; did < numRows; did++) {
                if (!Objects.equals(left.getCustomObject(did, colId), right.getCustomObject(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + left.getCustomObject(did, colId)
                        + " right: " + right.getCustomObject(did, colId));
                  }
                  return false;
                }
              }
              break;
            case INT_ARRAY:
              for (int did = 0; did < numRows; did++) {
                if (!Arrays.equals(left.getIntArray(did, colId), right.getIntArray(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + Arrays.toString(left.getIntArray(did, colId))
                        + " right: " + Arrays.toString(right.getIntArray(did, colId)));
                  }
                  return false;
                }
              }
              break;
            case LONG_ARRAY:
            case TIMESTAMP_ARRAY:
              for (int did = 0; did < numRows; did++) {
                if (!Arrays.equals(left.getLongArray(did, colId), right.getLongArray(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + Arrays.toString(left.getLongArray(did, colId))
                        + " right: " + Arrays.toString(right.getLongArray(did, colId)));
                  }
                  return false;
                }
              }
              break;
            case FLOAT_ARRAY:
              for (int did = 0; did < numRows; did++) {
                if (!Arrays.equals(left.getFloatArray(did, colId), right.getFloatArray(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + Arrays.toString(left.getFloatArray(did, colId))
                        + " right: " + Arrays.toString(right.getFloatArray(did, colId)));
                  }
                  return false;
                }
              }
              break;
            case DOUBLE_ARRAY:
              for (int did = 0; did < numRows; did++) {
                if (!Arrays.equals(left.getDoubleArray(did, colId), right.getDoubleArray(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + Arrays.toString(left.getDoubleArray(did, colId))
                        + " right: " + Arrays.toString(right.getDoubleArray(did, colId)));
                  }
                  return false;
                }
              }
              break;
            case STRING_ARRAY:
              for (int did = 0; did < numRows; did++) {
                if (!Arrays.equals(left.getStringArray(did, colId), right.getStringArray(did, colId))) {
                  if (_failOnFalse) {
                    throw new IllegalArgumentException("Different values for " + colTypes[colId]
                        + " column: " + colNames[colId]
                        + " left: " + Arrays.toString(left.getStringArray(did, colId))
                        + " right: " + Arrays.toString(right.getStringArray(did, colId)));
                  }
                  return false;
                }
              }
              break;
            case BYTES_ARRAY:
            case BOOLEAN_ARRAY:
            case UNKNOWN:
              throw new UnsupportedOperationException("Check how to read " + colTypes[colId] + " from data block");
            default:
              throw new UnsupportedOperationException("Unsupported column type: " + colTypes[colId]);
          }
        }
      }
      return true;
    }