Skip to content

Commit 51b3f97

Browse files
committed
Cleanup
1 parent 7c63887 commit 51b3f97

File tree

3 files changed

+54
-48
lines changed

3 files changed

+54
-48
lines changed

bindings/python/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use pyo3::prelude::*;
1919

2020
mod datafusion_table_provider;
2121
mod error;
22+
mod manifest;
2223
mod runtime;
2324
mod transform;
24-
mod manifest;
2525

2626
#[pymodule]
2727
fn pyiceberg_core_rust(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {

bindings/python/src/manifest.rs

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,27 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use iceberg::spec::{DataFile, DataFileFormat, FieldSummary, FormatVersion, Literal, Manifest, ManifestEntry, ManifestFile, ManifestList, ManifestStatus, PrimitiveLiteral, StructType, Type};
19-
use iceberg::{Error, ErrorKind};
20-
use pyo3::prelude::*;
21-
use pyo3::types::PyAny;
2218
use std::collections::HashMap;
2319
use std::sync::Arc;
2420

21+
use iceberg::spec::{
22+
DataFile, DataFileFormat, FieldSummary, FormatVersion, Literal, Manifest, ManifestEntry,
23+
ManifestFile, ManifestList, ManifestStatus,
24+
};
25+
use pyo3::prelude::*;
26+
2527
#[pyclass]
2628
pub struct PyLiteral {
2729
inner: Literal,
2830
}
2931

30-
31-
#[pyclass]
32-
pub struct PyPrimitiveLiteral {
33-
inner: PrimitiveLiteral,
34-
}
35-
36-
3732
#[pyclass]
3833
pub struct PyDataFile {
3934
inner: DataFile,
4035
}
4136

4237
#[pymethods]
4338
impl PyDataFile {
44-
4539
#[getter]
4640
fn content(&self) -> i32 {
4741
self.inner.content_type() as i32
@@ -64,10 +58,15 @@ impl PyDataFile {
6458

6559
#[getter]
6660
fn partition(&self) -> Vec<Option<PyLiteral>> {
67-
self.inner.partition().fields().iter().map(|p| match p {
68-
Some(lit) => Some(PyLiteral { inner: lit.clone() }),
69-
_ => None
70-
} ).collect()
61+
self.inner
62+
.partition()
63+
.fields()
64+
.iter()
65+
.map(|p| match p {
66+
Some(lit) => Some(PyLiteral { inner: lit.clone() }),
67+
_ => None,
68+
})
69+
.collect()
7170
}
7271

7372
#[getter]
@@ -102,16 +101,24 @@ impl PyDataFile {
102101

103102
#[getter]
104103
fn upper_bounds(&self) -> HashMap<i32, Vec<u8>> {
105-
self.inner.upper_bounds().into_iter().map(|(k, v)| (k.clone(), v.to_bytes().unwrap().to_vec())).collect()
104+
self.inner
105+
.upper_bounds()
106+
.into_iter()
107+
.map(|(k, v)| (k.clone(), v.to_bytes().unwrap().to_vec()))
108+
.collect()
106109
}
107110

108111
#[getter]
109112
fn lower_bounds(&self) -> HashMap<i32, Vec<u8>> {
110-
self.inner.lower_bounds().into_iter().map(|(k, v)| (k.clone(), v.to_bytes().unwrap().to_vec())).collect()
113+
self.inner
114+
.lower_bounds()
115+
.into_iter()
116+
.map(|(k, v)| (k.clone(), v.to_bytes().unwrap().to_vec()))
117+
.collect()
111118
}
112119

113120
#[getter]
114-
fn key_metadata(&self) -> Option<&[u8]> {
121+
fn key_metadata(&self) -> Option<&[u8]> {
115122
self.inner.key_metadata()
116123
}
117124

@@ -129,36 +136,37 @@ impl PyDataFile {
129136
fn sort_order_id(&self) -> Option<i32> {
130137
self.inner.sort_order_id()
131138
}
132-
133139
}
134140

135141
#[pyclass]
136142
pub struct PyManifest {
137143
inner: Manifest,
138144
}
139145

140-
141146
#[pymethods]
142147
impl PyManifest {
143148
fn entries(&self) -> Vec<PyManifestEntry> {
144149
// TODO: Most of the time, we're only interested in 'alive' entries,
145150
// that are the ones that are either ADDED or EXISTING
146151
// so we can add a boolean to skip the DELETED entries right away before
147152
// moving it into the Python world
148-
self.inner.entries().iter().map(|entry| PyManifestEntry { inner: entry.clone() }).collect()
153+
self.inner
154+
.entries()
155+
.iter()
156+
.map(|entry| PyManifestEntry {
157+
inner: entry.clone(),
158+
})
159+
.collect()
149160
}
150161
}
151162

152-
153163
#[pyclass]
154164
pub struct PyFieldSummary {
155165
inner: FieldSummary,
156166
}
157167

158-
159168
#[pymethods]
160169
impl crate::manifest::PyFieldSummary {
161-
162170
#[getter]
163171
fn contains_null(&self) -> bool {
164172
self.inner.contains_null
@@ -170,25 +178,21 @@ impl crate::manifest::PyFieldSummary {
170178
}
171179

172180
#[getter]
173-
fn lower_bound(&self) -> Option<PyPrimitiveLiteral> {
174-
self.inner.lower_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
181+
fn lower_bound(&self) -> Option<ByteBuf> {
182+
self.inner.lower_bound
175183
}
176184

177185
#[getter]
178-
fn upper_bound(&self) -> Option<PyPrimitiveLiteral> {
179-
self.inner.upper_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
186+
fn upper_bound(&self) -> Option<ByteBuf> {
187+
self.inner.upper_bound
180188
}
181-
182-
183-
184189
}
185190

186191
#[pyclass]
187192
pub struct PyManifestFile {
188193
inner: ManifestFile,
189194
}
190195

191-
192196
#[pymethods]
193197
impl crate::manifest::PyManifestFile {
194198
#[getter]
@@ -214,7 +218,6 @@ impl crate::manifest::PyManifestFile {
214218
self.inner.sequence_number
215219
}
216220

217-
218221
#[getter]
219222
fn min_sequence_number(&self) -> i64 {
220223
self.inner.min_sequence_number
@@ -225,7 +228,6 @@ impl crate::manifest::PyManifestFile {
225228
self.inner.added_snapshot_id
226229
}
227230

228-
229231
#[getter]
230232
fn added_files_count(&self) -> Option<u32> {
231233
self.inner.added_files_count
@@ -258,16 +260,17 @@ impl crate::manifest::PyManifestFile {
258260

259261
#[getter]
260262
fn partitions(&self) -> Vec<PyFieldSummary> {
261-
self.inner.partitions.iter().map(|s| PyFieldSummary {
262-
inner: s.clone()
263-
}).collect()
263+
self.inner
264+
.partitions
265+
.iter()
266+
.map(|s| PyFieldSummary { inner: s.clone() })
267+
.collect()
264268
}
265269

266270
#[getter]
267271
fn key_metadata(&self) -> Vec<u8> {
268272
self.inner.key_metadata.clone()
269273
}
270-
271274
}
272275

273276
#[pyclass]
@@ -277,7 +280,6 @@ pub struct PyManifestEntry {
277280

278281
#[pymethods]
279282
impl PyManifestEntry {
280-
281283
#[getter]
282284
fn status(&self) -> i32 {
283285
ManifestStatus::Existing as i32
@@ -301,17 +303,16 @@ impl PyManifestEntry {
301303
#[getter]
302304
fn data_file(&self) -> PyDataFile {
303305
PyDataFile {
304-
inner: self.inner.data_file.clone()
306+
inner: self.inner.data_file.clone(),
305307
}
306308
}
307309
}
308310

309-
310311
#[pyfunction]
311312
pub fn read_manifest_entries(bs: &[u8]) -> PyManifest {
312313
// TODO: Some error handling
313314
PyManifest {
314-
inner: Manifest::parse_avro(bs).unwrap()
315+
inner: Manifest::parse_avro(bs).unwrap(),
315316
}
316317
}
317318

@@ -320,19 +321,23 @@ pub struct PyManifestList {
320321
inner: ManifestList,
321322
}
322323

323-
324324
#[pymethods]
325325
impl crate::manifest::PyManifestList {
326326
fn entries(&self) -> Vec<PyManifestFile> {
327-
self.inner.entries().iter().map(|file| PyManifestFile { inner: file.clone() }).collect()
327+
self.inner
328+
.entries()
329+
.iter()
330+
.map(|file| PyManifestFile {
331+
inner: file.clone(),
332+
})
333+
.collect()
328334
}
329335
}
330336

331-
332337
#[pyfunction]
333338
pub fn read_manifest_list(bs: &[u8]) -> PyManifestList {
334339
PyManifestList {
335-
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap()
340+
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap(),
336341
}
337342
}
338343

crates/iceberg/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern crate derive_builder;
6060
extern crate core;
6161

6262
mod error;
63+
6364
pub use error::{Error, ErrorKind, Result};
6465

6566
mod catalog;

0 commit comments

Comments
 (0)