connectorx/transports/
dummy_arrowstream.rs1use crate::destinations::arrowstream::{
4 typesystem::{ArrowTypeSystem, NaiveDateTimeWrapperMicro},
5 ArrowDestination, ArrowDestinationError,
6};
7use crate::sources::dummy::{DummySource, DummyTypeSystem};
8use crate::typesystem::TypeConversion;
9use chrono::{DateTime, NaiveDate, NaiveDateTime, Utc};
10use thiserror::Error;
11
12pub struct DummyArrowTransport;
14
15#[derive(Error, Debug)]
17pub enum DummyArrowTransportError {
18 #[error(transparent)]
20 Destination(#[from] ArrowDestinationError),
21
22 #[error(transparent)]
24 ConnectorX(#[from] crate::errors::ConnectorXError),
25}
26
27impl_transport!(
28 name = DummyArrowTransport,
29 error = DummyArrowTransportError,
30 systems = DummyTypeSystem => ArrowTypeSystem,
31 route = DummySource => ArrowDestination,
32 mappings = {
33 { F64[f64] => Float64[f64] | conversion auto}
34 { I64[i64] => Int64[i64] | conversion auto}
35 { Bool[bool] => Boolean[bool] | conversion auto}
36 { String[String] => LargeUtf8[String] | conversion auto}
37 { DateTime[DateTime<Utc>] => Date64Micro[NaiveDateTimeWrapperMicro] | conversion option}
38 }
39);
40
41impl TypeConversion<DateTime<Utc>, NaiveDateTimeWrapperMicro> for DummyArrowTransport {
42 fn convert(val: DateTime<Utc>) -> NaiveDateTimeWrapperMicro {
43 NaiveDateTimeWrapperMicro(val.naive_utc())
44 }
45}
46
47impl TypeConversion<NaiveDateTime, DateTime<Utc>> for DummyArrowTransport {
48 fn convert(val: NaiveDateTime) -> DateTime<Utc> {
49 DateTime::from_naive_utc_and_offset(val, Utc)
50 }
51}
52
53impl TypeConversion<NaiveDate, DateTime<Utc>> for DummyArrowTransport {
54 fn convert(val: NaiveDate) -> DateTime<Utc> {
55 DateTime::from_naive_utc_and_offset(
56 val.and_hms_opt(0, 0, 0)
57 .unwrap_or_else(|| panic!("and_hms_opt return None")),
58 Utc,
59 )
60 }
61}
62
63#[cfg(test)]
66#[allow(clippy::duplicate_mod)]
67#[path = "dummy_tests.rs"]
68mod tests;