我试图通过形成键值对来读取日志行,但出现错误。 这是我的代码:
logLine=sc.textFile("C:\TestLogs\testing.log").cache()
lines = logLine.flatMap(lambda x: x.split('\n'))
rx = "(\\S+)=(\\S+)"
line_collect = lines.collect()
for line in line_collect :
d = dict([(x,y) for x,y in re.findall(rx,line)])
d = str(d)
print d
错误:
line_collect = lines.collect()......InvalidInputException: Input path does not exist: file:/C:/TestLogs esting.log
我不知道如何纠正这个问题。我是 python 和 Spark 的新手。
最佳答案
当字符序列\t
在字符串中找到,它将被替换为制表符。您实际上可以在错误消息中看到这一点。
我建议始终使用正斜杠 /
作为目录分隔符,即使在 Windows 上也是如此。或者在字符串前面加上 r 前缀,如下所示: r"does not replace \t with <tab>."
.
您可能想阅读字符串文字:https://docs.python.org/2.0/ref/strings.html .
关于python - 即使在正确的位置提到了该文件,输入文件也不存在 - pyspark,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39200177/