Skip to content

Commit d6c93a7

Browse files
committed
New HsqlDB connector
1 parent 8e64aa5 commit d6c93a7

File tree

21 files changed

+3161
-0
lines changed

21 files changed

+3161
-0
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ jobs:
370370
!:trino-hdfs,
371371
!:trino-hive,
372372
!:trino-hive-formats,
373+
!:trino-hsqldb,
373374
!:trino-hudi,
374375
!:trino-iceberg,
375376
!:trino-ignite,
Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
---
2+
myst:
3+
substitutions:
4+
default_domain_compaction_threshold: '`256`'
5+
---
6+
7+
# HsqlDB connector
8+
9+
```{raw} html
10+
<img src="../_static/img/hsqldb.png" class="connector-logo">
11+
```
12+
13+
The HsqlDB connector allows querying and creating tables in an external HsqlDB
14+
database.
15+
16+
## Requirements
17+
18+
To connect to HsqlDB, you need:
19+
20+
- HsqlDB version 2.7.4 or higher.
21+
- Network access from the Trino coordinator and workers to HsqlDB. Port
22+
9001 is the default port.
23+
24+
## Configuration
25+
26+
To configure the HsqlDB connector, create a catalog properties file in
27+
`etc/catalog` named, for example, `example.properties`, to mount the HsqlDB
28+
connector as the `example` catalog. Create the file with the following
29+
contents, replacing the connection properties as appropriate for your setup:
30+
31+
```text
32+
connector.name=hsqldb
33+
connection-url=jdbc:hsqldb:hsql://localhost:9001/
34+
connection-user=SA
35+
connection-password=
36+
```
37+
38+
The `connection-user` and `connection-password` are typically required and
39+
determine the user credentials for the connection, often a service user. You can
40+
use {doc}`secrets </security/secrets>` to avoid actual values in the catalog
41+
properties files.
42+
43+
```{include} jdbc-authentication.fragment
44+
```
45+
46+
```{include} jdbc-common-configurations.fragment
47+
```
48+
49+
```{include} jdbc-domain-compaction-threshold.fragment
50+
```
51+
52+
```{include} jdbc-case-insensitive-matching.fragment
53+
```
54+
55+
## Querying HsqlDB
56+
57+
The HsqlDB connector provides a catalog for every HsqlDB *database* (ie: every catalog properties file).
58+
You can see the available HsqlDB databases by running `SHOW CATALOGS`:
59+
60+
```
61+
SHOW CATALOGS;
62+
```
63+
64+
If you have a HsqlDB schema named `web`, you can view the tables
65+
in this schema by running `SHOW TABLES`:
66+
67+
```
68+
SHOW TABLES FROM example.web;
69+
```
70+
71+
You can see a list of the columns in the `clicks` table in the `web`
72+
schema using either of the following:
73+
74+
```
75+
DESCRIBE example.web.clicks;
76+
SHOW COLUMNS FROM example.web.clicks;
77+
```
78+
79+
Finally, you can access the `clicks` table in the `web` database:
80+
81+
```
82+
SELECT * FROM example.web.clicks;
83+
```
84+
85+
If you used a different name for your catalog properties file, use
86+
that catalog name instead of `example` in the above examples.
87+
88+
% hsqldb-type-mapping:
89+
90+
## Type mapping
91+
92+
Because Trino and HsqlDB each support types that the other does not, this
93+
connector {ref}`modifies some types <type-mapping-overview>` when reading or
94+
writing data. Data types may not map the same way in both directions between
95+
Trino and the data source. Refer to the following sections for type mapping in
96+
each direction.
97+
98+
### HsqlDB type to Trino type mapping
99+
100+
The connector maps HsqlDB types to the corresponding Trino types according
101+
to the following table:
102+
103+
:::{list-table} HsqlDB type to Trino type mapping
104+
:widths: 30, 30, 50
105+
:header-rows: 1
106+
107+
* - HsqlDB type
108+
- Trino type
109+
- Notes
110+
* - `BOOLEAN`
111+
- `BOOLEAN`
112+
-
113+
* - `TINYINT`
114+
- `TINYINT`
115+
-
116+
* - `SMALLINT`
117+
- `SMALLINT`
118+
-
119+
* - `INTEGER` or `INT`
120+
- `INTEGER`
121+
-
122+
* - `BIGINT`
123+
- `BIGINT`
124+
-
125+
* - `DOUBLE` or `FLOAT`
126+
- `DOUBLE`
127+
-
128+
* - `DECIMAL(p,s)`
129+
- `DECIMAL(p,s)`
130+
-
131+
* - `CHAR(n)`
132+
- `CHAR(n)`
133+
-
134+
* - `VARCHAR(n)`
135+
- `VARCHAR(n)`
136+
-
137+
* - `CLOB(n)`
138+
- `VARCHAR(n)`
139+
-
140+
- `BINARY(n)`
141+
- `VARBINARY`
142+
-
143+
* - `VARBINARY(n)`
144+
- `VARBINARY`
145+
-
146+
* - `BLOB(n)`
147+
- `VARBINARY`
148+
-
149+
* - `UUID`
150+
- `UUID`
151+
-
152+
* - `DATE`
153+
- `DATE`
154+
-
155+
* - `TIME(n)`
156+
- `TIME(n)`
157+
-
158+
* - `TIME(n) WITH TIMEZONE`
159+
- `TIME(n) WITH TIMEZONE`
160+
-
161+
* - `TIMESTAMP(n)`
162+
- `TIMESTAMP(n)`
163+
-
164+
* - `TIMESTAMP(n) WITH TIMEZONE`
165+
- `TIMESTAMP(n) WITH TIMEZONE`
166+
-
167+
* - `INTERVAL`
168+
- `INTERVAL`
169+
-
170+
:::
171+
172+
No other types are supported.
173+
174+
### Trino type mapping to HsqlDB type mapping
175+
176+
The connector maps Trino types to the corresponding HsqlDB types according
177+
to the following table:
178+
179+
:::{list-table} Trino type mapping to HsqlDB type mapping
180+
:widths: 30, 25, 50
181+
:header-rows: 1
182+
183+
* - Trino type
184+
- HsqlDB type
185+
- Notes
186+
* - `BOOLEAN`
187+
- `BOOLEAN`
188+
-
189+
* - `TINYINT`
190+
- `TINYINT`
191+
-
192+
* - `SMALLINT`
193+
- `SMALLINT`
194+
-
195+
* - `INTEGER`
196+
- `INTEGER`
197+
-
198+
* - `BIGINT`
199+
- `BIGINT`
200+
-
201+
* - `DOUBLE`
202+
- `DOUBLE`
203+
-
204+
* - `DECIMAL(p,s)`
205+
- `DECIMAL(p,s)`
206+
-
207+
* - `CHAR(n)`
208+
- `CHAR(n)`
209+
-
210+
* - `VARCHAR(n)`
211+
- `VARCHAR(n)`
212+
-
213+
* - `VARBINARY`
214+
- `VARBINARY(32768)`
215+
-
216+
* - `UUID`
217+
- `UUID`
218+
-
219+
* - `DATE`
220+
- `DATE`
221+
-
222+
* - `TIME(n)`
223+
- `TIME(n)`
224+
-
225+
* - `TIME(n) WITH TIMEZONE`
226+
- `TIME(n) WITH TIMEZONE`
227+
-
228+
* - `TIMESTAMP(n)`
229+
- `TIMESTAMP(n)`
230+
-
231+
* - `TIMESTAMP(n) WITH TIMEZONE`
232+
- `TIMESTAMP(n) WITH TIMEZONE`
233+
-
234+
* - `INTERVAL`
235+
- `INTERVAL`
236+
-
237+
238+
:::
239+
240+
No other types are supported.
241+
242+
Complete list of [HsqlDB data types](https://hsqldb.org/doc/2.0/guide/guide.html#sgc_data_type_guide).
243+
244+
```{include} jdbc-type-mapping.fragment
245+
```
246+
247+
(hsqldb-sql-support)=
248+
## SQL support
249+
250+
The connector provides read access and write access to data and metadata in a
251+
HsqlDB database. In addition to the [globally
252+
available](sql-globally-available) and [read operation](sql-read-operations)
253+
statements, the connector supports the following features:
254+
255+
- [](/sql/insert), see also [](hsqldb-insert)
256+
- [](/sql/update), see also [](hsqldb-update)
257+
- [](/sql/delete), see also [](hsqldb-delete)
258+
- [](/sql/truncate)
259+
- [](/sql/create-table)
260+
- [](/sql/create-table-as)
261+
- [](/sql/drop-table)
262+
- [](/sql/alter-table)
263+
- [](/sql/create-schema)
264+
- [](/sql/drop-schema)
265+
- [](hsqldb-procedures)
266+
- [](hsqldb-table-functions)
267+
268+
(hsqldb-insert)=
269+
```{include} non-transactional-insert.fragment
270+
```
271+
272+
(hsqldb-update)=
273+
```{include} sql-update-limitation.fragment
274+
```
275+
276+
(hsqldb-delete)=
277+
```{include} sql-delete-limitation.fragment
278+
```
279+
280+
(hsqldb-procedures)=
281+
### Procedures
282+
283+
```{include} jdbc-procedures-flush.fragment
284+
```
285+
```{include} procedures-execute.fragment
286+
```
287+
288+
(hsqldb-table-functions)=
289+
### Table functions
290+
291+
The connector provides specific {doc}`table functions </functions/table>` to
292+
access HsqlDB.
293+
294+
(hsqldb-query-function)=
295+
#### `query(varchar) -> table`
296+
297+
The `query` function allows you to query the underlying database directly. It
298+
requires syntax native to HsqlDB, because the full query is pushed down and
299+
processed in HsqlDB. This can be useful for accessing native features which are
300+
not available in Trino or for improving query performance in situations where
301+
running a query natively may be faster.
302+
303+
```{include} query-passthrough-warning.fragment
304+
```
305+
306+
As an example, query the `example` catalog and select the age of employees in `public` schema by
307+
using `TIMESTAMPDIFF` and `CURRENT_DATE`:
308+
309+
```
310+
SELECT
311+
age
312+
FROM
313+
TABLE(
314+
example.system.query(
315+
query => 'SELECT
316+
TIMESTAMPDIFF(
317+
SQL_TSI_YEAR,
318+
date_of_birth,
319+
CURRENT_DATE
320+
) AS age
321+
FROM
322+
example.public.employees'
323+
)
324+
);
325+
```
326+
327+
```{include} query-table-function-ordering.fragment
328+
```
5.49 KB
Loading

0 commit comments

Comments
 (0)