Skip to content

Commit 0fae964

Browse files
committed
Cleanup
1 parent 7c63887 commit 0fae964

File tree

3 files changed

+56
-41
lines changed

3 files changed

+56
-41
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: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,32 @@
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, PrimitiveLiteral,
24+
};
25+
use pyo3::prelude::*;
26+
2527
#[pyclass]
2628
pub struct PyLiteral {
2729
inner: Literal,
2830
}
2931

30-
3132
#[pyclass]
3233
pub struct PyPrimitiveLiteral {
3334
inner: PrimitiveLiteral,
3435
}
3536

36-
3737
#[pyclass]
3838
pub struct PyDataFile {
3939
inner: DataFile,
4040
}
4141

4242
#[pymethods]
4343
impl PyDataFile {
44-
4544
#[getter]
4645
fn content(&self) -> i32 {
4746
self.inner.content_type() as i32
@@ -64,10 +63,15 @@ impl PyDataFile {
6463

6564
#[getter]
6665
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()
66+
self.inner
67+
.partition()
68+
.fields()
69+
.iter()
70+
.map(|p| match p {
71+
Some(lit) => Some(PyLiteral { inner: lit.clone() }),
72+
_ => None,
73+
})
74+
.collect()
7175
}
7276

7377
#[getter]
@@ -102,16 +106,24 @@ impl PyDataFile {
102106

103107
#[getter]
104108
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()
109+
self.inner
110+
.upper_bounds()
111+
.into_iter()
112+
.map(|(k, v)| (k.clone(), v.to_bytes().unwrap().to_vec()))
113+
.collect()
106114
}
107115

108116
#[getter]
109117
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()
118+
self.inner
119+
.lower_bounds()
120+
.into_iter()
121+
.map(|(k, v)| (k.clone(), v.to_bytes().unwrap().to_vec()))
122+
.collect()
111123
}
112124

113125
#[getter]
114-
fn key_metadata(&self) -> Option<&[u8]> {
126+
fn key_metadata(&self) -> Option<&[u8]> {
115127
self.inner.key_metadata()
116128
}
117129

@@ -129,36 +141,37 @@ impl PyDataFile {
129141
fn sort_order_id(&self) -> Option<i32> {
130142
self.inner.sort_order_id()
131143
}
132-
133144
}
134145

135146
#[pyclass]
136147
pub struct PyManifest {
137148
inner: Manifest,
138149
}
139150

140-
141151
#[pymethods]
142152
impl PyManifest {
143153
fn entries(&self) -> Vec<PyManifestEntry> {
144154
// TODO: Most of the time, we're only interested in 'alive' entries,
145155
// that are the ones that are either ADDED or EXISTING
146156
// so we can add a boolean to skip the DELETED entries right away before
147157
// moving it into the Python world
148-
self.inner.entries().iter().map(|entry| PyManifestEntry { inner: entry.clone() }).collect()
158+
self.inner
159+
.entries()
160+
.iter()
161+
.map(|entry| PyManifestEntry {
162+
inner: entry.clone(),
163+
})
164+
.collect()
149165
}
150166
}
151167

152-
153168
#[pyclass]
154169
pub struct PyFieldSummary {
155170
inner: FieldSummary,
156171
}
157172

158-
159173
#[pymethods]
160174
impl crate::manifest::PyFieldSummary {
161-
162175
#[getter]
163176
fn contains_null(&self) -> bool {
164177
self.inner.contains_null
@@ -171,24 +184,24 @@ impl crate::manifest::PyFieldSummary {
171184

172185
#[getter]
173186
fn lower_bound(&self) -> Option<PyPrimitiveLiteral> {
174-
self.inner.lower_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
187+
self.inner.lower_bound.clone().map(|v| PyPrimitiveLiteral {
188+
inner: v.iter().clone(),
189+
})
175190
}
176191

177192
#[getter]
178193
fn upper_bound(&self) -> Option<PyPrimitiveLiteral> {
179-
self.inner.upper_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
194+
self.inner.upper_bound.clone().map(|v| PyPrimitiveLiteral {
195+
inner: v.literal().clone(),
196+
})
180197
}
181-
182-
183-
184198
}
185199

186200
#[pyclass]
187201
pub struct PyManifestFile {
188202
inner: ManifestFile,
189203
}
190204

191-
192205
#[pymethods]
193206
impl crate::manifest::PyManifestFile {
194207
#[getter]
@@ -214,7 +227,6 @@ impl crate::manifest::PyManifestFile {
214227
self.inner.sequence_number
215228
}
216229

217-
218230
#[getter]
219231
fn min_sequence_number(&self) -> i64 {
220232
self.inner.min_sequence_number
@@ -225,7 +237,6 @@ impl crate::manifest::PyManifestFile {
225237
self.inner.added_snapshot_id
226238
}
227239

228-
229240
#[getter]
230241
fn added_files_count(&self) -> Option<u32> {
231242
self.inner.added_files_count
@@ -258,16 +269,17 @@ impl crate::manifest::PyManifestFile {
258269

259270
#[getter]
260271
fn partitions(&self) -> Vec<PyFieldSummary> {
261-
self.inner.partitions.iter().map(|s| PyFieldSummary {
262-
inner: s.clone()
263-
}).collect()
272+
self.inner
273+
.partitions
274+
.iter()
275+
.map(|s| PyFieldSummary { inner: s.clone() })
276+
.collect()
264277
}
265278

266279
#[getter]
267280
fn key_metadata(&self) -> Vec<u8> {
268281
self.inner.key_metadata.clone()
269282
}
270-
271283
}
272284

273285
#[pyclass]
@@ -277,7 +289,6 @@ pub struct PyManifestEntry {
277289

278290
#[pymethods]
279291
impl PyManifestEntry {
280-
281292
#[getter]
282293
fn status(&self) -> i32 {
283294
ManifestStatus::Existing as i32
@@ -301,17 +312,16 @@ impl PyManifestEntry {
301312
#[getter]
302313
fn data_file(&self) -> PyDataFile {
303314
PyDataFile {
304-
inner: self.inner.data_file.clone()
315+
inner: self.inner.data_file.clone(),
305316
}
306317
}
307318
}
308319

309-
310320
#[pyfunction]
311321
pub fn read_manifest_entries(bs: &[u8]) -> PyManifest {
312322
// TODO: Some error handling
313323
PyManifest {
314-
inner: Manifest::parse_avro(bs).unwrap()
324+
inner: Manifest::parse_avro(bs).unwrap(),
315325
}
316326
}
317327

@@ -320,19 +330,23 @@ pub struct PyManifestList {
320330
inner: ManifestList,
321331
}
322332

323-
324333
#[pymethods]
325334
impl crate::manifest::PyManifestList {
326335
fn entries(&self) -> Vec<PyManifestFile> {
327-
self.inner.entries().iter().map(|file| PyManifestFile { inner: file.clone() }).collect()
336+
self.inner
337+
.entries()
338+
.iter()
339+
.map(|file| PyManifestFile {
340+
inner: file.clone(),
341+
})
342+
.collect()
328343
}
329344
}
330345

331-
332346
#[pyfunction]
333347
pub fn read_manifest_list(bs: &[u8]) -> PyManifestList {
334348
PyManifestList {
335-
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap()
349+
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap(),
336350
}
337351
}
338352

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)