ODBC (Open Database Connectivity) is a standard API for connecting applications to various database management systems using a common interface. To connect to any ODBC database for federated/accelerated SQL queries, specify odbc as the selector in the from value for the dataset. The odbc_connection_string parameter is required.
:::warning
Spice must be built with the odbc feature, and the host/container must have a valid ODBC configuration.
Alternatively, use the official Spice Docker image. To use the official Spice Docker image from DockerHub:
:::
An ODBC connection requires a compatible ODBC driver and valid driver configuration. ODBC drivers are available from their respective vendors. Here are a few examples:
Non-Windows systems additionally require the installation of an ODBC Driver Manager like unixodbc.
sudo apt-get install unixodbcbrew install unixodbc:::info
For the best JOIN performance, ensure all ODBC datasets from the same database are configured with the exact same odbc_connection_string in Spice.
:::
The ODBC connection string requires the use of an installed and registered driver based on your system type:
/etc/odbc.ini or /etc/odbcinst.ini. For example, in the Databricks DSN Connection Setup Guide for Linux.For an example Unix system with an installed PostgreSQL driver where the contents of /etc/odbcinst.ini is:
The Spice Runtime can use this driver installation where Driver={PostgreSQL Unicode} is used in the connection string, like:
fromThe from field takes the form odbc:path.to.my.dataset where path.to.my.dataset is the table name in the ODBC-supporting server to read from.
nameThe dataset name. This will be used as the table name within Spice.
Example:
The dataset name cannot be a reserved keyword.
params| Parameter | Type | Description |
|---|---|---|
sql_dialect | string | Override what SQL dialect is used for the ODBC connection. Supports postgresql, mysql, sqlite, athena or databricks values. Default is unset (auto-detected). |
odbc_max_bytes_per_batch | number (bytes) | Maximum number of bytes transferred in each query record batch. A lower value may improve performance on low-memory systems. Default is 512_000_000. |
odbc_max_num_rows_per_batch | number (rows) | Maximum number of rows transferred in each query record batch. A higher value may speed up query results, but requires more memory in conjunction with odbc_max_bytes_per_batch. Default is 65536. |
odbc_max_text_size | number (bytes) | A limit for the maximum size of text columns transmitted between the ODBC driver and the Runtime. Default is unset (allocates driver-reported max column size). |
odbc_max_binary_size |
The default SQL dialect may not be supported by every ODBC connection. The sql_dialect parameter supports overriding the selected SQL dialect for a specified connection.
The runtime will attempt to detect the dialect to use for a connection based on the contents of Driver= in the odbc_connection_string. The runtime will detect the correct SQL dialect for the following connection types, when setup with a standard driver configuration:
These connection types are also the supported values for overriding dialect in sql_dialect, in lowercase format: postgresql, mysql, sqlite, databricks, athena. For example, overriding the dialect for your connection to a postgresql style dialect:
ODBC support is not included in the released binaries. To use ODBC with Spice, you need to checkout and compile the code with the --features odbc flag (cargo build --release --features odbc).
Alternatively, use the official Spice Docker image. To use the official Spice Docker image from DockerHub:
There are many dozens of ODBC adapters; this recipe covers making a custom image and configuring it to work with Spice.
Build the container:
Validate that the ODBC configuration was updated to reference the newly installed driver:
:::warning[Note]
Since libsqliteodbc is vendored by Debian, the package install hooks append the driver configuration to /etc/odbcinst.ini. When using a custom driver (e.g. Databricks Simba), it is your responsibility to update /etc/odbcinst.ini to point at the location of the newly installed driver.
:::
test.dbTo fully test the image, make an example SQLite database (test.db) and spicepod on your host:
spicepod.yamlMake sure that the DRIVER parameter matches the name of the driver section in odbcinst.ini.
All together now:
Ensure that the Postgres ODBC driver is installed. On Unix systems, this will create an entry in /etc/odbcinst.ini similar to:
Then, in your spicepod.yaml the odbc_connection_string parameter can be used for the ODBC connection string:
See the ODBC Cookbook for more help on getting started with ODBC and Postgres.
Spice integrates with multiple secret stores to help manage sensitive data securely. For detailed information on supported secret stores, refer to the secret stores documentation. Additionally, learn how to use referenced secrets in component parameters by visiting the using referenced secrets guide.
| number (bytes) |
| A limit for the maximum size of binary columns transmitted between the ODBC driver and the Runtime. Default is unset (allocates driver-reported max column size). |
odbc_connection_string | string | Connection string to use to connect to the ODBC server |