Skip to content

Commit e6e0dae

Browse files
authored
Merge branch 'main' into serialize-table-source
2 parents 6b7d21b + 28b6e9d commit e6e0dae

File tree

3 files changed

+70
-37
lines changed

3 files changed

+70
-37
lines changed

datafusion-examples/examples/parquet_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use url::Url;
7171
/// (using the same underlying APIs)
7272
///
7373
/// For a more advanced example of using an index to prune row groups within a
74-
/// file, see the (forthcoming) `advanced_parquet_index` example.
74+
/// file, see the `advanced_parquet_index` example.
7575
///
7676
/// # Diagram
7777
///

datafusion/common/src/scalar/mod.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,38 +3075,7 @@ impl ScalarValue {
30753075
target_type: &DataType,
30763076
cast_options: &CastOptions<'static>,
30773077
) -> Result<Self> {
3078-
let scalar_array = match (self, target_type) {
3079-
(
3080-
ScalarValue::Decimal128(Some(decimal_value), _, scale),
3081-
DataType::Timestamp(time_unit, None),
3082-
) => {
3083-
let scale_factor = 10_i128.pow(*scale as u32);
3084-
let seconds = decimal_value / scale_factor;
3085-
let fraction = decimal_value % scale_factor;
3086-
3087-
let timestamp_value = match time_unit {
3088-
TimeUnit::Second => ScalarValue::Int64(Some(seconds as i64)),
3089-
TimeUnit::Millisecond => {
3090-
let millis = seconds * 1_000 + (fraction * 1_000) / scale_factor;
3091-
ScalarValue::Int64(Some(millis as i64))
3092-
}
3093-
TimeUnit::Microsecond => {
3094-
let micros =
3095-
seconds * 1_000_000 + (fraction * 1_000_000) / scale_factor;
3096-
ScalarValue::Int64(Some(micros as i64))
3097-
}
3098-
TimeUnit::Nanosecond => {
3099-
let nanos = seconds * 1_000_000_000
3100-
+ (fraction * 1_000_000_000) / scale_factor;
3101-
ScalarValue::Int64(Some(nanos as i64))
3102-
}
3103-
};
3104-
3105-
timestamp_value.to_array()?
3106-
}
3107-
_ => self.to_array()?,
3108-
};
3109-
3078+
let scalar_array = self.to_array()?;
31103079
let cast_arr = cast_with_options(&scalar_array, target_type, cast_options)?;
31113080
ScalarValue::try_from_array(&cast_arr, 0)
31123081
}

