Skip to content

Commit

Permalink
Fixes and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AsafMah committed Jan 4, 2024
1 parent 2031f7f commit 71aaff7
Show file tree
Hide file tree
Showing 19 changed files with 858 additions and 97 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["azure-kusto-data"]
resolver = "2"
9 changes: 5 additions & 4 deletions azure-kusto-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Rust wrappers around Microsoft Azure REST APIs - Azure Data Explo
readme = "README.md"
license = "MIT"
edition = "2021"
rust-version = "1.75"
rust-version = "1.74"
repository = "https://github.com/azure/azure-sdk-for-rust"
homepage = "https://github.com/azure/azure-sdk-for-rust"
documentation = "https://docs.rs/azure_kusto_data"
Expand All @@ -26,7 +26,7 @@ bytes = "1.4"
futures = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_with = { version = "3.4.0"}
serde_with = { version = "3.4.0" }
thiserror = "1.0.38"
hashbrown = { version = "0.14", features = ["serde"] }
regex = "1.7.1"
Expand All @@ -38,16 +38,17 @@ time = { version = "0.3", features = [
"serde-well-known",
] }
derive_builder = "0.12"
derive_more = { version = "1.0.0-beta.6" , features = ["from", "into", "display", "from_str"] }
derive_more = { version = "1.0.0-beta.6", features = ["from", "into", "display", "from_str"] }
once_cell = "1"
rust_decimal = { version = "1.33.1", features = ["serde-str"] }
uuid = { version = "1.3.0", features = ["serde"] }
tokio = { version = "1.35.1", features = ["macros", "rt"] }


