`SCALE ... VIA date` fails to coerce Timestamp columns from registered tables
Mantenedores costumam responder em até 6 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 65/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- rust
- Domínio
- backend-api-design, data-visualization
Direção de pesquisa
The issue is in src/execute/scale.rs, function coerce_column_to_type, around line 754. Look at the match arm for ArrayElementType::Date. Currently it only handles DataType::Utf8; you need to add a branch for DataType::Timestamp to use arrow::compute::cast_array to cast to Date32. Also check the ArrayElementType::DateTime arm for a similar issue. Run the provided Rust test case to verify the fix works for registered tables.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
A column of Arrow type Timestamp -- the same type as DuckDB's own
TIMESTAMP -- only coerces successfully under SCALE <col> VIA date when
its table lives natively in the reader's DuckDB catalog. The identical
column type, when the table is instead provided via Reader::register()
(the API for handing a reader an externally-produced table), fails to
coerce with:
Validation error: Cannot coerce column '__ggsql_aes_pos1__' of type Timestamp(Microsecond, None) to date
Both cases below produce a column that is unambiguously Timestamp(Microsecond, None) -- confirmed independently for each. Only the table's origin differs.
Case 1: native DuckDB table -- succeeds
CREATE TABLE t AS
SELECT DATE_TRUNC('month', d) AS month, v
FROM (VALUES (DATE '2024-01-15', 10), (DATE '2024-02-20', 20)) AS x(d, v);
DESCRIBE t reports month as TIMESTAMP; .arrow().schema confirms timestamp[us].
VISUALISE month AS x, v AS y FROM t DRAW bar SCALE x VIA date
This succeeds.
Case 2: registered table -- fails
Calling the core crate directly, with no other bindings involved:
use std::sync::Arc;
use arrow::array::{Int64Array, TimestampMicrosecondArray};
use ggsql::reader::{DuckDBReader, Reader};
use ggsql::DataFrame;
fn main() {
let reader = DuckDBReader::from_connection_string("duckdb://memory").unwrap();
let month = TimestampMicrosecondArray::from(vec![
1704067200000000i64, // 2024-01-01T00:00:00
1706745600000000i64, // 2024-02-01T00:00:00
]);
let v = Int64Array::from(vec![10i64, 20i64]);
let df = DataFrame::new(vec![
("month", Arc::new(month) as _),
("v", Arc::new(v) as _),
]).unwrap();
println!("registered column dtype: {:?}", df.column_dtype("month"));
reader.register("t", df, false).unwrap();
match reader.execute("VISUALISE month AS x, v AS y FROM t DRAW bar SCALE x VIA date") {
Ok(_) => println!("SUCCEEDED (unexpected)"),
Err(e) => println!("FAILED: {}", e),
}
}
Output:
registered column dtype: Ok(Timestamp(Microsecond, None))
FAILED: Validation error: Cannot coerce column '__ggsql_aes_pos1__' of type Timestamp(Microsecond, None) to date
Environment: posit-dev/ggsql main @ 983e38e3 (v0.5.2).
Root cause
src/execute/scale.rs, coerce_column_to_type, the ArrayElementType::Date
match arm (~line 754) only handles a DataType::Utf8 source (parsing
YYYY-MM-DD strings); every other source dtype -- including
Timestamp(Microsecond, None) -- falls into the catch-all _ branch and
hard-errors:
ArrayElementType::Date => match dtype {
DataType::Utf8 => {
// ... parses date strings into a Date32 array ...
}
_ => {
return Err(GgsqlError::ValidationError(format!(
"Cannot coerce column '{}' of type {:?} to date",
column_name, dtype
)));
}
},
Arrow's cast_array (already imported and used a few lines above for
ArrayElementType::Number) supports a safe Timestamp -> Date32 cast that
just truncates the time-of-day component, but this arm never reaches it for
non-Utf8 inputs. Since Case 1 and Case 2 produce the identical Arrow
Timestamp(Microsecond, None) type, something upstream of this function
must be normalizing/pre-casting the column differently depending on whether
it came from register() or from the reader's own catalog -- worth tracing
that path too, since it's the reason this bug is inconsistent rather than
a hard failure every time a Timestamp reaches a date scale.
Note the neighboring ArrayElementType::DateTime arm has the identical
Utf8-only pattern, so a native Date32 column being coerced to a datetime
target may have the mirror-image problem -- I haven't verified that case,
but it's worth checking alongside this fix.
Suggested fix
Add a DataType::Timestamp(_, _) => cast_array(column, &DataType::Date32)?
branch to the ArrayElementType::Date arm in coerce_column_to_type,
mirroring the existing Number arm's use of cast_array. That would make
Case 2 succeed unconditionally rather than only when the upstream
normalization happens to have already run.
Workaround
Explicitly CAST(... AS DATE) the derived expression in SQL before it
reaches ggsql, e.g. CAST(DATE_TRUNC('month', d) AS DATE). That produces a
genuine Date32-typed column, which coerces fine regardless of table origin.
- Linguagem predominante
- Rust
- Estrelas
- 573
- Forks
- 32
- Merge médio
- 8d 23h
- PRs com merge (30d)
- 5
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de posit-dev/ggsql
-
Missing `linewidth` and `linetype` aesthetics on histogram and bar layersTalvez já em andamento @teunbrand assumiu há 30 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 61/100
Mantenedores costumam responder em até 6 dias
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 6 dias
-
writer
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 6 dias
-
plot building
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 6 dias
-
Mention DuckDB extensionTalvez já em andamento @Anant-mishra1729 assumiu há 152 dias. Abertadocumentation integration
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 6 dias
Todas as issues de posit-dev/ggsql
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
storytold/craft-anything#2472 ·
Mantenedores costumam responder em até 1 dia
-
enhancement good first issue help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
getsotto/sotto-authenticator#68 ·
Mantenedores costumam responder em até 1 dia
-
Project submission: AegisAberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
slavakurilyak/awesome-ai-agents#1046 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
nowledge-co/hawdb#1995 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
swc-project/swc-next-issues#984 ·