Skip to content

Add Date, POSIXct and hms types - #333

Merged
krlmlr merged 16 commits into
r-dbi:masterfrom
anderic1:alt_types
Jan 19, 2021
Merged

krlmlr merged 16 commits into
r-dbi:masterfrom
anderic1:alt_types

Conversation

@anderic1

Copy link
Copy Markdown
Contributor

Following #319 this PR adds support for Date, datetime and hms types. It depends on BH package version 1.75.0-0 which is not yet on CRAN.
The new option extended_types is set to TRUE by default in the dbConnect() method but could be set to FALSE to return to the old behaviour.

@krlmlr

krlmlr commented Dec 22, 2020

Copy link
Copy Markdown
Member

Thanks for looking into it. Is there a timeline for BH 1.75?

Can we keep extended_types = FALSE for now?

@anderic1

anderic1 commented Dec 23, 2020 via email

Copy link
Copy Markdown
Contributor Author

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I took a closer look.

Is the implementation in line with the discussion in #237?

Comment thread src/SqliteResultImpl.cpp
Comment thread DESCRIPTION Outdated
pkgconfig,
Rcpp (>= 0.12.7)
Rcpp (>= 0.12.7),
hms

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit hesitant to bring in hms as a dependency here. Can we move to Suggests and load only if a connection with extended types is requested?

if (with_alt_types) {
DATA_TYPE decl_dt = get_decl_data_type();
if (decl_dt == DT_DATE || decl_dt == DT_DATETIME || decl_dt == DT_TIME) {
return decl_dt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that a declared data type overrides what's stored in the columns?

}
return dateval;
} else {
return static_cast<double>(sqlite3_column_int(get_stmt(), get_j()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the underlying data is an integer or a blob?

@krlmlr

krlmlr commented Dec 27, 2020

Copy link
Copy Markdown
Member

When done, we can enable many more DBItest tests that test for roundtrip for these data types.

@anderic1

anderic1 commented Dec 27, 2020 via email

Copy link
Copy Markdown
Contributor Author

@anderic1

anderic1 commented Jan 4, 2021

Copy link
Copy Markdown
Contributor Author

I addressed all but one of the issues you mentioned and added warnings when blobs are encountered. I did not yet address the columninfo for time columns. As I mentioned earlier, how should this be returned? Should the whole column be coerced into a list column? Or perhaps add a third column as you alluded to in the beginning? For simplicity I think keeping just "hms"for time columns and "POSIXct" for datetime columns is the easiest and conveys sufficient information, but you be the judge.

@krlmlr

krlmlr commented Jan 4, 2021

Copy link
Copy Markdown
Member

Thanks. Could you please rerun (e.g. merge with master) when BH 1.75 becomes available on CRAN?

The class needs to be c("hms", "difftime"), for the column info the first component should be sufficient -- don't need to convert to a list here.

@anderic1

anderic1 commented Jan 4, 2021

Copy link
Copy Markdown
Contributor Author

One last thing, would you mind if I changed the default value of extended_types to something like extended_types = getOption("RSQLite_extended_types", FALSE)? That way it can easily be enabled globally if one so wishes.

@anderic1

Copy link
Copy Markdown
Contributor Author

BH has been updated on cran.
Some checks are still failing, the Windows and Mac images have not yet been updated it seems.
The extended_types setting is set to FALSE by default, but can be overridden by setting options(RSQLite_extended_types = TRUE). Some changes were also needed to fix checks on all platforms.

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. Just a few minor tweaks necessary.

Comment thread R/connect.R Outdated
Comment thread R/connect.R Outdated
Comment thread src/DbColumnStorage.cpp Outdated
anderic1 and others added 4 commits January 18, 2021 16:13
Co-authored-by: Kirill Müller <krlmlr@users.noreply.github.com>
Co-authored-by: Kirill Müller <krlmlr@users.noreply.github.com>
@anderic1

Copy link
Copy Markdown
Contributor Author

I think we are done here. I committed your suggestions and you are right, it is better to be too strict and then loosen up than the other way around.

@krlmlr
krlmlr merged commit 6bfe467 into r-dbi:master Jan 19, 2021
@krlmlr

krlmlr commented Jan 19, 2021

Copy link
Copy Markdown
Member

Thanks!

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants