pub struct ListingTableUrl { /* private fields */ }Expand description
A parsed URL identifying files for a listing table, see ListingTableUrl::parse
for more information on the supported expressions
Implementations§
Source§impl ListingTableUrl
impl ListingTableUrl
Sourcepub fn parse(s: impl AsRef<str>) -> Result<Self>
pub fn parse(s: impl AsRef<str>) -> Result<Self>
Parse a provided string as a ListingTableUrl
A URL can either refer to a single object, or a collection of objects with a
common prefix, with the presence of a trailing / indicating a collection.
For example, file:///foo.txt refers to the file at /foo.txt, whereas
file:///foo/ refers to all the files under the directory /foo and its
subdirectories.
Similarly s3://BUCKET/blob.csv refers to blob.csv in the S3 bucket BUCKET,
whereas s3://BUCKET/foo/ refers to all objects with the prefix foo/ in the
S3 bucket BUCKET
§URL Encoding
URL paths are expected to be URL-encoded. That is, the URL for a file named bar%2Efoo
would be file:///bar%252Efoo, as per the URL specification.
It should be noted that some tools, such as the AWS CLI, take a different approach and
instead interpret the URL path verbatim. For example the object bar%2Efoo would be
addressed as s3://BUCKET/bar%252Efoo using ListingTableUrl but s3://BUCKET/bar%2Efoo
when using the aws-cli.
§Paths without a Scheme
If no scheme is provided, or the string is an absolute filesystem path
as determined by std::path::Path::is_absolute, the string will be
interpreted as a path on the local filesystem using the operating
system’s standard path delimiter, i.e. \ on Windows, / on Unix.
If the path contains any of '?', '*', '[', it will be considered
a glob expression and resolved as described in the section below.
Otherwise, the path will be resolved to an absolute path based on the current working directory, and converted to a file URI.
If the path already exists in the local filesystem this will be used to determine if this
ListingTableUrl refers to a collection or a single object, otherwise the presence
of a trailing path delimiter will be used to indicate a directory. For the avoidance
of ambiguity it is recommended users always include trailing / when intending to
refer to a directory.
§Glob File Paths
If no scheme is provided, and the path contains a glob expression, it will be resolved as follows.
The string up to the first path segment containing a glob expression will be extracted, and resolved in the same manner as a normal scheme-less path above.
The remaining string will be interpreted as a glob::Pattern and used as a
filter when listing files from object storage
Sourcepub fn try_new(url: Url, glob: Option<Pattern>) -> Result<Self>
pub fn try_new(url: Url, glob: Option<Pattern>) -> Result<Self>
Creates a new ListingTableUrl from a url and optional glob expression
Self::parse supports glob expression only for file system paths.
However, some applications may want to support glob expression for URLs with a scheme.
The application can split the URL into a base URL and a glob expression and use this method
to create a ListingTableUrl.
Sourcepub fn prefix(&self) -> &Path
pub fn prefix(&self) -> &Path
Return the URL path not excluding any glob expression
If Self::is_collection, this is the listing prefix
Otherwise, this is the path to the object
Sourcepub fn contains(&self, path: &Path, ignore_subdirectory: bool) -> bool
pub fn contains(&self, path: &Path, ignore_subdirectory: bool) -> bool
Returns true if path matches this ListingTableUrl
Sourcepub fn is_collection(&self) -> bool
pub fn is_collection(&self) -> bool
Returns true if path refers to a collection of objects
Sourcepub fn file_extension(&self) -> Option<&str>
pub fn file_extension(&self) -> Option<&str>
Returns the file extension of the last path segment if it exists
Examples:
use datafusion_datasource::ListingTableUrl;
let url = ListingTableUrl::parse("file:///foo/bar.csv").unwrap();
assert_eq!(url.file_extension(), Some("csv"));
let url = ListingTableUrl::parse("file:///foo/bar").unwrap();
assert_eq!(url.file_extension(), None);
let url = ListingTableUrl::parse("file:///foo/bar.").unwrap();
assert_eq!(url.file_extension(), None);Sourcepub fn strip_prefix<'a, 'b: 'a>(
&'a self,
path: &'b Path,
) -> Option<impl Iterator<Item = &'b str> + 'a>
pub fn strip_prefix<'a, 'b: 'a>( &'a self, path: &'b Path, ) -> Option<impl Iterator<Item = &'b str> + 'a>
Strips the prefix of this ListingTableUrl from the provided path, returning
an iterator of the remaining path segments
Sourcepub async fn list_all_files<'a>(
&'a self,
ctx: &'a dyn Session,
store: &'a dyn ObjectStore,
file_extension: &'a str,
) -> Result<BoxStream<'a, Result<ObjectMeta>>>
pub async fn list_all_files<'a>( &'a self, ctx: &'a dyn Session, store: &'a dyn ObjectStore, file_extension: &'a str, ) -> Result<BoxStream<'a, Result<ObjectMeta>>>
List all files identified by this ListingTableUrl for the provided file_extension
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns this ListingTableUrl as a string
Sourcepub fn object_store(&self) -> ObjectStoreUrl
pub fn object_store(&self) -> ObjectStoreUrl
Return the ObjectStoreUrl for this ListingTableUrl
Sourcepub fn is_folder(&self) -> bool
pub fn is_folder(&self) -> bool
Returns true if the ListingTableUrl points to the folder
Sourcepub fn get_url(&self) -> &Url
pub fn get_url(&self) -> &Url
Return the url for ListingTableUrl
Sourcepub fn get_glob(&self) -> &Option<Pattern>
pub fn get_glob(&self) -> &Option<Pattern>
Return the glob for ListingTableUrl
Sourcepub fn with_glob(self, glob: &str) -> Result<Self>
pub fn with_glob(self, glob: &str) -> Result<Self>
Returns a copy of current ListingTableUrl with a specified glob
Trait Implementations§
Source§impl AsRef<Url> for ListingTableUrl
impl AsRef<Url> for ListingTableUrl
Source§impl AsRef<str> for ListingTableUrl
impl AsRef<str> for ListingTableUrl
Source§impl Clone for ListingTableUrl
impl Clone for ListingTableUrl
Source§fn clone(&self) -> ListingTableUrl
fn clone(&self) -> ListingTableUrl
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ListingTableUrl
impl Debug for ListingTableUrl
Source§impl Display for ListingTableUrl
impl Display for ListingTableUrl
Source§impl Hash for ListingTableUrl
impl Hash for ListingTableUrl
Source§impl PartialEq for ListingTableUrl
impl PartialEq for ListingTableUrl
impl Eq for ListingTableUrl
impl StructuralPartialEq for ListingTableUrl
Auto Trait Implementations§
impl Freeze for ListingTableUrl
impl RefUnwindSafe for ListingTableUrl
impl Send for ListingTableUrl
impl Sync for ListingTableUrl
impl Unpin for ListingTableUrl
impl UnwindSafe for ListingTableUrl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more