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

fix: Ignore HTTP store client errors trying to get content length #2874

Merged
merged 17 commits into from
Apr 12, 2024
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
21 changes: 19 additions & 2 deletions crates/datasources/src/object_store/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,28 @@ pub struct HttpStoreAccess {
impl HttpStoreAccess {
async fn content_length(u: Url) -> Result<Option<u64>> {
let res = reqwest::Client::new().head(u.clone()).send().await?;

let status = res.status();
if !status.is_success() {
// Ignore client errors (head method might not be supported).
if status.is_client_error() {
return Ok(None);
}

if u.as_str().contains('*') {
return Err(ObjectStoreSourceError::InvalidHttpStatus(format!(
"Unexpected status code '{}' for url: '{}'. \
Note that globbing is not supported for HTTP.",
status, u,
)));
}

return Err(ObjectStoreSourceError::InvalidHttpStatus(format!(
"Unexpected status code '{}' for url: '{}'",
status, u,
)));
}

// reqwest doesn't check the content length header, instead looks at the contents
// See: https://github.com/seanmonstar/reqwest/issues/843
let len = res
Expand Down Expand Up @@ -326,10 +334,19 @@ impl ObjectStore for SimpleHttpStore {
if content_length != 0 {
self.obj_store.get_opts(location, options).await
} else {
self.simple_get_req(location.clone()).await.map_err(|e| {
self.simple_get_req(location.clone()).await.map_err(|err| {
let err = if self.url.as_str().contains('*') {
ObjectStoreSourceError::String(format!(
"{err}: \
Note that globbing is not supported for HTTP.",
))
} else {
err
};

object_store::Error::Generic {
store: "HTTP",
source: Box::new(e),
source: Box::new(err),
}
})
}
Expand Down
5 changes: 0 additions & 5 deletions testdata/sqllogictests/functions/json_scan.slt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ select * from ndjson_scan([]);

# Glob patterns not supported on HTTP

statement error Unexpected status code '404 Not Found'
select * from ndjson_scan(
'https://raw.githubusercontent.com/GlareDB/glaredb/main/testdata/sqllogictests_datasources_common/data/*.ndjson'
tychoish marked this conversation as resolved.
Show resolved Hide resolved
);

statement error Note that globbing is not supported for HTTP.
select * from ndjson_scan(
'https://raw.githubusercontent.com/GlareDB/glaredb/main/testdata/sqllogictests_datasources_common/data/*.ndjson'
Expand Down
5 changes: 0 additions & 5 deletions testdata/sqllogictests/functions/read_ndjson.slt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ select * from read_ndjson([]);

# Glob patterns not supported on HTTP

statement error Unexpected status code '404 Not Found'
select * from read_ndjson(
'https://raw.githubusercontent.com/GlareDB/glaredb/main/testdata/sqllogictests_datasources_common/data/*.ndjson'
);

statement error Note that globbing is not supported for HTTP.
select * from read_ndjson(
'https://raw.githubusercontent.com/GlareDB/glaredb/main/testdata/sqllogictests_datasources_common/data/*.ndjson'
Expand Down
3 changes: 2 additions & 1 deletion testdata/sqllogictests/http.slt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
statement error Unexpected status code '403 Forbidden'
# TODO: Maybe someday fix the error message (should be 403 Forbidden)
statement error
select * from 'http://host.com/path/*.parquet'

statement error Error during planning: missing file extension: http://host.com/path/*
Expand Down