我有一个看起来像这样多个XML文件计数行:PySpark包含字符串
<?xml version="1.0" encoding="UTF-8"?>
<parent>
<row AcceptedAnswerId="15" AnswerCount="5" Body="<p>How should
I elicit prior distributions from experts when fitting a Bayesian
model?</p> " CommentCount="1" CreationDate="2010-07-
19T19:12:12.510" FavoriteCount="17" Id="1" LastActivityDate="2010-09-
15T21:08:26.077" OwnerUserId="8" PostTypeId="1" Score="26"
Tags="<bayesian><prior><elicitation>"
Title="Eliciting priors from experts" ViewCount="1457" />
我想能够使用PySpark数不包含该字符串的行:<row
我目前的想法:
def startWithRow(line):
if line.strip().startswith("<row"):
return True
else:
return False
sc.textFile(localpath("folder_containing_xmg.gz_files")) \
.filter(lambda x: not startWithRow(x)) \
.count()
我试图验证这一点,但我从甚至一个简单的计数线是没有意义得到结果(我下载的XML文件,并做了一个wc
它与PySpark的字数不匹配。)
关于我上面的方法有什么突出的错/奇怪吗?
的可能的复制[如何解析Apache中星火XML文件?(https://stackoverflow.com/questions/33280821/how-to-parse-xml-files-in-apache-spark) –