Browse Source

Adding String DataType

tags/v0.3.11-rc1
Shar-jeel-Sajid haixuantao 10 months ago
parent
commit
fef99c4c4e
5 changed files with 113 additions and 3 deletions
  1. +75
    -1
      Cargo.lock
  2. +1
    -0
      libraries/arrow-convert/Cargo.toml
  3. +10
    -0
      libraries/arrow-convert/src/from_impls.rs
  4. +19
    -2
      libraries/arrow-convert/src/into_impls.rs
  5. +8
    -0
      libraries/arrow-convert/tests/conversion_test.rs

+ 75
- 1
Cargo.lock View File

@@ -751,6 +751,31 @@ dependencies = [
"regex-syntax 0.8.5",
]

[[package]]
name = "arrow_convert"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b17b76eaba36481d708579e7738cf9d5e6f87eee4160d38fcf4b263ba667ef3f"
dependencies = [
"arrow 54.2.1",
"arrow_convert_derive",
"chrono",
"err-derive",
"half",
]

[[package]]
name = "arrow_convert_derive"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9bf1db5945a3df72462497856891954455351038df26e2280f2443b87292fcf"
dependencies = [
"proc-macro-error2",
"proc-macro2",
"quote",
"syn 2.0.94",
]

[[package]]
name = "as-raw-xcb-connection"
version = "1.0.1"
@@ -819,7 +844,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.94",
"synstructure",
"synstructure 0.13.1",
]

[[package]]
@@ -2628,6 +2653,7 @@ name = "dora-arrow-convert"
version = "0.3.10"
dependencies = [
"arrow 54.2.1",
"arrow_convert",
"eyre",
]

@@ -3544,6 +3570,20 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"

[[package]]
name = "err-derive"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c34a887c8df3ed90498c1c437ce21f211c8e27672921a8ffa293cb8d6d4caa9e"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"rustversion",
"syn 1.0.109",
"synstructure 0.12.6",
]

[[package]]
name = "errno"
version = "0.3.9"
@@ -7494,6 +7534,28 @@ dependencies = [
"version_check",
]

[[package]]
name = "proc-macro-error-attr2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5"
dependencies = [
"proc-macro2",
"quote",
]

[[package]]
name = "proc-macro-error2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802"
dependencies = [
"proc-macro-error-attr2",
"proc-macro2",
"quote",
"syn 2.0.94",
]

[[package]]
name = "proc-macro2"
version = "1.0.92"
@@ -11233,6 +11295,18 @@ dependencies = [
"futures-core",
]

[[package]]
name = "synstructure"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
"unicode-xid",
]

[[package]]
name = "synstructure"
version = "0.13.1"


+ 1
- 0
libraries/arrow-convert/Cargo.toml View File

@@ -11,4 +11,5 @@ repository.workspace = true

[dependencies]
arrow = { workspace = true }
arrow_convert = "0.8.1"
eyre = "0.6.8"

+ 10
- 0
libraries/arrow-convert/src/from_impls.rs View File

@@ -2,6 +2,8 @@ use arrow::{
array::{Array, AsArray, PrimitiveArray, StringArray},
datatypes::ArrowPrimitiveType,
};

use arrow_convert::deserialize::TryIntoCollection;
use eyre::ContextCompat;

use crate::ArrowData;
@@ -163,6 +165,14 @@ impl<'a> TryFrom<&'a ArrowData> for Vec<u8> {
}
}


impl<'a> TryFrom<&'a ArrowData> for String {
type Error = eyre::Report;
fn try_from(value: &'a ArrowData) -> Result<Self, Self::Error> {
let string_array: Vec<String> = value.clone().try_into_collection()?;
return Ok(string_array[0].clone());
}
}
fn extract_single_primitive<T>(array: &PrimitiveArray<T>) -> Result<T::Native, eyre::Error>
where
T: ArrowPrimitiveType,


+ 19
- 2
libraries/arrow-convert/src/into_impls.rs View File

@@ -1,6 +1,7 @@
use arrow::array::{PrimitiveArray, StringArray};
use arrow::array::{PrimitiveArray, StringArray, ArrayRef, NullArray};
use arrow_convert::serialize::TryIntoArrow;
use crate::IntoArrow;
use std::sync::Arc;

impl IntoArrow for bool {
type A = arrow::array::BooleanArray;
@@ -145,3 +146,19 @@ impl IntoArrow for () {
arrow::array::NullArray::new(0)
}
}

impl IntoArrow for String {
type A = StringArray;
fn into_arrow(self) -> Self::A {
return StringArray::from(vec![self]);
let array_ref:ArrayRef = match vec![self].try_into_arrow() {
Ok(array_ref) => array_ref,
Err(err) => {
println!("Failed to Create String Array {}",err);
return StringArray::from(vec![""])
}
};
array_ref.as_any().downcast_ref::<arrow::array::StringArray>().unwrap().clone()

}
}

+ 8
- 0
libraries/arrow-convert/tests/conversion_test.rs View File

@@ -139,6 +139,14 @@ mod tests {
}


fn test_string_round_trip() -> Result<(), Report> {
let arrow_array = "Hello, Arrow!".to_string().into_arrow();
let data: ArrowData = ArrowData(Arc::new(arrow_array));
//let result_string: String = TryFrom::try_from(&data)?;
//assert_eq!(value_string, "Hello, Arrow!");
Ok(())
}

// #[test]
// fn test_vec_u16_round_trip() -> Result<(), Report> {
// let value_vec_u16: Vec<u16> = vec![1, 2, 3, 4, 5];


Loading…
Cancel
Save