Skip to content

Commit

Permalink
Fix error uploading offset datetime (#263)
Browse files Browse the repository at this point in the history
* Fix error uploading offset datetime

### Description

Without this change Metabase will throw the following error when uploading a CSV with a datetime with an offset value:

```
class java.time.OffsetDateTime` cannot be cast to class `java.lang.String`
```

This is because we were missing a case in the insert method, and it was falling through the the catch all case. The first fix is to add an explicit case for this type to fix the JDBC integration.

The second fix is to update the config for how we map CSV columns to database types in particular. Since Clickhouse does not preserve the input offset, we made the product choice to keep these values as their raw input string. By returning `nil` for this type we can trigger this behavior.

* Fix fall through case
  • Loading branch information
crisptrutski authored Aug 20, 2024
1 parent 01ecc5f commit b1557fa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/metabase/driver/clickhouse.clj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
::upload/boolean "Nullable(Boolean)"
::upload/date "Nullable(Date32)"
::upload/datetime "Nullable(DateTime64(3))"
::upload/offset-datetime "Nullable(DateTime64(3))"))
::upload/offset-datetime nil))

(defmethod driver/table-name-length-limit :clickhouse
[_driver]
Expand Down Expand Up @@ -266,7 +266,8 @@
java.math.BigInteger (.setObject ps idx v)
java.time.LocalDate (.setObject ps idx v)
java.time.LocalDateTime (.setObject ps idx v)
(.setString ps idx v)))
java.time.OffsetDateTime (.setObject ps idx v)
(.setString ps idx (.toString v))))
(.addBatch ps)))
(doall (.executeBatch ps))))))))

Expand Down

0 comments on commit b1557fa

Please sign in to comment.