如何优化火花连接函数

时间:2017-07-07 11:12:03

标签: apache-spark dataframe apache-spark-sql user-defined-functions

我有两个数据帧,我确实在它们之间建立联接。

我目前正在考虑为此联接添加一个函数。 我在第一个数据框中有id,在第二个数据框中有描述。

这是我的文章:

// my small file
val rdd = sc.textFile("hdfs:///user/zed/file/app_desc")
// create an RDD[(String, String)] 
// collectAsMap and broadcast on the result
val id_dec: Broadcast[Map[String, String]] = sc.broadcast(rdd.map(line=>(line.split(";")(0),line.split(";")(1))).collectAsMap)
// create a function : take the id and return the descriptions
def extract_connection_type(input: String): String = {
  if (input == null || input.length() == 0)
    input
  else try {
    id_dec.value(input)
  } catch {
    case e: Exception => throw new IOException("UDF:Caught exception processing input row :" + input + e.toString);
  }
}
// apply my function into my schema
def structure(line: String): structure_Ot = {
  val fields = line.split("\\\t",-1)
  val Name1 = fields(0)
  val Name2 = fields(1)
  val Appd = fields(2)
  val App = extract_connection_type(Appd)
  val ot_str = structure_Ot(Name1, Name2, App.toInt)
  ot_str
}

我只是想知道如何优化我的工作;它仍然需要很多时间。 (正如我提到的那样,我正在一个非常大的桌子和一个小桌子之间进行连接)

我对新想法持开放态度。 谢谢,

0 个答案:

没有答案