如何将文件从本地移动到 Python 中的 HDFS?
How do I move a file from local to HDFS in Python?
我有一个脚本来检查目录中的文件。如果存在正确的文件(带关键字),我想将 that/those 个文件移动到 HDFS 位置。
import os
tRoot = "/tmp/mike"
keyword = "test"
for root, dirs, files in os.walk(tRoot):
for file in files:
if keyword in file:
fullPath = str(os.path.join(root, file))
subprocess.call(['hdfs', 'dfs', '-copyFromLocal','/tmp/mike/test*','hdfs:///user/edwaeadt/app'], shell=True)
我看到以下错误:
Usage: hdfs [--config confdir] [--loglevel loglevel] COMMAND
我也试过
subprocess.call(['hadoop', 'fs', '-copyFromLocal', '/tmp/mike/test*', 'hdfs:///user/edwaeadt/app'], shell=True)
但我看到了
Usage: hadoop [--config confdir] [COMMAND | CLASSNAME]
CLASSNAME
此外,这个循环似乎是 运行 3 次。因为我现在看到文件已移至 hdfs 位置,但我也看到两次它表示文件存在。好像这个 copyFromLocal 是 运行 3 次。有什么想法吗?
如果您打算使用子流程并且 shell=True 那么您的命令应该读作
subprocess.call(['hadoop fs -copyFromLocal /tmp/mike/test* hdfs:///user/edwaeadt/app'], shell=True)
我有一个脚本来检查目录中的文件。如果存在正确的文件(带关键字),我想将 that/those 个文件移动到 HDFS 位置。
import os
tRoot = "/tmp/mike"
keyword = "test"
for root, dirs, files in os.walk(tRoot):
for file in files:
if keyword in file:
fullPath = str(os.path.join(root, file))
subprocess.call(['hdfs', 'dfs', '-copyFromLocal','/tmp/mike/test*','hdfs:///user/edwaeadt/app'], shell=True)
我看到以下错误:
Usage: hdfs [--config confdir] [--loglevel loglevel] COMMAND
我也试过
subprocess.call(['hadoop', 'fs', '-copyFromLocal', '/tmp/mike/test*', 'hdfs:///user/edwaeadt/app'], shell=True)
但我看到了
Usage: hadoop [--config confdir] [COMMAND | CLASSNAME]
CLASSNAME
此外,这个循环似乎是 运行 3 次。因为我现在看到文件已移至 hdfs 位置,但我也看到两次它表示文件存在。好像这个 copyFromLocal 是 运行 3 次。有什么想法吗?
如果您打算使用子流程并且 shell=True 那么您的命令应该读作
subprocess.call(['hadoop fs -copyFromLocal /tmp/mike/test* hdfs:///user/edwaeadt/app'], shell=True)