如何将hadooprdd结果转换为parquet格式?

lokaqttq  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(527)

我在读一本书 DynamodDB 使用apachespark的表。
以下是我的实现:
所以在Spark壳里

spark-shell --jars /usr/share/aws/emr/ddb/lib/emr-ddb-hadoop.jar
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.dynamodb.DynamoDBItemWritable

/* Importing DynamoDBInputFormat and DynamoDBOutputFormat */ 
import org.apache.hadoop.dynamodb.read.DynamoDBInputFormat 
import org.apache.hadoop.dynamodb.write.DynamoDBOutputFormat 
import org.apache.hadoop.mapred.JobConf 
import org.apache.hadoop.io.LongWritable   
var jobConf = new JobConf(sc.hadoopConfiguration) 
jobConf.set("dynamodb.servicename", "dynamodb") 
jobConf.set("dynamodb.input.tableName", "myDynamoDBTable")

// Pointing to DynamoDB table 
jobConf.set("dynamodb.endpoint", "dynamodb.us-east-1.amazonaws.com") 
jobConf.set("dynamodb.regionid", "us-east-1") jobConf.set("dynamodb.throughput.read", "1")
jobConf.set("dynamodb.throughput.read.percent", "1")
jobConf.set("dynamodb.version", "2011-12-05")  
jobConf.set("mapred.output.format.class", "org.apache.hadoop.dynamodb.write.DynamoDBOutputFormat")
jobConf.set("mapred.input.format.class", "org.apache.hadoop.dynamodb.read.DynamoDBInputFormat")  
var orders = sc.hadoopRDD(jobConf, classOf[DynamoDBInputFormat], classOf[Text], classOf[DynamoDBItemWritable])

我们在“orders”变量中得到结果。
如何将此结果转换为Parquet文件或格式?
更新:我找到了这段代码来访问和转换dynamodb数据https://github.com/onzocom/spark-dynamodb/blob/master/src/main/scala/com/onzo/spark/dynamodb/dynamodbrelation.scala?

pepwfjgg

pepwfjgg1#

Dataframe可以保存为Parquet文件,但rdd不能。这是因为Parquet文件需要一个模式。rdd不需要有模式,但dataframes必须有。

相关问题