SQL
SQL module for XTDB built on Apache Calcite.
This document describes setup and configuration for the SQL module. To query using the SQL module, see the SQL Query Reference.
Connecting
You can either obtain a JDBC connection in-process, or start a server port and connect through a number of external SQL tools.
To get a connection in-process, call xtdb.calcite/jdbc-connection
, passing it an XTDB node:
(require '[xtdb.calcite])
(with-open [conn (xtdb.calcite/jdbc-connection node)]
;; ...
)
SQL server
We use Apache Avatica to open up a SQL server port.
Add the following to your node configuration:
{
...
"xtdb.calcite/server": {
"port": 1501
}
}
{...
:xtdb.calcite/server {:port 1501}}
{...
:xtdb.calcite/server {:port 1501}}
Properties
-
port
(int, default 1501) -
scan-only?
(boolean, default false): only use table scans in queries
Connecting via JDBC
Add to the Avatica SQL driver to your project and use the connection string:
jdbc:avatica:remote:url=http://<server-hostname>:1501;serialization=protobuf;timeZone=UTC
You can then connect using the Avatica JDBC driver, for example:
(java.sql.DriverManager/getConnection "jdbc:avatica:remote:url=http://localhost:1501;serialization=protobuf;timeZone=UTC")
SQL Query Reference
See the SQL Query Reference.