我创建了如下凭据:
Configuration conf = new Configuration();
conf.set("fs.s3a.impl", org.apache.hadoop.fs.s3a.S3AFileSystem.class.getName());
conf.set("fs.s3a.access.key", "ACCESS_ID");
conf.set("fs.s3a.secret.key", "SECRET VALUE");
conf.set("fs.s3a.endpoint", "s3.us-east-1.amazonaws.com");
conf.set("fs.s3a.aws.credentials.provider", SimpleAWSCredentialsProvider.NAME);
conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
和路径
Path path = new Path("s3a://<backet>/<directory>/my.parquet");
尝试写入Parquet数据时:
try (ParquetWriter<GenericData.Record> writer = AvroParquetWriter.<GenericData.Record>builder(path)
.withSchema(avroSchema)
.withConf(conf)
.withCompressionCodec(SNAPPY)
.withWriteMode(OVERWRITE)
.build())
出现以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.metrics2.lib.MetricsRegistry.newCounter(Ljava/lang/String;Ljava/lang/String;J)Lorg/apache/hadoop/metrics2/lib/MutableCounterLong;
at org.apache.hadoop.fs.s3a.S3AInstrumentation.counter(S3AInstrumentation.java:183)
at org.apache.hadoop.fs.s3a.S3AInstrumentation.counter(S3AInstrumentation.java:206)
at org.apache.hadoop.fs.s3a.S3AInstrumentation.<init>(S3AInstrumentation.java:160)
at org.apache.hadoop.fs.s3a.S3AFileSystem.initialize(S3AFileSystem.java:174)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1446)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:67)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1464)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:263)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:187)
at org.apache.parquet.hadoop.ParquetFileWriter.<init>(ParquetFileWriter.java:209)
at org.apache.parquet.hadoop.ParquetWriter.<init>(ParquetWriter.java:266)
at org.apache.parquet.hadoop.ParquetWriter$Builder.build(ParquetWriter.java:489)
at Main.main(Main.java:64)
我的依赖性如下:
org.apache.avro-1.8.2, org.apache.hadoop-hadoop-core-1.2.1, org.apache.parquet-parquet-hadoop-1.8.1, org.apache.parquet-parquet-avro -1.8.1, org.apache.hadoop-hadoop-hdfs-3.2.1, org.apache.hadoop-hadoop-aws -2.8.2
你知道怎么解决这个问题吗?
1条答案
按热度按时间z4bn682m1#
这个
MetricsRegistry
班级是学校的一部分hadoop-common
图书馆。您在依赖项列表中缺少它。确保此jar的版本与hadoop-aws
jar。另外,建议所有hadoop依赖jar使用相同的版本。
更新:
您正在尝试使用hadoop库来写入s3。在这种情况下,hadoop将尝试使用本地文件系统来创建临时文件。这是windows操作系统,您需要
winutils
.下载
winutils.exe
二进制文件和其他需要的文件。设置环境变量
%HADOOP_HOME%
指向安装这些二进制文件的目录。阅读more:hadoop2 - windows问题