Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

python - ptrepack sortby needs 'full' index

I am trying to ptrepack a HDF file that was created with pandas HDFStore pytables interface. The main index of the dataframe was time but I made some more columns data_columns so that I can filter for data on-disk via these data_columns.

Now I would like to sort the HDF file by one of those columns (because the selection is too slow for my taste, 84 GB file), using ptrepack with the sortby option like so:

()[maye@luna4 .../nominal]$ ptrepack --chunkshape=auto --propindexes --complevel=9 --complib=blosc --sortby=clat C9.h5 C9_sorted.h5

and I get the error message:

()[maye@luna4 .../nominal]$ Problems doing the copy from 'C9.h5:/' to 'C9_sorted.h5:/' The error was --> : Field clat must have associated a 'full' index in table /df/table (Table(390557601,)) ''. The destination file looks like: C9_sorted.h5 (File) '' Last modif.: 'Fri Jul 26 18:17:56 2013' Object Tree: / (RootGroup) '' /df (Group) '' /df/table (Table(0,), shuffle, blosc(9)) ''

Traceback (most recent call last): File "/usr/local/epd/bin/ptrepack", line 10, in sys.exit(main()) File "/usr/local/epd/lib/python2.7/site-packages/tables/scripts/ptrepack.py", line 480, in main upgradeflavors=upgradeflavors) File "/usr/local/epd/lib/python2.7/site-packages/tables/scripts/ptrepack.py", line 225, in copyChildren raise RuntimeError("Please check that the node names are not " RuntimeError: Please check that the node names are not duplicated in destination, and if so, add the --overwrite-nodes flag if desired. In particular, pay attention that rootUEP is not fooling you.

Does this mean, that I can not sort a HDF file by an index column, because they are not 'full' indexes?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have tested several of the options Jeff mentions in our chatty discussions above.

Please have a look at this notebook, hopefully it will help you to make relevant decisions for your data storage: https://nbviewer.ipython.org/810bd0720bb1732067ff The gist for the notebook is here: https://gist.github.com/michaelaye/810bd0720bb1732067ff

My main conclusions:

  • Using index=False has several impressive effects:
    1. It reduces the file size of the resulting HDF file.
    2. It creates the HDF file much faster.
    3. Even so ptdump and the storer().group.table print-out does not show any index, the store display still shows indexers and data-columns (That's probably ignorance of the pytables machinery on my side).
  • Creating an index via store.create_table_index() does nothing yet to the speed of data selection via one of the data-columns.
  • This index HAS to be a 'full' index, so that the later ptrepack with --sortby does not bail. But it does NOT have to be a index level 9. The default level 6 is fine, and does not seem to influence the data selection speed significantly. Maybe it would though with many columns?
  • Using --propindexes almost doubles the ptrepacking time with a slight improvement in data selection speed.
  • Using compression and --propindexs is only slightly slower than using --propindex alone, while the data size (at least in this example) does not go down dramatically.
  • The data selection speed does not seem to be hugely different by having used compression.
  • the speedup for this example of 1 mio. lines of 2 columns random data by just using --sortby without --propindexes is approx factor 5 after sorting for the column of selection.

For completion, the ultra-short summary of commands:

df = pd.DataFrame(randn(1e6,2),columns=list('AB')).to_hdf('test.h5','df',
                  data_columns=list('AB'),mode='w',table=True,index=False)
store = pd.HDFStore('test.h5')
store.create_table_index('df',columns=['B'], kind='full')
store.close()

And in the shell:

ptrepack --chunkshape=auto --sortby=B test.h5 test_sorted.h5

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...