datafusion/sqllogictest/test_files/timestamps.slt

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,12 @@ SELECT to_timestamp(123456789.123456789) as c1, cast(123456789.123456789 as time
530530
query PPP
531531
SELECT to_timestamp(arrow_cast(1.1, 'Decimal128(2,1)')) as c1, cast(arrow_cast(1.1, 'Decimal128(2,1)') as timestamp) as c2, arrow_cast(1.1, 'Decimal128(2,1)')::timestamp as c3;
532532
----
533-
1970-01-01T00:00:01.100 1970-01-01T00:00:01.100 1970-01-01T00:00:01.100
533+
1970-01-01T00:00:01.100 1970-01-01T00:00:00.000000001 1970-01-01T00:00:00.000000001
534534

535535
query PPP
536536
SELECT to_timestamp(arrow_cast(-1.1, 'Decimal128(2,1)')) as c1, cast(arrow_cast(-1.1, 'Decimal128(2,1)') as timestamp) as c2, arrow_cast(-1.1, 'Decimal128(2,1)')::timestamp as c3;
537537
----
538-
1969-12-31T23:59:58.900 1969-12-31T23:59:58.900 1969-12-31T23:59:58.900
538+
1969-12-31T23:59:58.900 1969-12-31T23:59:59.999999999 1969-12-31T23:59:59.999999999
539539

540540
query PPP
541541
SELECT to_timestamp(arrow_cast(0.0, 'Decimal128(2,1)')) as c1, cast(arrow_cast(0.0, 'Decimal128(2,1)') as timestamp) as c2, arrow_cast(0.0, 'Decimal128(2,1)')::timestamp as c3;
@@ -545,12 +545,12 @@ SELECT to_timestamp(arrow_cast(0.0, 'Decimal128(2,1)')) as c1, cast(arrow_cast(0
545545
query PPP
546546
SELECT to_timestamp(arrow_cast(1.23456789, 'Decimal128(9,8)')) as c1, cast(arrow_cast(1.23456789, 'Decimal128(9,8)') as timestamp) as c2, arrow_cast(1.23456789, 'Decimal128(9,8)')::timestamp as c3;
547547
----
548-
1970-01-01T00:00:01.234567890 1970-01-01T00:00:01.234567890 1970-01-01T00:00:01.234567890
548+
1970-01-01T00:00:01.234567890 1970-01-01T00:00:00.000000001 1970-01-01T00:00:00.000000001
549549

550550
query PPP
551551
SELECT to_timestamp(arrow_cast(123456789.123456789, 'Decimal128(18,9)')) as c1, cast(arrow_cast(123456789.123456789, 'Decimal128(18,9)') as timestamp) as c2, arrow_cast(123456789.123456789, 'Decimal128(18,9)')::timestamp as c3;
552552
----
553-
1973-11-29T21:33:09.123456784 1973-11-29T21:33:09.123456784 1973-11-29T21:33:09.123456784
553+
1973-11-29T21:33:09.123456784 1970-01-01T00:00:00.123456789 1970-01-01T00:00:00.123456789
554554

555555

556556
# from_unixtime
@@ -3529,3 +3529,67 @@ select to_timestamp('-1');
35293529

35303530
query error DataFusion error: Arrow error: Parser error: Error parsing timestamp from '\-1': timestamp must contain at least 10 characters
35313531
select to_timestamp(arrow_cast('-1', 'Utf8'));
3532+
3533+
query P
3534+
SELECT CAST(CAST(1 AS decimal(17,2)) AS timestamp(3)) AS a UNION ALL
3535+
SELECT CAST(CAST(one AS decimal(17,2)) AS timestamp(3)) AS a FROM (VALUES (1)) t(one);
3536+
----
3537+
1970-01-01T00:00:00.001
3538+
1970-01-01T00:00:00.001
3539+
3540+
query P
3541+
SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Nanosecond, None)') AS a UNION ALL
3542+
SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Nanosecond, None)') AS a FROM (VALUES (1)) t(one);
3543+
----
3544+
1970-01-01T00:00:00.000000001
3545+
1970-01-01T00:00:00.000000001
3546+
3547+
query P
3548+
SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Microsecond, None)') AS a UNION ALL
3549+
SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Microsecond, None)') AS a FROM (VALUES (1)) t(one);
3550+
----
3551+
1970-01-01T00:00:00.000001
3552+
1970-01-01T00:00:00.000001
3553+
3554+
query P
3555+
SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Millisecond, None)') AS a UNION ALL
3556+
SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Millisecond, None)') AS a FROM (VALUES (1)) t(one);
3557+
----
3558+
1970-01-01T00:00:00.001
3559+
1970-01-01T00:00:00.001
3560+
3561+
query P
3562+
SELECT arrow_cast(CAST(1 AS decimal(17,2)), 'Timestamp(Second, None)') AS a UNION ALL
3563+
SELECT arrow_cast(CAST(one AS decimal(17,2)), 'Timestamp(Second, None)') AS a FROM (VALUES (1)) t(one);
3564+
----
3565+
1970-01-01T00:00:01
3566+
1970-01-01T00:00:01
3567+
3568+
3569+
query P
3570+
SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Nanosecond, None)') AS a UNION ALL
3571+
SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Nanosecond, None)') AS a FROM (VALUES (1.123)) t(one);
3572+
----
3573+
1970-01-01T00:00:00.000000001
3574+
1970-01-01T00:00:00.000000001
3575+
3576+
query P
3577+
SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Microsecond, None)') AS a UNION ALL
3578+
SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Microsecond, None)') AS a FROM (VALUES (1.123)) t(one);
3579+
----
3580+
1970-01-01T00:00:00.000001
3581+
1970-01-01T00:00:00.000001
3582+
3583+
query P
3584+
SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Millisecond, None)') AS a UNION ALL
3585+
SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Millisecond, None)') AS a FROM (VALUES (1.123)) t(one);
3586+
----
3587+
1970-01-01T00:00:00.001
3588+
1970-01-01T00:00:00.001
3589+
3590+
query P
3591+
SELECT arrow_cast(CAST(1.123 AS decimal(17,3)), 'Timestamp(Second, None)') AS a UNION ALL
3592+
SELECT arrow_cast(CAST(one AS decimal(17,3)), 'Timestamp(Second, None)') AS a FROM (VALUES (1.123)) t(one);
3593+
----
3594+
1970-01-01T00:00:01
3595+
1970-01-01T00:00:01

0 commit comments

Comments
 (0)