Skip to content

Commit

Permalink
Fix local datetime stringification for columns that need escaping (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease authored Feb 8, 2024
1 parent 8357b8c commit db91169
Show file tree
Hide file tree
Showing 4 changed files with 1,059 additions and 2 deletions.
6 changes: 5 additions & 1 deletion vegafusion-core/src/planning/stringify_local_datetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::task_graph::scope::TaskScope;
use itertools::sorted;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use vegafusion_common::escape::unescape_field;

/// This planning phase converts select datetime columns from the default millisecond UTC
/// representation to naive datetime strings in an "output timezone". This is only done for datetime
Expand Down Expand Up @@ -385,13 +386,14 @@ impl<'a> MutChartVisitor for StringifyLocalDatetimeFieldsVisitor<'a> {
);

for field in sorted(fields) {
let field = unescape_field(&field);
let expr_str =
format!("timeFormat(toDate(datum['{field}'], 'local'), '%Y-%m-%dT%H:%M:%S.%L')");

let transforms = &mut data.transform;
let transform = FormulaTransformSpec {
expr: expr_str,
as_: field.to_string(),
as_: field,
extra: Default::default(),
};
transforms.push(TransformSpec::Formula(transform))
Expand All @@ -405,6 +407,7 @@ impl<'a> MutChartVisitor for StringifyLocalDatetimeFieldsVisitor<'a> {
let source_resolved_var = (source_resolved.var, source_resolved.scope);
if let Some(fields) = self.local_datetime_fields.get(&source_resolved_var) {
for field in sorted(fields) {
let field = unescape_field(&field);
let expr_str = format!("toDate(datum['{field}'], 'local')");
let transforms = &mut data.transform;
let transform = FormulaTransformSpec {
Expand Down Expand Up @@ -448,6 +451,7 @@ impl<'a> MutChartVisitor for FormatLocalDatetimeFieldsVisitor<'a> {
self.domain_dataset_fields,
);
for field in sorted(fields) {
let field = unescape_field(&field);
let transforms = &mut data.transform;
let transform = FormulaTransformSpec {
expr: format!("toDate(datum['{field}'])"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"server_to_client": [
{
"namespace": "data",
"name": "data_0",
"scope": []
},
{
"namespace": "data",
"name": "data_0_y_domain_sum_price",
"scope": []
}
],
"client_to_server": []
}
Loading

0 comments on commit db91169

Please sign in to comment.