4

hdfs のthrift IDL から、次の唯一の記述定義が表示されます (バージョン: Hadoop-0.20):

// write a string to the open handle for the file
bool write(1:ThriftHandle handle, string data) throws (1:ThriftIOException ouch),

データは文字列型で、圧縮ファイルを書き込もうとすると機能しません。tar.gzとにかく、先に進み、上記の API を使用してファイルを書き込もうとしました。

    pathName = ttypes.Pathname(os.path.join("/tmp", "data.tar.gz"))
    fd = open("data.tar.gz", "rb")
    thirftHandle = self.__client.create(pathName)
    b = fd.read(1)
    while b:
        self.__client.write(thirftHandle, b)
        b = fd.read(1)

    self.__client.close(thirftHandle)

スクリプトは正常に機能し、ファイルは HDFS で作成されましたが、次のコマンドを使用して取得しようとしたとき:

hadoop dfs -get /tmp/data.tar.gz .

解凍しようとすると、予想どおり破損しています。

倹約でバイナリデータを hdfs に書き込む方法はありませんか?

4

0 に答える 0