Java ParquetWriter构造函数不可见

Java ParquetWriter构造函数不可见,java,constructor,parquet,Java,Constructor,Parquet,我试图创建ParquetWriter类的对象,该类接受参数(OutputFile、Mode、WriteSupport、CompressionCodecName、int、boolean、Configuration、int、ParquetProperties)。 但是这个构造函数在我使用的API中有默认的访问修饰符。我无法访问它 我包括了maven的拼花地板库 compile group: 'org.apache.parquet', name: 'parquet-hadoop', version:

我试图创建ParquetWriter类的对象,该类接受参数(OutputFile、Mode、WriteSupport、CompressionCodecName、int、boolean、Configuration、int、ParquetProperties)。 但是这个构造函数在我使用的API中有默认的访问修饰符。我无法访问它

我包括了maven的拼花地板库

compile group: 'org.apache.parquet', name: 'parquet-hadoop', version: '1.10.1'
我甚至试图扩展那个类,但仍然得到了不可见的错误构造函数

public class MyParquetWriter  extends ParquetWriter{

    MyParquetWriter(OutputFile file, Mode mode, WriteSupport writeSupport, CompressionCodecName compressionCodecName,
            int rowGroupSize, boolean validating, Configuration conf, int maxPaddingSize,
            ParquetProperties encodingProps) throws IOException {
        super(file, mode, writeSupport, compressionCodecName, rowGroupSize, validating, conf, maxPaddingSize, encodingProps);

    }
}

如何在我的项目中使用此构造函数?

我查看了类
ParquetWriter
的实现,所有构造函数都标记为不推荐使用。
您应该使用inted
Builder
类对其进行实例化,该类在
ParquetWriter
中作为嵌套类提供

这样,您还可以确保您的代码与将来的版本兼容

有关如何使用构建器的更多信息,请参阅本文:

编辑: 在类似的情况下,我一直在做的是编写一个包装器类,它(在本例中)将使用构建器初始化一个私有ParquetWriter实例:

public class MyParquetWriterWrapper implements Closeable {
    private final ParquetWriter parquetWriter;

    public MyParquetWriterWrapper(Path file, WriteSupport writeSupport, CompressionCodecName compressionCodecName, int blockSize, int pageSize) throws IOException {
        ParquetWriter.Builder parquetWriterbuilder = new ParquetWriter.Builder() {
            @Override
            protected ParquetWriter.Builder self() {
                return this;
            }

            @Override
            protected WriteSupport getWriteSupport(org.apache.hadoop.conf.Configuration conf) {
                return writeSupport;
            }
        };

        parquetWriterbuilder.withCompressionCodec(compressionCodecName);
        parquetWriterbuilder.withPageSize(pageSize);
        // ... + other properties which you want to be set

        parquetWriter = parquetWriterbuilder.build(); // building the parquetWriter instance
    }

    public ParquetWriter unwrap() {
        return this.parquetWriter;
    }

    @Override
    public void close() throws IOException {
        parquetWriter.close();
    }
包装器不会覆盖ParquetWriter中的方法,而是简单地转发调用:

public void write(T object) throws IOException {
    // some code before writing...
    this.parquetWriter.write(object);
    // some code after writing...
}

正如中所指出的,扩展一个具体类(特别是在不受您控制的情况下)通常不被认为是最佳实践。最好是从接口继承,但ParquetWriter只使用Closeable,这并不能让您走得很远…

您会遇到什么编译错误?请看一下:在版本2.0编译错误中,构造函数似乎也将被删除-构造函数不可见。ParquetWriter的最后一种方法并没有被弃用,它使用路径作为HadoopOutputFile。fromPath(path,conf)您能推荐任何在Hadoop中编写ParquetFile的替代方法吗?我也尝试过ParquetFileWriter,但它不支持通过我读到的关于构建器类的文章。但我仍然无法访问ParquetWriter构造函数,该构造函数为在Hadoop中编写parquet文件提供了输出文件。我希望我可以这样做,但无法扩展具体类CloseableMy bad:它应该是implements Closeable而不是extends Closeable。。。我相应地修改了我的答案