Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Hadoop流媒体读取PySpark中的Xml文件_Pyspark_Hadoop Streaming - Fatal编程技术网

通过Hadoop流媒体读取PySpark中的Xml文件

通过Hadoop流媒体读取PySpark中的Xml文件,pyspark,hadoop-streaming,Pyspark,Hadoop Streaming,我正在尝试将代码从Scala版本改编为PySpark版本。以下是我使用的代码: conf = SparkConf().setAppName("Parse Xml File") sc = SparkContext(conf = conf) sqlContext = HiveContext(sc) sc._jsc.hadoopConfiguration().set('stream.recordreader.class', 'org.apache.hadoop.str

我正在尝试将代码从Scala版本改编为PySpark版本。以下是我使用的代码:

    conf = SparkConf().setAppName("Parse Xml File")
    sc = SparkContext(conf = conf)
    sqlContext = HiveContext(sc)

    sc._jsc.hadoopConfiguration().set('stream.recordreader.class', 'org.apache.hadoop.streaming.StreamXmlRecordReader')
    sc._jsc.hadoopConfiguration().set('stream.recordreader.begin', '<page>')
    sc._jsc.hadoopConfiguration().set('stream.recordreader.end', '</page>')

    xml_sdf = sc.newAPIHadoopFile(xml_data_path,
                                       'org.apache.hadoop.streaming.StreamInputFormat',
                                       'org.apache.hadoop.io.Text',
                                       'org.apache.hadoop.io.Text')
    print("Found {0} records.".format(wiki_xml_sdf.count()))

    sc.stop()

是否有其他输入格式/设置可供我使用?

最简单的解决方案是使用软件包。在您的情况下(所有文档都以
开头),下面的代码将数据加载到数据框中:

sqlContext.read.format('com.databricks.spark.xml')
    .options(rowTag='page').load('samplexml.xml')

我在找更普通的东西。我不认为底层文件被拆分为每行一个文档,这是spark xml工作所必需的。spark-xml不需要文档在单独的行中,您可以有一个大的单行文件,它可以工作。试试看:-)
sqlContext.read.format('com.databricks.spark.xml')
    .options(rowTag='page').load('samplexml.xml')