datafusion_data_access/
lib.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18pub mod object_store;
19
20use chrono::{DateTime, Utc};
21use std::{io, result};
22
23/// Result type for operations that could result in an io error
24pub type Result<T> = result::Result<T, io::Error>;
25
26/// Represents a specific file or a prefix (folder) that may
27/// require further resolution
28#[derive(Debug)]
29pub enum ListEntry {
30    /// Specific file with metadata
31    FileMeta(FileMeta),
32    /// Prefix to be further resolved during partition discovery
33    Prefix(String),
34}
35
36/// The path and size of the file.
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct SizedFile {
39    /// Path of the file. It is relative to the current object
40    /// store (it does not specify the `xx://` scheme).
41    pub path: String,
42    /// File size in total
43    pub size: u64,
44}
45
46/// Description of a file as returned by the listing command of a
47/// given object store. The resulting path is relative to the
48/// object store that generated it.
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub struct FileMeta {
51    /// The path and size of the file.
52    pub sized_file: SizedFile,
53    /// The last modification time of the file according to the
54    /// object store metadata. This information might be used by
55    /// catalog systems like Delta Lake for time travel (see
56    /// <https://github.com/delta-io/delta/issues/192>)
57    pub last_modified: Option<DateTime<Utc>>,
58}
59
60impl FileMeta {
61    /// The path that describes this file. It is relative to the
62    /// associated object store.
63    pub fn path(&self) -> &str {
64        &self.sized_file.path
65    }
66
67    /// The size of the file.
68    pub fn size(&self) -> u64 {
69        self.sized_file.size
70    }
71}
72
73impl std::fmt::Display for FileMeta {
74    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
75        write!(f, "{} (size: {})", self.path(), self.size())
76    }
77}