[dev-dependencies]
arrow = { version = "49.0.0", features = ["prettyprint"] }
dotenv = "0.15.0"
env_logger = "0.10.0"
tokio = { version = "1.25.0", features = ["macros"] }
oauth2 = "4.3.0"
criterion = "0.5"
clap = { version = "4.1.6", features = ["derive", "env"] }
Expand Down
2 changes: 1 addition & 1 deletion azure-kusto-data/src/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn convert_column(data: Vec<Value>, column: &Column) -> Result<(Field, Array
.map(|data| (Field::new(column_name, DataType::Int64, true), data)),
ColumnType::Real => convert_array_float(data)
.map(|data| (Field::new(column_name, DataType::Float64, true), data)),
ColumnType::Datetime => convert_array_datetime(data).map(|data| {
ColumnType::DateTime => convert_array_datetime(data).map(|data| {
(
Field::new(
column_name,
Expand Down
7 changes: 2 additions & 5 deletions azure-kusto-data/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::prelude::ClientRequestProperties;
use azure_core::headers::Headers;
use azure_core::prelude::{Accept, AcceptEncoding, ClientVersion, ContentType};
use serde::de::DeserializeOwned;
use serde_json::Value;
use std::convert::TryFrom;
use std::fmt::Debug;
use std::sync::Arc;
Expand Down Expand Up @@ -250,10 +249,8 @@ impl KustoClient {
.ok_or_else(|| Error::QueryError("No primary results found".into()))?
.rows
.into_iter()
.map(|row| match row {
Row::Values(v) => serde_json::from_value(Value::Array(v)).map_err(Error::from),
Row::Error(e) => Err(Error::QueryApiError(e)),
})
.map(Row::into_result)
.map(|r| r.and_then(|v| serde_json::from_value::<T>(serde_json::Value::Array(v)).map_err(Error::from)))
.collect::<Result<Vec<T>>>()?;

Ok(results)
Expand Down
25 changes: 25 additions & 0 deletions azure-kusto-data/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,50 @@ pub enum Error {
/// Errors raised from the api calls to kusto
#[error("Query API error: {0}")]
QueryApiError(OneApiError),

/// Multiple errors
#[error("Multiple errors: {0:?}")]
MultipleErrors(Vec<Error>),
}

Check warning on line 61 in azure-kusto-data/src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

large size difference between variants

warning: large size difference between variants --> azure-kusto-data/src/error.rs:9:1 | 9 | / pub enum Error { 10 | | /// Raised when failing to convert a kusto response to the expected type. 11 | | #[error("Error converting Kusto response for {0}")] 12 | | ConversionError(String), ... | 36 | | AzureError(#[from] azure_core::error::Error), | | -------------------------------------------- the second-largest variant contains at least 72 bytes ... | 56 | | QueryApiError(OneApiError), | | -------------------------- the largest variant contains at least 352 bytes ... | 60 | | MultipleErrors(Vec<Error>), 61 | | } | |_^ the entire enum is at least 0 bytes | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant = note: `#[warn(clippy::large_enum_variant)]` on by default help: consider boxing the large fields to reduce the total size of the enum | 56 | QueryApiError(Box<OneApiError>), | ~~~~~~~~~~~~~~~~

impl From<Vec<Error>> for Error {
fn from(errors: Vec<Error>) -> Self {
if errors.len() == 1 {
Error::from(errors.into_iter().next().unwrap())

Check warning on line 66 in azure-kusto-data/src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `error::Error`

warning: useless conversion to the same type: `error::Error` --> azure-kusto-data/src/error.rs:66:13 | 66 | Error::from(errors.into_iter().next().unwrap()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `Error::from()`: `errors.into_iter().next().unwrap()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
} else {
Error::MultipleErrors(errors)
}
}
}

/// Errors raised when parsing values.
#[derive(thiserror::Error, Debug)]
pub enum ParseError {
/// Raised when a value is null, but the type is not nullable.
#[error("Error parsing null value for {0}")]
ValueNull(String),
/// Raised when an int value is failed to be parsed.
#[error("Error parsing int: {0}")]
Int(#[from] std::num::ParseIntError),
/// Raised when a long value is failed to be parsed.
#[error("Error parsing float: {0}")]
Float(#[from] std::num::ParseFloatError),
/// Raised when a bool value is failed to be parsed.
#[error("Error parsing bool: {0}")]
Bool(#[from] std::str::ParseBoolError),
/// Raised when a timespan value is failed to be parsed.
#[error("Error parsing timespan: {0}")]
Timespan(String),
/// Raised when a datetime value is failed to be parsed.
#[error("Error parsing datetime: {0}")]
DateTime(#[from] time::error::Parse),
/// Raised when a guid value is failed to be parsed.
#[error("Error parsing guid: {0}")]
Guid(#[from] uuid::Error),
/// Raised when a decimal value is failed to be parsed.
#[error("Error parsing decimal")]
Decimal(#[from] rust_decimal::Error),
/// Raised when a dynamic value is failed to be parsed.
#[error("Error parsing dynamic: {0}")]
Dynamic(#[from] serde_json::Error),
}
Expand Down Expand Up @@ -115,3 +139,4 @@ impl ConnectionStringError {

/// Result type for kusto operations.
pub type Result<T> = std::result::Result<T, Error>;
pub type Partial<T> = std::result::Result<T, (Option<T>, Error)>;

Check warning on line 142 in azure-kusto-data/src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a type alias

warning: missing documentation for a type alias --> azure-kusto-data/src/error.rs:142:1 | 142 | pub type Partial<T> = std::result::Result<T, (Option<T>, Error)>; | ^^^^^^^^^^^^^^^^^^^
5 changes: 4 additions & 1 deletion azure-kusto-data/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pub mod v1;

Check warning on line 1 in azure-kusto-data/src/models/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> azure-kusto-data/src/models/mod.rs:1:1 | 1 | pub mod v1; | ^^^^^^^^^^
pub mod v2;

Check warning on line 2 in azure-kusto-data/src/models/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> azure-kusto-data/src/models/mod.rs:2:1 | 2 | pub mod v2; | ^^^^^^^^^^

#[cfg(test)]
pub(crate) mod test_helpers;

use serde::{Deserialize, Serialize};

/// Represents the scalar data types of ADX. see [the docs for more information](https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/)
Expand All @@ -11,7 +14,7 @@ pub enum ColumnType {
Bool,
/// Datetime, represents a specific point in time.
#[serde(rename = "datetime")]
Datetime,
DateTime,
/// A complex type, that is either an array or a dictionary of other values.
#[serde(rename = "dynamic")]
Dynamic,
Expand Down
1 change: 0 additions & 1 deletion azure-kusto-data/src/models/one_api_error.rs

This file was deleted.

Loading

0 comments on commit 71aaff7

Please sign in to comment.