Querying Spark SQL DataFrame with complex types

后端 未结 3 1057
难免孤独
难免孤独 2020-11-22 01:18

How Can I query an RDD with complex types such as maps/arrays? for example, when I was writing this test code:

case class Test(name: String, map: Map[String,         


        
3条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 02:01

    here was what I did and it worked

    case class Test(name: String, m: Map[String, String])
    val map = Map("hello" -> "world", "hey" -> "there")
    val map2 = Map("hello" -> "people", "hey" -> "you")
    val rdd = sc.parallelize(Array(Test("first", map), Test("second", map2)))
    val rffffdf = rdd.toDF
    rffffdf.registerTempTable("mytable")
    sqlContext.sql("select m.hello from mytable").show
    

    Results

    +------+
    | hello|
    +------+
    | world|
    |people|
    +------+
    

提交回复
热议问题