【问题标题】:Data governance with scala/spark使用 scala/spark 进行数据治理
【发布时间】:2018-07-23 21:22:31
【问题描述】:

我有一个 ETL 来分析大数据,我的所有表都是 Spark 2.2.X 的 DataFrames。现在,我必须添加数据治理才能知道数据的来源。例如:

表A

| Col1 | Col2 |  
| ---- | ---- |  
| test | hello |  
| test3 | bye |

表 B

| Col1 | Col2 |  
| ---- | ---- |  
| test2 | hey |  
| test3 | bye |

现在我有两个表,我要做的是通过Col1Col2 + Col2 进行连接。结果表:

决赛桌

| Col1 | Col2 |  
| ---- | ---- |  
|test3 | byebye|  

我的问题是,Spark DataFrame、API 中是否有任何功能不会让我对代码进行太多更改,并且我可以在 DataFrame 中显示我拥有的所有转换?

【问题讨论】:

    标签: scala apache-spark apache-spark-sql


    【解决方案1】:

    如果您想快速解决此问题,可以查看RDD#toDebugString。您可以在 DataFrame 上调用 rdd 方法,然后通过此方法显示其血统。

    这是来自Jacek Laskowski's book "Mastering Apache Spark"的示例:

    scala> val wordCount = sc.textFile("README.md").flatMap(_.split("\\s+")).map((_, 1)).reduceByKey(_ + _)
    wordCount: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[21] at reduceByKey at <console>:24
    
    scala> wordCount.toDebugString
    res13: String =
    (2) ShuffledRDD[21] at reduceByKey at <console>:24 []
     +-(2) MapPartitionsRDD[20] at map at <console>:24 []
        |  MapPartitionsRDD[19] at flatMap at <console>:24 []
        |  README.md MapPartitionsRDD[18] at textFile at <console>:24 []
        |  README.md HadoopRDD[17] at textFile at <console>:24 []
    

    此 sn-p 以及有关 RDD 沿袭和toDebugString 的详细说明可在here 获得。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-13
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 2017-01-24
      • 2018-07-12
      • 2019-10-14
      相关资源
      最近更新 更多