iceberg/scan/
task.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
18use futures::stream::BoxStream;
19use serde::{Deserialize, Serialize};
20
21use crate::Result;
22use crate::expr::BoundPredicate;
23use crate::spec::{DataContentType, DataFileFormat, ManifestEntryRef, Schema, SchemaRef};
24
25/// A stream of [`FileScanTask`].
26pub type FileScanTaskStream = BoxStream<'static, Result<FileScanTask>>;
27
28/// A task to scan part of file.
29#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
30pub struct FileScanTask {
31    /// The start offset of the file to scan.
32    pub start: u64,
33    /// The length of the file to scan.
34    pub length: u64,
35    /// The number of records in the file to scan.
36    ///
37    /// This is an optional field, and only available if we are
38    /// reading the entire data file.
39    pub record_count: Option<u64>,
40
41    /// The data file path corresponding to the task.
42    pub data_file_path: String,
43
44    /// The format of the file to scan.
45    pub data_file_format: DataFileFormat,
46
47    /// The schema of the file to scan.
48    pub schema: SchemaRef,
49    /// The field ids to project.
50    pub project_field_ids: Vec<i32>,
51    /// The predicate to filter.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub predicate: Option<BoundPredicate>,
54
55    /// The list of delete files that may need to be applied to this data file
56    pub deletes: Vec<FileScanTaskDeleteFile>,
57}
58
59impl FileScanTask {
60    /// Returns the data file path of this file scan task.
61    pub fn data_file_path(&self) -> &str {
62        &self.data_file_path
63    }
64
65    /// Returns the project field id of this file scan task.
66    pub fn project_field_ids(&self) -> &[i32] {
67        &self.project_field_ids
68    }
69
70    /// Returns the predicate of this file scan task.
71    pub fn predicate(&self) -> Option<&BoundPredicate> {
72        self.predicate.as_ref()
73    }
74
75    /// Returns the schema of this file scan task as a reference
76    pub fn schema(&self) -> &Schema {
77        &self.schema
78    }
79
80    /// Returns the schema of this file scan task as a SchemaRef
81    pub fn schema_ref(&self) -> SchemaRef {
82        self.schema.clone()
83    }
84}
85
86#[derive(Debug)]
87pub(crate) struct DeleteFileContext {
88    pub(crate) manifest_entry: ManifestEntryRef,
89    pub(crate) partition_spec_id: i32,
90}
91
92impl From<&DeleteFileContext> for FileScanTaskDeleteFile {
93    fn from(ctx: &DeleteFileContext) -> Self {
94        FileScanTaskDeleteFile {
95            file_path: ctx.manifest_entry.file_path().to_string(),
96            file_type: ctx.manifest_entry.content_type(),
97            partition_spec_id: ctx.partition_spec_id,
98            equality_ids: ctx.manifest_entry.data_file.equality_ids.clone(),
99        }
100    }
101}
102
103/// A task to scan part of file.
104#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
105pub struct FileScanTaskDeleteFile {
106    /// The delete file path
107    pub file_path: String,
108
109    /// delete file type
110    pub file_type: DataContentType,
111
112    /// partition id
113    pub partition_spec_id: i32,
114
115    /// equality ids for equality deletes (null for anything other than equality-deletes)
116    pub equality_ids: Option<Vec<i32>>,
117}