sqlite-parquet-vtable/README.md

121 lines
3.2 KiB
Markdown
Raw Normal View History

2018-03-04 01:26:41 +00:00
# sqlite-parquet-vtable
[![Build Status](https://travis-ci.org/cldellow/sqlite-parquet-vtable.svg?branch=master)](https://travis-ci.org/cldellow/sqlite-parquet-vtable)
2018-07-05 22:54:05 +00:00
[![codecov](https://codecov.io/gh/cldellow/sqlite-parquet-vtable/branch/master/graph/badge.svg)](https://codecov.io/gh/cldellow/sqlite-parquet-vtable)
2018-06-24 03:58:13 +00:00
A SQLite [virtual table](https://sqlite.org/vtab.html) extension to expose Parquet files as SQL tables. You may also find [csv2parquet](https://github.com/cldellow/csv2parquet/) useful.
2018-06-24 15:39:44 +00:00
This [blog post](https://cldellow.com/2018/06/22/sqlite-parquet-vtable.html) provides some context on why you might use this.
## Installing
### Download
2018-03-18 19:08:02 +00:00
2018-03-25 04:07:56 +00:00
You can fetch a version built for Ubuntu 16.04 at https://s3.amazonaws.com/cldellow/public/libparquet/libparquet.so.xz
2018-03-18 19:08:02 +00:00
### Building
```
./make-linux
```
The first run will git clone a bunch of libraries, patch them to be statically linkable and build them.
Subsequent builds will only build the parquet virtual table extension.
### Building (release)
2018-10-02 15:42:43 +00:00
Run `./make-linux-pgo` to build an instrumented binary, run tests to collect real-life usage samples, then build an optimized binary. PGO seems to give a 5-10% reduction in query times.
### Tests
Run:
```
tests/create-queries-from-templates
tests/test-all
```
## Use
```
$ sqlite/sqlite3
sqlite> .load build/linux/libparquet
2018-03-18 19:08:02 +00:00
sqlite> CREATE VIRTUAL TABLE demo USING parquet('parquet-generator/99-rows-1.parquet');
2018-03-04 18:06:50 +00:00
sqlite> SELECT * FROM demo;
...if all goes well, you'll see data here!...
```
2018-03-04 01:26:41 +00:00
2018-03-18 22:25:08 +00:00
Note: if you get an error like:
```
sqlite> .load build/linux/libparquet
2018-03-18 22:25:08 +00:00
Error: parquet/libparquet.so: wrong ELF class: ELFCLASS64
```
You have the 32-bit SQLite installed. To fix this, do:
```
sudo apt-get remove --purge sqlite3
sudo apt-get install sqlite3:amd64
```
2018-03-04 01:26:41 +00:00
## Supported features
2018-03-16 20:30:05 +00:00
### Row group filtering
2018-03-04 01:26:41 +00:00
2018-03-16 20:30:05 +00:00
Row group filtering is supported for strings and numerics so long as the SQLite
type matches the Parquet type.
e.g. if you have a column `foo` that is an INT32, this query will skip row groups whose
statistics prove that it does not contain relevant rows:
```
SELECT * FROM tbl WHERE foo = 123;
```
but this query will devolve to a table scan:
```
SELECT * FROM tbl WHERE foo = '123';
```
This is laziness on my part and could be fixed without too much effort.
### Row filtering
For common constraints, the row is checked to see if it satisfies the query's
constraints before returning control to SQLite's virtual machine. This minimizes
the number of allocations performed when many rows are filtered out by
the user's criteria.
2018-03-04 01:26:41 +00:00
### Memoized slices
Individual clauses are mapped to the row groups they match.
eg going on row group statistics, which store minimum and maximum values, a clause
like `WHERE city = 'Dawson Creek'` may match 80% of row groups.
In reality, it may only be present in one or two row groups.
This is recorded in a shadow table so future queries that contain that clause
can read only the necessary row groups.
2018-03-04 01:26:41 +00:00
### Types
2018-03-16 20:30:05 +00:00
These Parquet types are supported:
2018-03-04 01:26:41 +00:00
* INT96 timestamps (exposed as milliseconds since the epoch)
* INT8/INT16/INT32/INT64
* UTF8 strings
* BOOLEAN
* FLOAT
* DOUBLE
2018-03-04 22:20:28 +00:00
* Variable- and fixed-length byte arrays
2018-03-04 01:26:41 +00:00
2018-03-16 20:30:05 +00:00
These are not currently supported:
2018-03-04 01:26:41 +00:00
* UINT8/UINT16/UINT32/UINT64
* DECIMAL