Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datatime in mysql 8 not supported by InstantColumn #1241

Open
Robert-Qiu opened this issue Nov 19, 2023 · 2 comments
Open

datatime in mysql 8 not supported by InstantColumn #1241

Robert-Qiu opened this issue Nov 19, 2023 · 2 comments

Comments

@Robert-Qiu
Copy link

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
Copy link

frankwondon commented Nov 19, 2023 via email

@ccleva
Copy link
Contributor

ccleva commented Dec 15, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants