Skip to content

Commit 8e27d9e

Browse files
committed
Cleanup
1 parent 7c63887 commit 8e27d9e

File tree

3 files changed

+44
-48
lines changed

3 files changed

+44
-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: 42 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,11 @@ 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+
.map(|lit| PyLiteral { inner: lit.clone() })
65+
.collect()
7166
}
7267

7368
#[getter]
@@ -102,16 +97,16 @@ impl PyDataFile {
10297

10398
#[getter]
10499
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()
100+
self.inner.upper_bounds().collect()
106101
}
107102

108103
#[getter]
109104
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()
105+
self.inner.lower_bounds().collect()
111106
}
112107

113108
#[getter]
114-
fn key_metadata(&self) -> Option<&[u8]> {
109+
fn key_metadata(&self) -> Option<&[u8]> {
115110
self.inner.key_metadata()
116111
}
117112

@@ -129,36 +124,37 @@ impl PyDataFile {
129124
fn sort_order_id(&self) -> Option<i32> {
130125
self.inner.sort_order_id()
131126
}
132-
133127
}
134128

135129
#[pyclass]
136130
pub struct PyManifest {
137131
inner: Manifest,
138132
}
139133

140-
141134
#[pymethods]
142135
impl PyManifest {
143136
fn entries(&self) -> Vec<PyManifestEntry> {
144137
// TODO: Most of the time, we're only interested in 'alive' entries,
145138
// that are the ones that are either ADDED or EXISTING
146139
// so we can add a boolean to skip the DELETED entries right away before
147140
// moving it into the Python world
148-
self.inner.entries().iter().map(|entry| PyManifestEntry { inner: entry.clone() }).collect()
141+
self.inner
142+
.entries()
143+
.iter()
144+
.map(|entry| PyManifestEntry {
145+
inner: entry.clone(),
146+
})
147+
.collect()
149148
}
150149
}
151150

152-
153151
#[pyclass]
154152
pub struct PyFieldSummary {
155153
inner: FieldSummary,
156154
}
157155

158-
159156
#[pymethods]
160157
impl crate::manifest::PyFieldSummary {
161-
162158
#[getter]
163159
fn contains_null(&self) -> bool {
164160
self.inner.contains_null
@@ -170,25 +166,21 @@ impl crate::manifest::PyFieldSummary {
170166
}
171167

172168
#[getter]
173-
fn lower_bound(&self) -> Option<PyPrimitiveLiteral> {
174-
self.inner.lower_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
169+
fn lower_bound(&self) -> Option<Vec<u8>> {
170+
self.inner.lower_bound.clone().map(|b| b.to_vec())
175171
}
176172

177173
#[getter]
178-
fn upper_bound(&self) -> Option<PyPrimitiveLiteral> {
179-
self.inner.upper_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
174+
fn upper_bound(&self) -> Option<Vec<u8>> {
175+
self.inner.upper_bound.clone().map(|b| b.to_vec())
180176
}
181-
182-
183-
184177
}
185178

186179
#[pyclass]
187180
pub struct PyManifestFile {
188181
inner: ManifestFile,
189182
}
190183

191-
192184
#[pymethods]
193185
impl crate::manifest::PyManifestFile {
194186
#[getter]
@@ -214,7 +206,6 @@ impl crate::manifest::PyManifestFile {
214206
self.inner.sequence_number
215207
}
216208

217-
218209
#[getter]
219210
fn min_sequence_number(&self) -> i64 {
220211
self.inner.min_sequence_number
@@ -225,7 +216,6 @@ impl crate::manifest::PyManifestFile {
225216
self.inner.added_snapshot_id
226217
}
227218

228-
229219
#[getter]
230220
fn added_files_count(&self) -> Option<u32> {
231221
self.inner.added_files_count
@@ -258,16 +248,19 @@ impl crate::manifest::PyManifestFile {
258248

259249
#[getter]
260250
fn partitions(&self) -> Vec<PyFieldSummary> {
261-
self.inner.partitions.iter().map(|s| PyFieldSummary {
262-
inner: s.clone()
263-
}).collect()
251+
self.inner
252+
.partitions
253+
.clone()
254+
.unwrap()
255+
.iter()
256+
.map(|s| PyFieldSummary { inner: s.clone() })
257+
.collect()
264258
}
265259

266260
#[getter]
267261
fn key_metadata(&self) -> Vec<u8> {
268262
self.inner.key_metadata.clone()
269263
}
270-
271264
}
272265

273266
#[pyclass]
@@ -277,7 +270,6 @@ pub struct PyManifestEntry {
277270

278271
#[pymethods]
279272
impl PyManifestEntry {
280-
281273
#[getter]
282274
fn status(&self) -> i32 {
283275
ManifestStatus::Existing as i32
@@ -301,17 +293,16 @@ impl PyManifestEntry {
301293
#[getter]
302294
fn data_file(&self) -> PyDataFile {
303295
PyDataFile {
304-
inner: self.inner.data_file.clone()
296+
inner: self.inner.data_file.clone(),
305297
}
306298
}
307299
}
308300

309-
310301
#[pyfunction]
311302
pub fn read_manifest_entries(bs: &[u8]) -> PyManifest {
312303
// TODO: Some error handling
313304
PyManifest {
314-
inner: Manifest::parse_avro(bs).unwrap()
305+
inner: Manifest::parse_avro(bs).unwrap(),
315306
}
316307
}
317308

@@ -320,19 +311,23 @@ pub struct PyManifestList {
320311
inner: ManifestList,
321312
}
322313

323-
324314
#[pymethods]
325315
impl crate::manifest::PyManifestList {
326316
fn entries(&self) -> Vec<PyManifestFile> {
327-
self.inner.entries().iter().map(|file| PyManifestFile { inner: file.clone() }).collect()
317+
self.inner
318+
.entries()
319+
.iter()
320+
.map(|file| PyManifestFile {
321+
inner: file.clone(),
322+
})
323+
.collect()
328324
}
329325
}
330326

331-
332327
#[pyfunction]
333328
pub fn read_manifest_list(bs: &[u8]) -> PyManifestList {
334329
PyManifestList {
335-
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap()
330+
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap(),
336331
}
337332
}
338333

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)