Search code examples
pythonhadoophdfssnakebite

Snakebite HDFS touchz not working


I want to use snakebite to check if a file exist in hdfs directory, and create if it doesnt exist. I'm following the documentation on touchz here and using it like this:

def createFile(client):
    if client.test("/user/test/sample.txt", exists=True):
        print "file exists"
    else:
        print "file not exist, create file"
        print client.touchz(["/user/test/sample.txt"])

client = Client(remote_host, 8020, use_trash=False)        
createFile(client)

But when I go to check, I dont see sample.txt in remote_host:/user/test/ But I see the file when I used hadoop fs -touchz remote_host:/user/test/sample.txt

How to use snakebite's touchz ?


Solution

  • snakebite's touchz yields a generator that doesn't do anything until you iterate over the values.

    So you either have to iterate over the return value of touchz or call list() on it.