Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 1 addition & 62 deletions crates/api-snowflake-rest/src/server/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,6 @@ pub type Result<T> = std::result::Result<T, Error>;
#[snafu(visibility(pub(crate)))]
#[error_stack_trace::debug]
pub enum Error {
#[snafu(display("Failed to decompress GZip body"))]
GZipDecompress {
#[snafu(source)]
error: std::io::Error,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Failed to parse login request"))]
LoginRequestParse {
#[snafu(source)]
error: serde_json::Error,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Failed to parse query body"))]
QueryBodyParse {
#[snafu(source)]
error: serde_json::Error,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Missing auth token"))]
MissingAuthToken {
#[snafu(implicit)]
Expand All @@ -56,20 +32,6 @@ pub enum Error {
location: Location,
},

#[snafu(display("Invalid uuid format"))]
InvalidUuidFormat {
#[snafu(source)]
error: uuid::Error,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Missing DBT session"))]
MissingDbtSession {
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Invalid auth data"))]
InvalidAuthData {
#[snafu(implicit)]
Expand All @@ -82,14 +44,6 @@ pub enum Error {
location: Location,
},

#[snafu(display("Failed to parse row JSON"))]
RowParse {
#[snafu(source)]
error: serde_json::Error,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("UTF8 error: {error}"))]
Utf8 {
#[snafu(source)]
Expand Down Expand Up @@ -211,29 +165,14 @@ impl Error {
_ => (http::StatusCode::OK, SqlState::Success, error_code),
}
}
Self::GZipDecompress { .. }
| Self::LoginRequestParse { .. }
| Self::QueryBodyParse { .. }
| Self::InvalidUuidFormat { .. } => {
// TODO: Is this need a fix? Bad request return retriable http code
(
http::StatusCode::BAD_REQUEST,
SqlState::Success,
ErrorCode::Other,
)
}
Self::MissingAuthToken { .. }
| Self::MissingDbtSession { .. }
| Self::InvalidAuthData { .. }
| Self::InvalidAuthToken { .. } => (
http::StatusCode::UNAUTHORIZED,
SqlState::Success,
ErrorCode::Other,
),
Self::RowParse { .. }
| Self::Utf8 { .. }
| Self::Arrow { .. }
| Self::NotImplemented { .. } => {
Self::Utf8 { .. } | Self::Arrow { .. } | Self::NotImplemented { .. } => {
(http::StatusCode::OK, SqlState::Success, ErrorCode::Other)
}
};
Expand Down
45 changes: 0 additions & 45 deletions crates/catalog-metastore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ pub enum Error {
location: Location,
},

#[snafu(display("Volume: Validation failed. Reason: {reason}"))]
VolumeValidationFailed {
reason: String,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Volume: Missing credentials"))]
VolumeMissingCredentials {
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Cloud provider not implemented"))]
CloudProviderNotImplemented {
provider: String,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("ObjectStore: {error}"))]
ObjectStore {
#[snafu(source)]
Expand All @@ -53,25 +33,6 @@ pub enum Error {
location: Location,
},

#[snafu(display("ObjectStore path: {error}"))]
ObjectStorePath {
#[snafu(source)]
error: object_store::path::Error,
#[snafu(implicit)]
location: Location,
},

#[snafu(display(
"Unable to create directory for File ObjectStore path {path}, error: {error}"
))]
CreateDirectory {
path: String,
#[snafu(source)]
error: std::io::Error,
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Metastore object of type {type_name} with name {name} already exists"))]
ObjectAlreadyExists {
type_name: String,
Expand All @@ -80,12 +41,6 @@ pub enum Error {
location: Location,
},

#[snafu(display("Metastore object not found"))]
ObjectNotFound {
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Volume {volume} already exists"))]
VolumeAlreadyExists {
volume: String,
Expand Down
67 changes: 0 additions & 67 deletions crates/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,70 +29,3 @@ where
.join()
.unwrap_or_else(|_| error::ThreadPanickedWhileExecutingFutureSnafu.fail()?)
}

pub mod test_utils {
use datafusion::arrow::array::{ArrayRef, RecordBatch};
use datafusion::arrow::compute::{
SortColumn, SortOptions, lexsort_to_indices, take_record_batch,
};
use datafusion::arrow::datatypes::{DataType, Field, Schema};
use std::collections::HashSet;
use std::sync::Arc;

#[allow(clippy::unwrap_used, clippy::must_use_candidate)]
pub fn sort_record_batch_by_sortable_columns(batch: &RecordBatch) -> RecordBatch {
let sort_columns: Vec<SortColumn> = (0..batch.num_columns())
.filter_map(|i| {
let col = batch.column(i).clone();
let field = batch.schema().field(i).clone();
if matches!(field.data_type(), DataType::Null) {
None
} else {
Some(SortColumn {
values: col,
options: Some(SortOptions::default()),
})
}
})
.collect();

if sort_columns.is_empty() {
return batch.clone();
}

let indices = lexsort_to_indices(&sort_columns, Some(batch.num_rows())).unwrap();
take_record_batch(batch, &indices).unwrap()
}

#[allow(clippy::unwrap_used, clippy::must_use_candidate)]
pub fn remove_columns_from_batches<S: ::std::hash::BuildHasher>(
batches: Vec<RecordBatch>,
excluded_columns: &HashSet<&str, S>,
) -> Vec<RecordBatch> {
batches
.into_iter()
.map(|batch| {
let schema = batch.schema();
let indices: Vec<usize> = schema
.fields()
.iter()
.enumerate()
.filter_map(|(i, f)| {
if excluded_columns.contains(f.name().as_str()) {
None
} else {
Some(i)
}
})
.collect();

let columns: Vec<ArrayRef> =
indices.iter().map(|&i| batch.column(i).clone()).collect();
let fields: Vec<Field> = indices.iter().map(|&i| schema.field(i).clone()).collect();
let new_schema = Arc::new(Schema::new(fields));

RecordBatch::try_new(new_schema, columns).unwrap()
})
.collect()
}
}