Package: zindex-py
DISCLAIMERThis repo is a fork of the original repo located athttps://github.com/mattgodbolt/zindex.
We modify this repo for using it cohesively with DLIO Profilerhttps://github.com/hariharan-devarajan/dlio-profiler.zindexcreates and queries an index on a compressed, line-based text file in a
time- and space-efficient way.The itch I hadI have many multigigabyte text gzipped log files and I'd like to be able to find data in them by an index.
There's a key on each line that a simple regex can pull out. However, to find a
particular record requireszgrep, which takes ages as it has to seek through
gigabytes of previous data to get to each record.Enterzindexwhich builds an index and also stores decompression checkpoints along the way
which allows lightning fast random access. Pulling out single lines by either
line number of by an index entry is then almost instant, even for huge files. The indices
themselves are small too, typically ~10% of the compressed file size for a simple unique
numeric index.Creating an indexzindexneeds to be told what part of each line constitutes the index. This can be done by
a regular expression, by field, or by piping each line through an external program.By default zindex creates an index offile.gz.zindexwhen asked to indexfile.gz.Example: create an index on lines matching a numeric regular expression. The capture group
indicates the part that's to be indexed, and the options show each line has a unique, numeric index.$zindexfile.gz--regex'id:([0-9]+)'--numeric--uniqueExample: create an index on the second field of a CSV file:$zindexfile.gz--delimiter,--field2Example: create an index on a JSON fieldorderId.idin any of the items in the document root'sactionsarray (requiresjq).
Thejqquery creates an array of all theorderId.ids, thenjoins them with a space to ensure each individual line piped to jq creates a single line of output,
with multiple matches separated by spaces (which is the default separator).$zindexfile.gz--pipe"jq --raw-output --unbuffered '[.actions[].orderId.id] | join(\" \")'"Multiple indices, and configuration of the index creation by JSON configuration file are supported, see below.Querying the indexThezqprogram is used to query an index.  It's given the name of the compressed file and a list of queries. For example:$zqfile.gz10234443554It's also possible to output by line number, so to print lines 1 and 1000 from a file:$zqfile.gz--line11000Building from sourcezindexuses CMake for its basic building (though has a bootstrappingMakefile), and requires a C++11 compatible compiler (GCC 4.8 or above and clang 3.4 and above). It also requireszlib. With the relevant compiler available, building ought to be as simple as:$gitclonehttps://github.com/mattgodbolt/zindex.git
$cdzindex
$makeBinaries are left inbuild/Release.Additionally a static binary can be built if you're happy to dip your toe into CMake:$cdpath/to/build/directory
$cmakepath/to/zindex/checkout/dir-DStatic:BOOL=On-DCMAKE_BUILD_TYPE=Release
$makeMultiple indicesTo support more than one index, or for easier configuration than all the command-line flags that might be
needed, there is a JSON configuration format. Pass the--config <yourconfigfile>.jsonoption and put something like this in the configuration file:{ 
    "indexes": [
        {
            "type": "field",
            "delimiter": "\t",
            "fieldNum": 1
        },
        {
            "name": "secondary",
            "type": "field",
            "delimiter": "\t",
            "fieldNum": 2
        }
    ]
}This creates two indices, one on the first field and one on the second field, as delimited by tabs. One can
then specify which index to query with the-i <index>option ofzq.Issues and feature requestsSee theissue trackerfor TODOs and known bugs. Please raise bugs there, and feel free to submit suggestions there also.Feel free tocontact meif you prefer email over bug trackers.