Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support object store in *_scan functions. #1306

Merged
merged 2 commits into from
Jul 13, 2023
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
19 changes: 15 additions & 4 deletions crates/datasources/src/common/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum DatasourceUrl {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DatasourceUrlScheme {
File,
Http,
Gcs,
S3,
}
Expand All @@ -23,13 +24,20 @@ impl Display for DatasourceUrlScheme {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::File => write!(f, "file"),
Self::Http => write!(f, "http(s)"),
Self::Gcs => write!(f, "gs"),
Self::S3 => write!(f, "s3"),
}
}
}

impl DatasourceUrl {
const FILE_SCHEME: &str = "file";
const HTTP_SCHEME: &str = "http";
const HTTPS_SCHEME: &str = "https";
const GS_SCHEME: &str = "gs";
const S3_SCHEME: &str = "s3";

pub fn new(u: impl AsRef<str>) -> Result<Self> {
let u = u.as_ref();

Expand All @@ -46,15 +54,17 @@ impl DatasourceUrl {
};

let ds_url = match ds_url.scheme() {
"file" => match ds_url.to_file_path() {
Self::FILE_SCHEME => match ds_url.to_file_path() {
Ok(f) => Self::File(f),
Err(()) => {
return Err(DatasourceCommonError::InvalidUrl(format!(
"url not a valid file: {ds_url}"
)))
}
},
"gs" | "s3" => Self::Url(ds_url),
Self::HTTP_SCHEME | Self::HTTPS_SCHEME | Self::GS_SCHEME | Self::S3_SCHEME => {
Self::Url(ds_url)
}
other => {
return Err(DatasourceCommonError::InvalidUrl(format!(
"unsupported scheme '{other}'"
Expand All @@ -69,8 +79,9 @@ impl DatasourceUrl {
match self {
Self::File(_) => DatasourceUrlScheme::File,
Self::Url(u) => match u.scheme() {
"gs" => DatasourceUrlScheme::Gcs,
"s3" => DatasourceUrlScheme::S3,
Self::HTTP_SCHEME | Self::HTTPS_SCHEME => DatasourceUrlScheme::Http,
Self::GS_SCHEME => DatasourceUrlScheme::Gcs,
Self::S3_SCHEME => DatasourceUrlScheme::S3,
_ => unreachable!(),
},
}
Expand Down
2 changes: 1 addition & 1 deletion crates/datasources/src/object_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod parquet;
pub mod registry;
pub mod s3;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum FileType {
Csv,
Parquet,
Expand Down
3 changes: 3 additions & 0 deletions crates/sqlbuiltins/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum BuiltinError {
#[error(transparent)]
Arrow(#[from] datafusion::arrow::error::ArrowError),

#[error(transparent)]
DatasourceCommonError(#[from] datasources::common::errors::DatasourceCommonError),

#[error("{0}")]
Static(&'static str),

Expand Down
Loading