this question 다음에 bz2 압축 json 파일을 40 GB TAR file에 PostgreSQL으로로드하려고합니다.TAR 파일을로드하고 bzcat으로 sdout에 압축을 풉니 다.
위에서 언급 한 대답에 따라 프로세스를 분리하고 외부 도구를 사용하여 다음 흐름을 생성하려고합니다. (TAR은 윈도우 빌드에서 추출 포함하지 않는 한,이 경우 bsdtar)
- 열기 &은 * .bz2로 파일을 TAR와 SDOUT 할 수있는 파일의 압축을 풉니 다.
- 오픈이 트윗과 출력에 들어오는 각 라인을 매핑 내 파이썬 스크립트 'file_handling'이이 CSV로 stdout에
- 은 (sdout 수출을) bzcat에 대한 호출로 *의 BZ2 파일의 압축을 풉니 다
- 이것을 하나의 COPY 명령으로로드하기 위해 PSQL로 파이프하십시오.
, 이것은 내가 위의 실행 그 라인을 구축 할 것입니다 :
pipeline = [filename[1:3] + " && ", # Change drive to H so that TAR can find the file without a drive name (doesn't like absolute paths, apparently).
'"C:\\Tools\\GnuWin32\\gnuwin32\\bin\\bsdtar" vxOf ' + filename_nodrive + ' "*.bz2"', # Call to tar, outputs to stdin
" | C:\\Tools\\GnuWin32\\gnuwin32\\bin\\bzcat.exe"#, # Forward its output to bzcat
' | python "D:\Cloud\Dropbox\Coding\GitHub\pyTwitter\pyTwitter_filehandling.py"', # Extract Tweets
' | "C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -1f copy.sql ' + secret_login_d
]
module_call = "".join(pipeline)
module_call = "H: && "C:\Tools\GnuWin32\gnuwin32\bin\bsdtar" vxOf "Twitter datastream/Sourcefiles/archiveteam-twitter-stream-2013-01.tar" "*.bz2" | C:\Tools\GnuWin32\gnuwin32\bin\bzcat.exe | python "D:\Cloud\Dropbox\Coding\GitHub\pyTwitter\pyTwitter_filehandling.py" | "C:\Program Files\PostgreSQL\9.4in\psql.exe" -1f copy.sql "user=xxx password=xxx host=localhost port=5432 dbname=xxxxxx""
TAR의 코드를 실행, tar 파일이 출력된다 CMD 프롬프트에 모든 것이 잘되어 있다는 것을 암시합니다.
x 01/29/06/39.json.bz2
bzcat.exe: Data integrity error when decompressing.
Input file = (stdin), output file = (stdout)
It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
-tvv을 실행하면 나에게 제공합니다 :
huff+mtf data integrity (CRC) error in data
나는 7-ZIP (GUI)와 같은 아카이브를 추출하기 위해 시도했다 :이 여전히 작동하지만, bzcat 라인에 오류가 제공합니다. 이 문제를 해결하는 방법에 대한 도움을 주시면 매우 감사하겠습니다. 나는 GNUWin32로 Windows 8.1을 돌리고있다.
감사 @MattV :
가장 좋은 대신 7-ZIP을 사용하는 것입니다! 내 작업에 매우 유용합니다. 아카이브에서이 메서드를 사용할 수 있도록 "file_handling"이라는 파이썬 코드를 공유 할 수 있습니까? 아마도 github 통해. 감사! –
이것은 오래전 일이었습니다. 여전히 좋은 생각이 들었습니다. https://gist.github.com/MVersteeg/bb4a754823e7609bd204acbdb479d37d – MattV
위대한 파이썬 코드에 대해 @MattV에 감사드립니다. 한가지 더 질문 : copy.sql 파일이 있습니까? 오랫동안 copy.sql을 작성하려고했지만 항상 "COPY 0"의 결과를 얻습니다. –