【问题标题】:How to get rdd after run rdd.map function on Spark (How to use rdd.insertInto)在 Spark 上运行 rdd.map 函数后如何获取 rdd(如何使用 rdd.insertInto)
【发布时间】:2014-08-07 07:57:19
【问题描述】:

我正在使用 spark 来处理数据。但我不知道如何将新数据保存到 Hive

我从 Hive 加载 rdd,然后运行 ​​map 函数来清理数据。

result = myRdd.map(lambda x: cleanup(x))

我想将结果保存到 Hive 中的新表中。所以我用

result.insertInto("newTable", True)

我收到错误:'PipelinedRDD' object has no attribute 'insertInto'

如何将结果转换为 rdd 以使用insertInto 函数?我也想知道还有其他方法可以完成这项任务吗?

【问题讨论】:

    标签: hadoop mapreduce hive apache-spark


    【解决方案1】:

    我找到了答案

    from pyspark.sql import SQLContext
    sqlCtx = SQLContext(sc)
    srdd = sqlCtx.inferSchema(result)
    

    现在我可以使用了

    srdd.insertInto("newTable", True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      • 2015-03-05
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      相关资源
      最近更新 更多