Read XML in spark

前端 未结 3 1053
花落未央
花落未央 2020-12-19 18:46

i am trying to read xml/nested xml in pysaprk uing spark-xml jar.

df = sqlContext.read \\
  .format(\"com.databricks.spark.xml\")\\
   .option(\"rowTag\", \         


        
3条回答
  •  悲&欢浪女
    2020-12-19 19:01

    heirarchy should be rootTag and att should be rowTag as

    df = spark.read \
        .format("com.databricks.spark.xml") \
        .option("rootTag", "hierarchy") \
        .option("rowTag", "att") \
        .load("test.xml")
    

    and you should get

    +-----+------+----------------------------+
    |Order|attval|children                    |
    +-----+------+----------------------------+
    |1    |Data  |[[[1, Studyval], [2, Site]]]|
    |2    |Info  |[[[1, age], [2, gender]]]   |
    +-----+------+----------------------------+
    

    and schema

    root
     |-- Order: long (nullable = true)
     |-- attval: string (nullable = true)
     |-- children: struct (nullable = true)
     |    |-- att: array (nullable = true)
     |    |    |-- element: struct (containsNull = true)
     |    |    |    |-- Order: long (nullable = true)
     |    |    |    |-- attval: string (nullable = true)
    

    find more information on databricks xml

提交回复
热议问题