Skip to content

Commit 5478d58

Browse files
committed
Cleanup
1 parent 7c63887 commit 5478d58

File tree

3 files changed

+56
-49
lines changed

3 files changed

+56
-49
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 & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,28 @@
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

25-
#[pyclass]
26-
pub struct PyLiteral {
27-
inner: Literal,
28-
}
29-
21+
use iceberg::spec::{
22+
DataFile, DataFileFormat, FieldSummary, FormatVersion, Manifest, ManifestEntry, ManifestFile,
23+
ManifestList, ManifestStatus, PrimitiveLiteral,
24+
};
25+
use pyo3::prelude::*;
3026

3127
#[pyclass]
28+
#[allow(dead_code)]
3229
pub struct PyPrimitiveLiteral {
33-
inner: PrimitiveLiteral,
30+
inner: Option<PrimitiveLiteral>,
3431
}
3532

36-
3733
#[pyclass]
3834
pub struct PyDataFile {
3935
inner: DataFile,
4036
}
4137

4238
#[pymethods]
4339
impl PyDataFile {
44-
4540
#[getter]
4641
fn content(&self) -> i32 {
4742
self.inner.content_type() as i32
@@ -63,11 +58,14 @@ impl PyDataFile {
6358
}
6459

6560
#[getter]
66-
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+
fn partition(&self) -> Vec<PyPrimitiveLiteral> {
62+
self.inner
63+
.partition()
64+
.iter()
65+
.map(|lit| PyPrimitiveLiteral {
66+
inner: lit.map(|l| l.as_primitive_literal().unwrap()),
67+
})
68+
.collect()
7169
}
7270

7371
#[getter]
@@ -102,16 +100,24 @@ impl PyDataFile {
102100

103101
#[getter]
104102
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()
103+
self.inner
104+
.upper_bounds()
105+
.iter()
106+
.map(|(k, v)| (*k, v.to_bytes().unwrap().to_vec()))
107+
.collect()
106108
}
107109

108110
#[getter]
109111
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()
112+
self.inner
113+
.lower_bounds()
114+
.iter()
115+
.map(|(k, v)| (*k, v.to_bytes().unwrap().to_vec()))
116+
.collect()
111117
}
112118

113119
#[getter]
114-
fn key_metadata(&self) -> Option<&[u8]> {
120+
fn key_metadata(&self) -> Option<&[u8]> {
115121
self.inner.key_metadata()
116122
}
117123

@@ -129,36 +135,37 @@ impl PyDataFile {
129135
fn sort_order_id(&self) -> Option<i32> {
130136
self.inner.sort_order_id()
131137
}
132-
133138
}
134139

135140
#[pyclass]
136141
pub struct PyManifest {
137142
inner: Manifest,
138143
}
139144

140-
141145
#[pymethods]
142146
impl PyManifest {
143147
fn entries(&self) -> Vec<PyManifestEntry> {
144148
// TODO: Most of the time, we're only interested in 'alive' entries,
145149
// that are the ones that are either ADDED or EXISTING
146150
// so we can add a boolean to skip the DELETED entries right away before
147151
// moving it into the Python world
148-
self.inner.entries().iter().map(|entry| PyManifestEntry { inner: entry.clone() }).collect()
152+
self.inner
153+
.entries()
154+
.iter()
155+
.map(|entry| PyManifestEntry {
156+
inner: entry.clone(),
157+
})
158+
.collect()
149159
}
150160
}
151161

152-
153162
#[pyclass]
154163
pub struct PyFieldSummary {
155164
inner: FieldSummary,
156165
}
157166

158-
159167
#[pymethods]
160168
impl crate::manifest::PyFieldSummary {
161-
162169
#[getter]
163170
fn contains_null(&self) -> bool {
164171
self.inner.contains_null
@@ -170,25 +177,21 @@ impl crate::manifest::PyFieldSummary {
170177
}
171178

172179
#[getter]
173-
fn lower_bound(&self) -> Option<PyPrimitiveLiteral> {
174-
self.inner.lower_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
180+
fn lower_bound(&self) -> Option<Vec<u8>> {
181+
self.inner.lower_bound.clone().map(|b| b.to_vec())
175182
}
176183

177184
#[getter]
178-
fn upper_bound(&self) -> Option<PyPrimitiveLiteral> {
179-
self.inner.upper_bound.clone().map(|v| PyPrimitiveLiteral{ inner: v.literal().clone() })
185+
fn upper_bound(&self) -> Option<Vec<u8>> {
186+
self.inner.upper_bound.clone().map(|b| b.to_vec())
180187
}
181-
182-
183-
184188
}
185189

186190
#[pyclass]
187191
pub struct PyManifestFile {
188192
inner: ManifestFile,
189193
}
190194

191-
192195
#[pymethods]
193196
impl crate::manifest::PyManifestFile {
194197
#[getter]
@@ -214,7 +217,6 @@ impl crate::manifest::PyManifestFile {
214217
self.inner.sequence_number
215218
}
216219

217-
218220
#[getter]
219221
fn min_sequence_number(&self) -> i64 {
220222
self.inner.min_sequence_number
@@ -225,7 +227,6 @@ impl crate::manifest::PyManifestFile {
225227
self.inner.added_snapshot_id
226228
}
227229

228-
229230
#[getter]
230231
fn added_files_count(&self) -> Option<u32> {
231232
self.inner.added_files_count
@@ -258,16 +259,19 @@ impl crate::manifest::PyManifestFile {
258259

259260
#[getter]
260261
fn partitions(&self) -> Vec<PyFieldSummary> {
261-
self.inner.partitions.iter().map(|s| PyFieldSummary {
262-
inner: s.clone()
263-
}).collect()
262+
self.inner
263+
.partitions
264+
.clone()
265+
.unwrap()
266+
.iter()
267+
.map(|s| PyFieldSummary { inner: s.clone() })
268+
.collect()
264269
}
265270

266271
#[getter]
267272
fn key_metadata(&self) -> Vec<u8> {
268273
self.inner.key_metadata.clone()
269274
}
270-
271275
}
272276

273277
#[pyclass]
@@ -277,7 +281,6 @@ pub struct PyManifestEntry {
277281

278282
#[pymethods]
279283
impl PyManifestEntry {
280-
281284
#[getter]
282285
fn status(&self) -> i32 {
283286
ManifestStatus::Existing as i32
@@ -301,17 +304,16 @@ impl PyManifestEntry {
301304
#[getter]
302305
fn data_file(&self) -> PyDataFile {
303306
PyDataFile {
304-
inner: self.inner.data_file.clone()
307+
inner: self.inner.data_file.clone(),
305308
}
306309
}
307310
}
308311

309-
310312
#[pyfunction]
311313
pub fn read_manifest_entries(bs: &[u8]) -> PyManifest {
312314
// TODO: Some error handling
313315
PyManifest {
314-
inner: Manifest::parse_avro(bs).unwrap()
316+
inner: Manifest::parse_avro(bs).unwrap(),
315317
}
316318
}
317319

@@ -320,19 +322,23 @@ pub struct PyManifestList {
320322
inner: ManifestList,
321323
}
322324

323-
324325
#[pymethods]
325326
impl crate::manifest::PyManifestList {
326327
fn entries(&self) -> Vec<PyManifestFile> {
327-
self.inner.entries().iter().map(|file| PyManifestFile { inner: file.clone() }).collect()
328+
self.inner
329+
.entries()
330+
.iter()
331+
.map(|file| PyManifestFile {
332+
inner: file.clone(),
333+
})
334+
.collect()
328335
}
329336
}
330337

331-
332338
#[pyfunction]
333339
pub fn read_manifest_list(bs: &[u8]) -> PyManifestList {
334340
PyManifestList {
335-
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap()
341+
inner: ManifestList::parse_with_version(bs, FormatVersion::V2).unwrap(),
336342
}
337343
}
338344

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)