@@ -22,14 +22,18 @@ use pyo3::prelude::*;
2222use object_store:: aws:: { AmazonS3 , AmazonS3Builder } ;
2323use object_store:: azure:: { MicrosoftAzure , MicrosoftAzureBuilder } ;
2424use object_store:: gcp:: { GoogleCloudStorage , GoogleCloudStorageBuilder } ;
25+ use object_store:: http:: { HttpBuilder , HttpStore } ;
2526use object_store:: local:: LocalFileSystem ;
27+ use pyo3:: exceptions:: PyValueError ;
28+ use url:: Url ;
2629
2730#[ derive( FromPyObject ) ]
2831pub enum StorageContexts {
2932 AmazonS3 ( PyAmazonS3Context ) ,
3033 GoogleCloudStorage ( PyGoogleCloudContext ) ,
3134 MicrosoftAzure ( PyMicrosoftAzureContext ) ,
3235 LocalFileSystem ( PyLocalFileSystemContext ) ,
36+ HTTP ( PyHttpContext ) ,
3337}
3438
3539#[ pyclass( name = "LocalFileSystem" , module = "datafusion.store" , subclass) ]
@@ -219,10 +223,37 @@ impl PyAmazonS3Context {
219223 }
220224}
221225
226+ #[ pyclass( name = "Http" , module = "datafusion.store" , subclass) ]
227+ #[ derive( Debug , Clone ) ]
228+ pub struct PyHttpContext {
229+ pub url : String ,
230+ pub store : Arc < HttpStore > ,
231+ }
232+
233+ #[ pymethods]
234+ impl PyHttpContext {
235+ #[ new]
236+ fn new ( url : String ) -> PyResult < Self > {
237+ let store = match Url :: parse ( url. as_str ( ) ) {
238+ Ok ( url) => HttpBuilder :: new ( )
239+ . with_url ( url. origin ( ) . ascii_serialization ( ) )
240+ . build ( ) ,
241+ Err ( _) => HttpBuilder :: new ( ) . build ( ) ,
242+ }
243+ . map_err ( |e| PyValueError :: new_err ( format ! ( "Error: {:?}" , e. to_string( ) ) ) ) ?;
244+
245+ Ok ( Self {
246+ url,
247+ store : Arc :: new ( store) ,
248+ } )
249+ }
250+ }
251+
222252pub ( crate ) fn init_module ( m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
223253 m. add_class :: < PyAmazonS3Context > ( ) ?;
224254 m. add_class :: < PyMicrosoftAzureContext > ( ) ?;
225255 m. add_class :: < PyGoogleCloudContext > ( ) ?;
226256 m. add_class :: < PyLocalFileSystemContext > ( ) ?;
257+ m. add_class :: < PyHttpContext > ( ) ?;
227258 Ok ( ( ) )
228259}
0 commit comments