In order to run this example you need to set up a new environment on your machine. Follow these steps to do so (thanks to David Li!).
- Make sure you have miniconda installed on your machine.
- Install Mamba:
conda install -c conda-forge mamba
. - Now, create a new dev environment
$ mamba create -n flight-sql -c conda-forge python=3.9
$ conda activate flight-sql
$
- Build and install Arrow
$ cd scripts && ./install_arrow.sh
- Build and install
duckdb
. This is sometimes necessary as condacompilers
seem to be including incompatible GlibC library with the compiled binaries ofduckdb
.
$ ./install_duckdb.sh
- Get the data.
$ mkdir ../data
$ wget https://github.com/lovasoa/TPCH-sqlite/releases/download/v1.0/TPC-H-small.db -O ../data/TPC-H-small.db
- Create duckdb database.
$ ./get_duckdb_database.sh
- Build the example.
$ mkdir build && cd build
$ cmake .. -GNinja -DCMAKE_PREFIX_PATH=$CONDA_PREFIX/lib/cmake/arrow
$ ninja && ./flight_sql
This example allows chosing from two backends: SQLite and DuckDB. It defaults to DuckDB.
$ ./flight_sql
> duckdb server listening on localhost:31337
> Connected to server: localhost:31337
> Client created.
> ...
The above call is equivalent to running ./flight_sql -B duckdb
or ./flight_sql --backend duckdb
. To select SQLite run
$ ./flight_sql -B sqlite
or
$ ./flight_sql --backend sqlite
The above will produce the following:
> sqlite server listening on localhost:31337
> Connected to server: localhost:31337
> Client created.
> ...
This example defaults to running the queries but does not print out
the query itself nor does it print the results. To switch to printing
results and queries set the print
flag to true
.
$ ./flight_sql --print true
To see all the available options run ./flight.sql --help
.
> Allowed options:
> --help produce this help message
> -B [ --backend ] arg (=duckdb) Specify the database backend. Allowed options:
> duckdb, sqlite.
> --print arg (=false) Print the results of running queries. Allowed
> options: false, true.