尝试从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读取镶木地板文件到火花数据帧(不先写一个镶木地板文件),我收到一个错误:
线程中的异常" main" java.lang.IllegalArgumentException:必须将AWS Access Key ID和Secret Access Key指定为s3n URL的用户名或密码,或者分别设置fs.s3n.awsAccessKeyId或fs.s3n.awsSecretAccessKey属性。
这很奇怪,因为我已经在代码片段的顶部设置了hadoopConfiguration s3AccessKeyId和secret。我想尝试使用格式为s3n://accessId:secret@bucket/path
的s3n网址,但似乎当secret包含/
字符时;它不会工作。
答案 0 :(得分:0)
升级到spark 1.5后,问题就解决了。