当试图从s3读取一个拼花文件时,我有一个非常奇怪的错误。我正在使用火花书中的以下代码片段。
package com.knx.rtb.sample
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.functions._
// One method for defining the schema of an RDD is to make a case class with the desired column
// names and types.
case class Record(key: Int, value: String)
object SparkSql {
def main(args: Array[String]) {
val sparkConf = new SparkConf().setAppName("SparkSql")
val sc = new SparkContext(sparkConf)
sc.hadoopConfiguration.set("fs.s3n.awsAccessKeyId", "accesskey")
sc.hadoopConfiguration.set("fs.s3n.awsSecretAccessKey", "secretKey+JJbat7uEQtX/")
val sqlContext = new SQLContext(sc)
// Importing the SQL context gives access to all the SQL functions and implicit conversions.
import sqlContext.implicits._
val df = sc.parallelize((1 to 100).map(i => Record(i, s"val_$i"))).toDF()
//if I remove this line; then I got the error
df.write.parquet("s3n://adx-test/hdfs/pair.parquet")
// Read in parquet file. Parquet files are self-describing so the schmema is preserved.
val parquetFile = sqlContext.read.parquet("s3n://adx-test/hdfs/pair.parquet")
// Queries can be run using the DSL on parequet files just like the original RDD.
parquetFile.where($"key" === 1).select($"value".as("a")).collect().foreach(println)
// These files can also be registered as tables.
parquetFile.registerTempTable("parquetFile")
println("Result of Parquet file:")
sqlContext.sql("SELECT * FROM parquetFile").collect().foreach(println)
sc.stop()
}
}代码段运行时没有任何问题。但是,每当我移除行:df.write.parquet("s3n://adx-test/hdfs/pair.parquet") (这意味着将s3中的拼花文件读取到火花数据文件中)时(没有首先写入拼花文件),我就会得到一个错误:
线程“java.lang.IllegalArgumentException”中的异常: AWS访问密钥ID和秘密访问密钥必须分别指定为s3n URL的用户名或密码,或者通过设置fs.s3n.awsAccessKeyId或fs.s3n.awsSecretAccessKey属性来指定。
这很奇怪,因为我已经在代码段的顶部设置了hadoopConfiguration s3AccessKeyId和s3AccessKeyId。我想尝试使用s3n url格式的s3n://accessId:secret@bucket/path,但是当秘密包含/字符时,它似乎无法工作。
发布于 2015-09-21 10:02:19
升级到火花1.5后,问题就解决了。
https://stackoverflow.com/questions/32552443
复制相似问题