Skip to content

Commit d77dda5

Browse files
committed
feat: support java.time.
1 parent 45b9a14 commit d77dda5

File tree

4 files changed

+307
-260
lines changed

4 files changed

+307
-260
lines changed

README.md

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
![Apache License 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)
44
[![databend-jdbc](https://img.shields.io/maven-central/v/com.databend/databend-jdbc?style=flat-square)](https://central.sonatype.dev/artifact/com.databend/databend-jdbc/0.0.1)
55

6+
## Highlights
7+
8+
- Databend-specific interfaces to stream files into tables or stages with `loadStreamToTable`, `uploadStream`, and `downloadStream`.
9+
- Temporal APIs use session timezone to avoid depending on JVM default zone and support modern `java.time`.
10+
611
## Prerequisites
712

813
The Databend JDBC driver requires Java 8 or later.
@@ -73,36 +78,60 @@ public class Main {
7378
you can call `while(r.next(){})` to iterate over the result set.
7479
3. For other SQL such as `create/drop table` non-query type SQL, you can call `statement.execute()` directly.
7580

76-
## JDBC Java type mapping
77-
The Databend type is mapped to Java type as follows:
7881

79-
| Databend Type | Java Type |
80-
|---------------|------------|
81-
| TINYINT | Byte |
82-
| SMALLINT | Short |
83-
| INT | Integer |
84-
| BIGINT | Long |
85-
| UInt8 | Short |
86-
| UInt16 | Integer |
87-
| UInt32 | Long |
88-
| UInt64 | BigInteger |
89-
| Float32 | Float |
90-
| Float64 | Double |
91-
| String | String |
92-
| Date | String |
93-
| TIMESTAMP | String |
94-
| Bitmap | byte[] |
95-
| Array | String |
96-
| Decimal | BigDecimal |
97-
| Tuple | String |
98-
| Map | String |
99-
| VARIANT | String |
82+
## Connection Parameters
10083

10184
For detailed references, please take a look at the following Links:
10285

10386
1. [Connection Parameters](./docs/Connection.md) : detailed documentation about how to use connection parameters in a
10487
jdbc connection
10588

89+
## JDBC Java type mapping
90+
The Databend type is mapped to Java type as follows:
91+
92+
| Databend Type | Java Type |
93+
|---------------|----------------|
94+
| TINYINT | Byte |
95+
| SMALLINT | Short |
96+
| INT | Integer |
97+
| BIGINT | Long |
98+
| UInt8 | Short |
99+
| UInt16 | Integer |
100+
| UInt32 | Long |
101+
| UInt64 | BigInteger |
102+
| Float32 | Float |
103+
| Float64 | Double |
104+
| Decimal | BigDecimal |
105+
| String | String |
106+
| Date | LocalDate |
107+
| TIMESTAMP | ZonedDateTime |
108+
| TIMESTAMP_TZ | OffsetDateTime |
109+
| Bitmap | byte[] |
110+
| Array | String |
111+
| Tuple | String |
112+
| Map | String |
113+
| VARIANT | String |
114+
115+
### Temporal types
116+
117+
we recommend using `java.time` to avoid ambiguity and letting the driver format values via these APIs:
118+
119+
```
120+
void setObject(int parameterIndex, Object x)
121+
<T> T getObject(int columnIndex, Class<T> type)
122+
```
123+
124+
- TIMESTAMP_TZ and TIMESTAMP map to `OffsetDateTime`, `ZonedDateTime`, `Instant` (TIMESTAMP_TZ can return `OffsetDateTime` but not `ZonedDateTime`), and `LocalDateTime`.
125+
- Date maps to `LocalDate`, and `getObject(..., LocalDate.class)` now mirrors what `getDate().toLocalDate()` returns.
126+
- When a TIMESTAMP literal omits a timezone, Databend uses the session timezone (not the JVM zone) when storing/returning dates on versions ≥0.4.3 driver + ≥1.2.844 server.
127+
128+
Timestamp/Date are also supported, note that:
129+
130+
- `getTimestamp(int, Calendar cal)` is the same as `getTimestamp(int)` (the cal is omitted) and
131+
`getObject(int, Instant.classes).toTimestamp()`
132+
- `setTimestamp(int, Calendar cal)` is diff with `setTimestamp(int)`, the epoch is adjusted according to timezone in cal
133+
- `setDate`/`getDate` still use the JVM timezone, and `setObject(localDate)` is equivalent to `setDate(Date.valueOf(localDate))`.
134+
106135

107136
# Unwrapping to Databend-specific interfaces
108137

@@ -171,4 +200,3 @@ Download a single file in the stage as `InputStream`
171200
```
172201
InputStream downloadStream(String stageName, String filePathInStage) throws SQLException;
173202
```
174-

0 commit comments

Comments
 (0)