Repository navigation
Convert to Datetime when encountering Date - #607
Conversation
| let expr = temporal_as_epoch_micros(dialect, &dialect.quote_ident(&value), kind); | ||
| ( | ||
| format!( | ||
| "SELECT *, {expr} AS {val_alias} FROM ({query}) AS {src_alias}", |
There was a problem hiding this comment.
Don't we need to use the Select dialect infrastructure you introduced?
| .collect(); | ||
| if !column_dtypes.is_empty() { | ||
| if let Ok(common_dtype) = crate::plot::scale::coerce_dtypes(&column_dtypes) { | ||
| let kind = infer_transform(&spec.scales[idx], &common_dtype, is_map); |
There was a problem hiding this comment.
Map projections stamp their position scales with TransformKind::Geographic, so these cannot have temporal scales. Because if temporal_transform then is mutually exclusive with is_map, we can hardcode false for is_map (and remove the variable here, maybe commenting on why we hardcode it to false).
Arguably a user can specify SCALE lon VIA date or something, which would be irregular and kicks all conventional map wisdom out the door, so the exact re-inference of the scale shouldn't matter too much even in this fringe case.
Also this kicks in on smooth layers, which may have its own problems with map projections.
| data_cte: &str, | ||
| grid_cte: &str, | ||
| dialect: &dyn SqlDialect, | ||
| value_temporal: Option<crate::plot::types::CastTargetType>, |
There was a problem hiding this comment.
IIUC we only cast to datetime when using smooth, but density/violin also maybe ought to support temporal data. If you agree, then we should remove this argument and always cast a date value.
teunbrand
left a comment
There was a problem hiding this comment.
I still think #607 (comment) is worth making a decision about.
In the current state, using density on a date column gives an unsightly error.
If we decide that we want date-enabled density, I'd be happy. If not, then we should error more gracefully.
Here is a test query that I think should work:
SELECT * FROM (VALUES
('2024-01-01'::DATE, 'A', 10),
('2024-01-02'::DATE, 'A', 20),
('2024-01-03'::DATE, 'A', 30),
('2024-01-04'::DATE, 'A', 40),
('2024-01-05'::DATE, 'A', 50),
('2024-03-10'::DATE, 'B', 15),
('2024-03-11'::DATE, 'B', 25),
('2024-03-12'::DATE, 'B', 35),
('2024-03-13'::DATE, 'B', 45),
('2024-03-14'::DATE, 'B', 55)
) AS t(date, grp, value)
VISUALISE date AS x, grp AS colour
DRAW density|
hmm I think a decision has been made and it is to support it... I can't reproduce your issue. Are you looking at the latest commit? |
|
Good catch - it was a preexisting bug that this work surfaced - fixed now |
teunbrand
left a comment
There was a problem hiding this comment.
LGTM thanks for fixing that ordering bug!

Fix #250
We now support doing smoothing (density/smooth/violin) over temporal values such as Date by upcasting to microseconds since epoch