Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chmp committed Jan 19, 2025
1 parent 2165ca9 commit c240d69
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 65 deletions.
20 changes: 10 additions & 10 deletions serde_arrow/src/internal/schema/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn date64_field_complex() -> PanicOnError<()> {
data_type: DataType::Date64,
metadata: hash_map!(
"foo" => "bar",
STRATEGY_KEY => "NaiveStrAsDate64",
STRATEGY_KEY => "DateTimeAsStr",
),
nullable: true,
}],
Expand All @@ -87,7 +87,7 @@ fn date64_field_complex() -> PanicOnError<()> {
"metadata": {
"foo": "bar",
},
"strategy": "NaiveStrAsDate64",
"strategy": "DateTimeAsStr",
"nullable": true,
}],
});
Expand Down Expand Up @@ -335,7 +335,7 @@ fn test_metadata_strategy_from_explicit() {
{
"name": "example",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
"metadata": {
"foo": "bar",
"hello": "world",
Expand All @@ -346,7 +346,7 @@ fn test_metadata_strategy_from_explicit() {

assert_eq!(
schema.fields[0].metadata,
hash_map!("foo" => "bar", "hello" => "world", STRATEGY_KEY => "UtcStrAsDate64"),
hash_map!("foo" => "bar", "hello" => "world", STRATEGY_KEY => "DateTimeAsStr"),
);

let schema_value = serde_json::to_value(&schema).unwrap();
Expand All @@ -355,7 +355,7 @@ fn test_metadata_strategy_from_explicit() {
{
"name": "example",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
"metadata": {
"foo": "bar",
"hello": "world",
Expand All @@ -374,7 +374,7 @@ fn test_metadata_strategy_from_metadata() {
"name": "example",
"data_type": "Date64",
"metadata": {
STRATEGY_KEY: "UtcStrAsDate64",
STRATEGY_KEY: "DateTimeAsStr",
"foo": "bar",
"hello": "world",
},
Expand All @@ -384,7 +384,7 @@ fn test_metadata_strategy_from_metadata() {

assert_eq!(
schema.fields[0].metadata,
hash_map!("foo" => "bar", "hello" => "world", STRATEGY_KEY => "UtcStrAsDate64")
hash_map!("foo" => "bar", "hello" => "world", STRATEGY_KEY => "DateTimeAsStr")
);

// NOTE: the strategy is always normalized to be an extra field
Expand All @@ -394,7 +394,7 @@ fn test_metadata_strategy_from_metadata() {
{
"name": "example",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
"metadata": {
"foo": "bar",
"hello": "world",
Expand All @@ -413,9 +413,9 @@ fn test_invalid_metadata() {
{
"name": "example",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
"metadata": {
STRATEGY_KEY: "UtcStrAsDate64"
STRATEGY_KEY: "DateTimeAsStr"
},
},
]));
Expand Down
14 changes: 8 additions & 6 deletions serde_arrow/src/internal/schema/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ fn coerce_primitive_type(
options: &TracingOptions,
) -> Result<(DataType, bool, Option<Strategy>)> {
use DataType::{
Date64, Float32, Float64, Int16, Int32, Int64, Int8, LargeUtf8, Null, UInt16, UInt32,
Float32, Float64, Int16, Int32, Int64, Int8, LargeUtf8, Null, Timestamp, UInt16, UInt32,
UInt64, UInt8, Utf8,
};

Expand Down Expand Up @@ -575,11 +575,13 @@ fn coerce_primitive_type(
(Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 | UInt64, _),
) if options.coerce_numbers => (Float64, nullable, None),
// incompatible formats, coerce to string
((Date64, nullable, _), (LargeUtf8, _)) => (LargeUtf8, nullable, None),
((LargeUtf8, nullable, _), (Date64, _)) => (LargeUtf8, nullable, None),
((Date64, nullable, _), (Utf8, _)) => (Utf8, nullable, None),
((Utf8, nullable, _), (Date64, _)) => (Utf8, nullable, None),
((Date64, nullable, prev_st), (Date64, curr_st)) if prev_st != curr_st.as_ref() => {
((Timestamp(_, _), nullable, _), (LargeUtf8, _)) => (LargeUtf8, nullable, None),
((LargeUtf8, nullable, _), (Timestamp(_, _), _)) => (LargeUtf8, nullable, None),
((Timestamp(_, _), nullable, _), (Utf8, _)) => (Utf8, nullable, None),
((Utf8, nullable, _), (Timestamp(_, _), _)) => (Utf8, nullable, None),
((Timestamp(_, _), nullable, prev_st), (Timestamp(_, _), curr_st))
if prev_st != curr_st.as_ref() =>
{
(options.string_type(), nullable, None)
}
((prev_ty, _, prev_st), (curr_ty, curr_st)) => {
Expand Down
8 changes: 4 additions & 4 deletions serde_arrow/src/test/schema_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ mod json_date64_naive_null {
let expected = SerdeArrowSchema::from_value(&json!([
{
"name": "date",
"data_type": "Date64",
"strategy": "NaiveStrAsDate64",
"data_type": "Timestamp(Millisecond, None)",
"strategy": "DateTimeAsStr",
"nullable": true,
},
]))?;
Expand Down Expand Up @@ -210,8 +210,8 @@ mod json_date64_utc_null {
let expected = SerdeArrowSchema::from_value(&json!([
{
"name": "date",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"data_type": "Timestamp(Millisecond, Some(\"UTC\"))",
"strategy": "DateTimeAsStr",
"nullable": true,
},
]))?;
Expand Down
42 changes: 21 additions & 21 deletions serde_arrow/src/test_with_arrow/impls/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ fn utc_as_date64() {
Test::new()
.with_schema(json!([{
"name": "item",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"data_type": "Timestamp(Millisecond, Some(\"UTC\"))",
"strategy": "DateTimeAsStr",
}]))
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
Expand All @@ -103,7 +103,7 @@ fn utc_as_date64_without_strategy() {
Test::new()
.with_schema(json!([{
"name": "item",
"data_type": "Date64",
"data_type": "Timestamp(Millisecond, Some(\"UTC\"))",
}]))
.serialize(&items)
.deserialize(&items)
Expand All @@ -121,8 +121,8 @@ fn naive_as_date64() {
Test::new()
.with_schema(json!([{
"name": "item",
"data_type": "Date64",
"strategy": "NaiveStrAsDate64",
"data_type": "Timestamp(Millisecond, None)",
"strategy": "DateTimeAsStr",
}]))
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
Expand Down Expand Up @@ -397,7 +397,7 @@ fn utc_str_as_date64_as_timestamp() {
.with_schema(json!([{
"name": "item",
"data_type": "Timestamp(Second, Some(\"Utc\"))",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand All @@ -407,7 +407,7 @@ fn utc_str_as_date64_as_timestamp() {
.with_schema(json!([{
"name": "item",
"data_type": "Timestamp(Millisecond, Some(\"Utc\"))",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand All @@ -417,7 +417,7 @@ fn utc_str_as_date64_as_timestamp() {
.with_schema(json!([{
"name": "item",
"data_type": "Timestamp(Microsecond, Some(\"Utc\"))",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand All @@ -427,7 +427,7 @@ fn utc_str_as_date64_as_timestamp() {
.with_schema(json!([{
"name": "item",
"data_type": "Timestamp(Nanosecond, Some(\"Utc\"))",
"strategy": "UtcStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand Down Expand Up @@ -456,7 +456,7 @@ fn naive_as_timestamp() {
"name": "item",
"data_type":
"Timestamp(Millisecond, None)",
"strategy": "NaiveStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand All @@ -467,7 +467,7 @@ fn naive_as_timestamp() {
"name": "item",
"data_type":
"Timestamp(Microsecond, None)",
"strategy": "NaiveStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand All @@ -478,7 +478,7 @@ fn naive_as_timestamp() {
"name": "item",
"data_type":
"Timestamp(Nanosecond, None)",
"strategy": "NaiveStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand Down Expand Up @@ -507,7 +507,7 @@ fn naive_as_timestamp_seconds() {
"name": "item",
"data_type":
"Timestamp(Second, None)",
"strategy": "NaiveStrAsDate64",
"strategy": "DateTimeAsStr",
}]))
.serialize(&items)
.deserialize(&items)
Expand All @@ -524,8 +524,8 @@ fn utc_as_date64_tracing_string_only() {
Test::new()
.with_schema(json!([{
"name": "item",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"data_type": "Timestamp(Millisecond, None)",
"strategy": "DateTimeAsStr",
}]))
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
Expand All @@ -544,8 +544,8 @@ fn utc_as_date64_tracing_string_nullable() {
Test::new()
.with_schema(json!([{
"name": "item",
"data_type": "Date64",
"strategy": "UtcStrAsDate64",
"data_type": "Timestmap(Millisecond, Some(\"UTC\"))",
"strategy": "DateTimeAsStr",
"nullable": true,
}]))
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
Expand Down Expand Up @@ -580,8 +580,8 @@ fn naive_as_date64_tracing_string_only() {
Test::new()
.with_schema(json!([{
"name": "item",
"data_type": "Date64",
"strategy": "NaiveStrAsDate64",
"data_type": "Timestamp(Millisecond, None)",
"strategy": "DateTimeAsStr",
}]))
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
Expand All @@ -600,8 +600,8 @@ fn naive_as_date64_tracing_string_nullable() {
Test::new()
.with_schema(json!([{
"name": "item",
"data_type": "Date64",
"strategy": "NaiveStrAsDate64",
"data_type": "Timestamp(Millisecond, None)",
"strategy": "DateTimeAsStr",
"nullable": true,
}]))
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
Expand Down
46 changes: 22 additions & 24 deletions serde_arrow/src/test_with_arrow/impls/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ mod date_time {
.deserialize(&items);
}

#[test]
fn as_timestamp_millisecond_with_strategy() {
let items = items();
Test::new()
.with_schema(json!([{"name": "item", "data_type": "Timestamp(Millisecond, None)", "strategy": "DateTimeAsStr"}]))
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
.deserialize(&items);
}

#[test]
fn as_timestamp_microsecond() {
let items = items();
Expand All @@ -187,18 +197,6 @@ mod date_time {
.serialize(&items)
.deserialize(&items);
}

#[test]
fn as_date64() {
let items = items();
Test::new()
.with_schema(
json!([{"name": "item", "data_type": "Date64", "strategy": "NaiveStrAsDate64"}]),
)
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
.deserialize(&items);
}
}

mod timestamp {
Expand Down Expand Up @@ -269,6 +267,18 @@ mod timestamp {
.deserialize(&items);
}

#[test]
fn as_timestamp_millisecond_with_strategy() {
let items = items();
Test::new()
.with_schema(
json!([{"name": "item", "data_type": "Timestamp(Millisecond, Some(\"UTC\"))", "strategy": "DateTimeAsStr"}]),
)
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
.deserialize(&items);
}

#[test]
fn as_timestamp_microsecond() {
let items = items();
Expand Down Expand Up @@ -300,18 +310,6 @@ mod timestamp {
.serialize(&items)
.deserialize(&items);
}

#[test]
fn as_date64() {
let items = items();
Test::new()
.with_schema(
json!([{"name": "item", "data_type": "Date64", "strategy": "UtcStrAsDate64"}]),
)
.trace_schema_from_samples(&items, TracingOptions::default().guess_dates(true))
.serialize(&items)
.deserialize(&items);
}
}

mod span {
Expand Down

0 comments on commit c240d69

Please sign in to comment.