Uploaded image for project: 'Parquet'
  1. Parquet
  2. PARQUET-2154

ParquetFileReader should close its input stream when `filterRowGroups` throw Exception in constructor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.13.0
    • None
    • None

    Description

       

      public ParquetFileReader(InputFile file, ParquetReadOptions options) throws IOException {
        this.converter = new ParquetMetadataConverter(options);
        this.file = file;
        this.f = file.newStream();
        this.options = options;
        try {
          this.footer = readFooter(file, options, f, converter);
        } catch (Exception e) {
          // In case that reading footer throws an exception in the constructor, the new stream
          // should be closed. Otherwise, there's no way to close this outside.
          f.close();
          throw e;
        }
        this.fileMetaData = footer.getFileMetaData();
        this.fileDecryptor = fileMetaData.getFileDecryptor(); // must be called before filterRowGroups!
        if (null != fileDecryptor && fileDecryptor.plaintextFile()) {
          this.fileDecryptor = null; // Plaintext file. No need in decryptor
        }
      
        this.blocks = filterRowGroups(footer.getBlocks());
        this.blockIndexStores = listWithNulls(this.blocks.size());
        this.blockRowRanges = listWithNulls(this.blocks.size());
        for (ColumnDescriptor col : footer.getFileMetaData().getSchema().getColumns()) {
          paths.put(ColumnPath.get(col.getPath()), col);
        }
        this.crc = options.usePageChecksumVerification() ? new CRC32() : null;
      } 

      During the construction of ParquetFileReader, if `filterRowGroups` method throws an exception, it will cause resource leak because when `filterRowGroups(footer.getBlocks())` throw an Exception, the open stream `this.f = file.newStream()` looks unable to be closed.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            LuciferYang Yang Jie
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: