jtablesaw / tablesaw

Java dataframe and visualization library
https://jtablesaw.github.io/tablesaw/
Apache License 2.0
3.55k stars 643 forks source link

datatime in mysql 8 not supported by InstantColumn #1241

Open rqwj opened 1 year ago

rqwj commented 1 year ago

the exception is

java.lang.IllegalArgumentException: Cannot append java.time.LocalDateTime to DateTimeColumn at tech.tablesaw.api.InstantColumn.appendObj(InstantColumn.java:276) at tech.tablesaw.api.InstantColumn.appendObj(InstantColumn.java:60)

I study the code, it seems that InstantColumn not support LocalDateTime type

@Override public InstantColumn appendObj(Object obj) { if (obj == null) { return appendMissing(); } if (obj instanceof Instant) { return append((Instant) obj); } if (obj instanceof Timestamp) { Timestamp timestamp = (Timestamp) obj; return append(timestamp.toInstant()); } throw new IllegalArgumentException( "Cannot append " + obj.getClass().getName() + " to DateTimeColumn"); }

frankwondon commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

ccleva commented 11 months ago

Hi @Robert-Qiu. It seems the jdbc driver reports the ColumnType as TIMESTAMP and returns a LocalDateTime object (instead of a java.sql.Timestamp) for DATETIME columns.

This is currently not supported, but you should be able to force the column type by calling this before reading from the db:

SqlResultSetReader.mapJdbcTypeToColumnType(java.sql.Types.TIMESTAMP, ColumnType.LOCAL_DATE_TIME);

You should get a DateTimeColumn in the resulting Table, compatible with the LocalDateTime returned by the client.

I'm not able to test this right now, so please let us know if that solves your problem.