parquet 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.lock +282 -167
- data/ext/parquet/Cargo.toml +4 -3
- data/ext/parquet/src/reader/unified/mod.rs +55 -20
- data/ext/parquet/src/types/mod.rs +2 -0
- data/ext/parquet/src/types/record_types.rs +178 -10
- data/lib/parquet/version.rb +1 -1
- metadata +2 -2
data/ext/parquet/Cargo.toml
CHANGED
@@ -11,20 +11,21 @@ rb-sys-env = "^0.2"
|
|
11
11
|
|
12
12
|
[dependencies]
|
13
13
|
ahash = "0.8"
|
14
|
-
arrow-array = { git = "https://github.com/njaremko/arrow-rs", branch = "nathan/fix-
|
15
|
-
arrow-schema = { git = "https://github.com/njaremko/arrow-rs", branch = "nathan/fix-
|
14
|
+
arrow-array = { git = "https://github.com/njaremko/arrow-rs", branch = "nathan/fix-time" }
|
15
|
+
arrow-schema = { git = "https://github.com/njaremko/arrow-rs", branch = "nathan/fix-time" }
|
16
16
|
bytes = "^1.9"
|
17
17
|
either = "1.9"
|
18
18
|
itertools = "^0.14"
|
19
19
|
jiff = "0.2"
|
20
20
|
magnus = { version = "0.7", features = ["rb-sys"] }
|
21
|
-
parquet = { git = "https://github.com/njaremko/arrow-rs", branch = "nathan/fix-
|
21
|
+
parquet = { git = "https://github.com/njaremko/arrow-rs", branch = "nathan/fix-time", features = ["json"] }
|
22
22
|
rand = "0.9"
|
23
23
|
rb-sys = "^0.9"
|
24
24
|
simdutf8 = "0.1.5"
|
25
25
|
tempfile = "^3.15"
|
26
26
|
thiserror = "2.0"
|
27
27
|
num = "0.4.3"
|
28
|
+
uuid = "1.16.0"
|
28
29
|
|
29
30
|
[target.'cfg(target_os = "linux")'.dependencies]
|
30
31
|
jemallocator = { version = "0.5", features = ["disable_initial_exec_tls"] }
|
@@ -2,8 +2,8 @@ use crate::header_cache::StringCache;
|
|
2
2
|
use crate::logger::RubyLogger;
|
3
3
|
use crate::types::TryIntoValue;
|
4
4
|
use crate::{
|
5
|
-
create_column_enumerator, create_row_enumerator,
|
6
|
-
|
5
|
+
create_column_enumerator, create_row_enumerator, ColumnEnumeratorArgs, ColumnRecord,
|
6
|
+
ParquetField, ParquetGemError, ParquetValueVec, ParserResultType, RowEnumeratorArgs, RowRecord,
|
7
7
|
};
|
8
8
|
use ahash::RandomState;
|
9
9
|
use either::Either;
|
@@ -13,10 +13,10 @@ use std::collections::HashMap;
|
|
13
13
|
use std::rc::Rc;
|
14
14
|
use std::sync::OnceLock;
|
15
15
|
|
16
|
-
use crate::types::ArrayWrapper;
|
17
16
|
use super::common::{
|
18
17
|
create_batch_reader, handle_block_or_enum, handle_empty_file, open_parquet_source,
|
19
18
|
};
|
19
|
+
use crate::types::ArrayWrapper;
|
20
20
|
|
21
21
|
/// A unified parser configuration that can be used for both row and column parsing
|
22
22
|
pub enum ParserType {
|
@@ -53,11 +53,11 @@ pub fn parse_parquet_unified(
|
|
53
53
|
} = args;
|
54
54
|
|
55
55
|
// Initialize the logger if provided
|
56
|
-
let ruby_logger = RubyLogger::new(&ruby, logger
|
57
|
-
|
56
|
+
let ruby_logger = RubyLogger::new(&ruby, logger)?;
|
57
|
+
|
58
58
|
// Clone values for the closure to avoid move issues
|
59
59
|
let columns_clone = columns.clone();
|
60
|
-
|
60
|
+
|
61
61
|
// Determine if we're handling rows or columns for enumerator creation
|
62
62
|
match &parser_type {
|
63
63
|
ParserType::Row { strict } => {
|
@@ -75,13 +75,13 @@ pub fn parse_parquet_unified(
|
|
75
75
|
})? {
|
76
76
|
return Ok(enum_value);
|
77
77
|
}
|
78
|
-
}
|
78
|
+
}
|
79
79
|
ParserType::Column { batch_size, strict } => {
|
80
80
|
// For column-based parsing, log the batch size if present
|
81
81
|
if let Some(ref bs) = batch_size {
|
82
82
|
ruby_logger.debug(|| format!("Using batch size: {}", bs))?;
|
83
83
|
}
|
84
|
-
|
84
|
+
|
85
85
|
// Handle block or create column enumerator
|
86
86
|
if let Some(enum_value) = handle_block_or_enum(&ruby, ruby.block_given(), || {
|
87
87
|
create_column_enumerator(ColumnEnumeratorArgs {
|
@@ -102,19 +102,34 @@ pub fn parse_parquet_unified(
|
|
102
102
|
|
103
103
|
// Open the Parquet source
|
104
104
|
let source = open_parquet_source(ruby.clone(), to_read)?;
|
105
|
-
|
105
|
+
|
106
106
|
// Based on the parser type, handle the data differently
|
107
107
|
match parser_type {
|
108
108
|
ParserType::Row { strict } => {
|
109
109
|
// Handle row-based parsing
|
110
|
-
process_row_data(
|
111
|
-
|
110
|
+
process_row_data(
|
111
|
+
ruby.clone(),
|
112
|
+
source,
|
113
|
+
&columns,
|
114
|
+
result_type,
|
115
|
+
strict,
|
116
|
+
&ruby_logger,
|
117
|
+
)?;
|
118
|
+
}
|
112
119
|
ParserType::Column { batch_size, strict } => {
|
113
120
|
// Handle column-based parsing
|
114
|
-
process_column_data(
|
121
|
+
process_column_data(
|
122
|
+
ruby.clone(),
|
123
|
+
source,
|
124
|
+
&columns,
|
125
|
+
result_type,
|
126
|
+
batch_size,
|
127
|
+
strict,
|
128
|
+
&ruby_logger,
|
129
|
+
)?;
|
115
130
|
}
|
116
131
|
}
|
117
|
-
|
132
|
+
|
118
133
|
Ok(ruby.qnil().into_value_with(&ruby))
|
119
134
|
}
|
120
135
|
|
@@ -129,7 +144,7 @@ fn process_row_data(
|
|
129
144
|
) -> Result<(), ParquetGemError> {
|
130
145
|
use parquet::file::reader::{FileReader, SerializedFileReader};
|
131
146
|
use parquet::record::reader::RowIter as ParquetRowIter;
|
132
|
-
|
147
|
+
|
133
148
|
// Create the row-based reader
|
134
149
|
let reader: Box<dyn FileReader> = match source {
|
135
150
|
Either::Left(file) => {
|
@@ -174,8 +189,19 @@ fn process_row_data(
|
|
174
189
|
|
175
190
|
let mut map =
|
176
191
|
HashMap::with_capacity_and_hasher(headers.len(), RandomState::default());
|
177
|
-
for (i, (_, v)
|
178
|
-
|
192
|
+
for (i, ((_, v), t)) in
|
193
|
+
row.get_column_iter().zip(schema.get_fields()).enumerate()
|
194
|
+
{
|
195
|
+
let type_info = t.get_basic_info();
|
196
|
+
map.insert(
|
197
|
+
headers[i],
|
198
|
+
ParquetField {
|
199
|
+
field: v.clone(),
|
200
|
+
converted_type: type_info.converted_type(),
|
201
|
+
logical_type: type_info.logical_type().clone(),
|
202
|
+
strict,
|
203
|
+
},
|
204
|
+
);
|
179
205
|
}
|
180
206
|
map
|
181
207
|
})
|
@@ -193,8 +219,14 @@ fn process_row_data(
|
|
193
219
|
row.map(|row| {
|
194
220
|
let column_count = row.get_column_iter().count();
|
195
221
|
let mut vec = Vec::with_capacity(column_count);
|
196
|
-
for (_, v) in row.get_column_iter() {
|
197
|
-
|
222
|
+
for ((_, v), t) in row.get_column_iter().zip(schema.get_fields()) {
|
223
|
+
let type_info = t.get_basic_info();
|
224
|
+
vec.push(ParquetField {
|
225
|
+
field: v.clone(),
|
226
|
+
converted_type: type_info.converted_type(),
|
227
|
+
logical_type: type_info.logical_type().clone(),
|
228
|
+
strict,
|
229
|
+
});
|
198
230
|
}
|
199
231
|
vec
|
200
232
|
})
|
@@ -309,7 +341,10 @@ fn process_column_data(
|
|
309
341
|
}
|
310
342
|
|
311
343
|
/// Helper function to create a projection schema
|
312
|
-
fn create_projection_schema(
|
344
|
+
fn create_projection_schema(
|
345
|
+
schema: &parquet::schema::types::Type,
|
346
|
+
columns: &[String],
|
347
|
+
) -> parquet::schema::types::Type {
|
313
348
|
if let parquet::schema::types::Type::GroupType { fields, .. } = schema {
|
314
349
|
let projected_fields: Vec<std::sync::Arc<parquet::schema::types::Type>> = fields
|
315
350
|
.iter()
|
@@ -325,4 +360,4 @@ fn create_projection_schema(schema: &parquet::schema::types::Type, columns: &[St
|
|
325
360
|
// Return original schema if not a group type
|
326
361
|
schema.clone()
|
327
362
|
}
|
328
|
-
}
|
363
|
+
}
|
@@ -1,7 +1,10 @@
|
|
1
1
|
use std::sync::OnceLock;
|
2
2
|
|
3
3
|
use itertools::Itertools;
|
4
|
-
use parquet::
|
4
|
+
use parquet::{
|
5
|
+
basic::{ConvertedType, LogicalType},
|
6
|
+
data_type::AsBytes,
|
7
|
+
};
|
5
8
|
|
6
9
|
use super::*;
|
7
10
|
|
@@ -44,7 +47,13 @@ pub enum ColumnRecord<S: BuildHasher + Default> {
|
|
44
47
|
}
|
45
48
|
|
46
49
|
#[derive(Debug)]
|
47
|
-
pub struct ParquetField
|
50
|
+
pub struct ParquetField {
|
51
|
+
pub field: Field,
|
52
|
+
#[allow(dead_code)]
|
53
|
+
pub converted_type: ConvertedType,
|
54
|
+
pub logical_type: Option<LogicalType>,
|
55
|
+
pub strict: bool,
|
56
|
+
}
|
48
57
|
|
49
58
|
impl<S: BuildHasher + Default> TryIntoValue for RowRecord<S> {
|
50
59
|
fn try_into_value_with(self, handle: &Ruby) -> Result<Value, ParquetGemError> {
|
@@ -158,7 +167,7 @@ pub trait TryIntoValue {
|
|
158
167
|
|
159
168
|
impl TryIntoValue for ParquetField {
|
160
169
|
fn try_into_value_with(self, handle: &Ruby) -> Result<Value, ParquetGemError> {
|
161
|
-
match self.
|
170
|
+
match self.field {
|
162
171
|
Field::Null => Ok(handle.qnil().as_value()),
|
163
172
|
Field::Bool(b) => Ok(b.into_value_with(handle)),
|
164
173
|
Field::Short(s) => Ok(s.into_value_with(handle)),
|
@@ -172,7 +181,7 @@ impl TryIntoValue for ParquetField {
|
|
172
181
|
Field::Float(f) => Ok(f.into_value_with(handle)),
|
173
182
|
Field::Double(d) => Ok(d.into_value_with(handle)),
|
174
183
|
Field::Str(s) => {
|
175
|
-
if self.
|
184
|
+
if self.strict {
|
176
185
|
Ok(simdutf8::basic::from_utf8(s.as_bytes())
|
177
186
|
.map_err(ParquetGemError::Utf8Error)
|
178
187
|
.map(|s| s.into_value_with(handle))?)
|
@@ -182,12 +191,27 @@ impl TryIntoValue for ParquetField {
|
|
182
191
|
}
|
183
192
|
}
|
184
193
|
Field::Byte(b) => Ok(b.into_value_with(handle)),
|
185
|
-
Field::Bytes(b) =>
|
194
|
+
Field::Bytes(b) => {
|
195
|
+
if matches!(self.logical_type, Some(parquet::basic::LogicalType::Uuid)) {
|
196
|
+
let bytes = b.as_bytes();
|
197
|
+
let uuid = uuid::Uuid::from_slice(bytes)?;
|
198
|
+
Ok(uuid.to_string().into_value_with(handle))
|
199
|
+
} else {
|
200
|
+
Ok(handle.str_from_slice(b.data()).as_value())
|
201
|
+
}
|
202
|
+
}
|
186
203
|
Field::Date(d) => {
|
187
204
|
let ts = jiff::Timestamp::from_second((d as i64) * 86400)?;
|
188
205
|
let formatted = ts.strftime("%Y-%m-%d").to_string();
|
189
206
|
Ok(formatted.into_value_with(handle))
|
190
207
|
}
|
208
|
+
Field::TimeMillis(ts) => {
|
209
|
+
let ts = jiff::Timestamp::from_millisecond(ts as i64)?;
|
210
|
+
let time_class = handle.class_time();
|
211
|
+
Ok(time_class
|
212
|
+
.funcall::<_, _, Value>("parse", (ts.to_string(),))?
|
213
|
+
.into_value_with(handle))
|
214
|
+
}
|
191
215
|
Field::TimestampMillis(ts) => {
|
192
216
|
let ts = jiff::Timestamp::from_millisecond(ts)?;
|
193
217
|
let time_class = handle.class_time();
|
@@ -195,7 +219,7 @@ impl TryIntoValue for ParquetField {
|
|
195
219
|
.funcall::<_, _, Value>("parse", (ts.to_string(),))?
|
196
220
|
.into_value_with(handle))
|
197
221
|
}
|
198
|
-
Field::TimestampMicros(ts) => {
|
222
|
+
Field::TimestampMicros(ts) | Field::TimeMicros(ts) => {
|
199
223
|
let ts = jiff::Timestamp::from_microsecond(ts)?;
|
200
224
|
let time_class = handle.class_time();
|
201
225
|
Ok(time_class
|
@@ -206,7 +230,15 @@ impl TryIntoValue for ParquetField {
|
|
206
230
|
let elements = list.elements();
|
207
231
|
let ary = handle.ary_new_capa(elements.len());
|
208
232
|
elements.iter().try_for_each(|e| {
|
209
|
-
ary.push(
|
233
|
+
ary.push(
|
234
|
+
ParquetField {
|
235
|
+
field: e.clone(),
|
236
|
+
logical_type: e.to_logical_type(),
|
237
|
+
converted_type: e.to_converted_type(),
|
238
|
+
strict: self.strict,
|
239
|
+
}
|
240
|
+
.try_into_value_with(handle)?,
|
241
|
+
)?;
|
210
242
|
Ok::<_, ParquetGemError>(())
|
211
243
|
})?;
|
212
244
|
Ok(ary.into_value_with(handle))
|
@@ -220,8 +252,20 @@ impl TryIntoValue for ParquetField {
|
|
220
252
|
|
221
253
|
map.entries().iter().try_for_each(|(k, v)| {
|
222
254
|
hash.aset(
|
223
|
-
ParquetField
|
224
|
-
|
255
|
+
ParquetField {
|
256
|
+
field: k.clone(),
|
257
|
+
converted_type: k.to_converted_type(),
|
258
|
+
logical_type: k.to_logical_type(),
|
259
|
+
strict: self.strict,
|
260
|
+
}
|
261
|
+
.try_into_value_with(handle)?,
|
262
|
+
ParquetField {
|
263
|
+
field: v.clone(),
|
264
|
+
converted_type: v.to_converted_type(),
|
265
|
+
logical_type: v.to_logical_type(),
|
266
|
+
strict: self.strict,
|
267
|
+
}
|
268
|
+
.try_into_value_with(handle)?,
|
225
269
|
)?;
|
226
270
|
Ok::<_, ParquetGemError>(())
|
227
271
|
})?;
|
@@ -278,7 +322,13 @@ impl TryIntoValue for ParquetField {
|
|
278
322
|
row.get_column_iter().try_for_each(|(k, v)| {
|
279
323
|
hash.aset(
|
280
324
|
k.clone().into_value_with(handle),
|
281
|
-
ParquetField
|
325
|
+
ParquetField {
|
326
|
+
field: v.clone(),
|
327
|
+
converted_type: v.to_converted_type(),
|
328
|
+
logical_type: v.to_logical_type(),
|
329
|
+
strict: self.strict,
|
330
|
+
}
|
331
|
+
.try_into_value_with(handle)?,
|
282
332
|
)?;
|
283
333
|
Ok::<_, ParquetGemError>(())
|
284
334
|
})?;
|
@@ -287,3 +337,121 @@ impl TryIntoValue for ParquetField {
|
|
287
337
|
}
|
288
338
|
}
|
289
339
|
}
|
340
|
+
|
341
|
+
trait ToTypeInfo {
|
342
|
+
fn to_converted_type(&self) -> ConvertedType;
|
343
|
+
fn to_logical_type(&self) -> Option<LogicalType>;
|
344
|
+
}
|
345
|
+
|
346
|
+
impl ToTypeInfo for &parquet::record::Field {
|
347
|
+
fn to_converted_type(&self) -> ConvertedType {
|
348
|
+
match self {
|
349
|
+
Field::Null => ConvertedType::NONE,
|
350
|
+
Field::Bool(_) => ConvertedType::INT_8,
|
351
|
+
Field::Byte(_) => ConvertedType::INT_8,
|
352
|
+
Field::Short(_) => ConvertedType::INT_16,
|
353
|
+
Field::Int(_) => ConvertedType::INT_32,
|
354
|
+
Field::Long(_) => ConvertedType::INT_64,
|
355
|
+
Field::UByte(_) => ConvertedType::UINT_8,
|
356
|
+
Field::UShort(_) => ConvertedType::UINT_16,
|
357
|
+
Field::UInt(_) => ConvertedType::UINT_32,
|
358
|
+
Field::ULong(_) => ConvertedType::UINT_64,
|
359
|
+
Field::Float16(_) => ConvertedType::NONE,
|
360
|
+
Field::Float(_) => ConvertedType::NONE,
|
361
|
+
Field::Double(_) => ConvertedType::NONE,
|
362
|
+
Field::Decimal(_) => ConvertedType::DECIMAL,
|
363
|
+
Field::Str(_) => ConvertedType::UTF8,
|
364
|
+
Field::Bytes(_) => ConvertedType::LIST,
|
365
|
+
Field::Date(_) => ConvertedType::DATE,
|
366
|
+
Field::TimeMillis(_) => ConvertedType::TIME_MILLIS,
|
367
|
+
Field::TimeMicros(_) => ConvertedType::TIMESTAMP_MICROS,
|
368
|
+
Field::TimestampMillis(_) => ConvertedType::TIMESTAMP_MILLIS,
|
369
|
+
Field::TimestampMicros(_) => ConvertedType::TIMESTAMP_MICROS,
|
370
|
+
Field::Group(_) => ConvertedType::NONE,
|
371
|
+
Field::ListInternal(_) => ConvertedType::LIST,
|
372
|
+
Field::MapInternal(_) => ConvertedType::MAP,
|
373
|
+
}
|
374
|
+
}
|
375
|
+
fn to_logical_type(&self) -> Option<LogicalType> {
|
376
|
+
Some(match self {
|
377
|
+
Field::Null => LogicalType::Unknown,
|
378
|
+
Field::Bool(_) => LogicalType::Integer {
|
379
|
+
bit_width: 1,
|
380
|
+
is_signed: false,
|
381
|
+
},
|
382
|
+
Field::Byte(_) => LogicalType::Integer {
|
383
|
+
bit_width: 8,
|
384
|
+
is_signed: false,
|
385
|
+
},
|
386
|
+
Field::Short(_) => LogicalType::Integer {
|
387
|
+
bit_width: 16,
|
388
|
+
is_signed: true,
|
389
|
+
},
|
390
|
+
Field::Int(_) => LogicalType::Integer {
|
391
|
+
bit_width: 32,
|
392
|
+
is_signed: true,
|
393
|
+
},
|
394
|
+
Field::Long(_) => LogicalType::Integer {
|
395
|
+
bit_width: 64,
|
396
|
+
is_signed: true,
|
397
|
+
},
|
398
|
+
Field::UByte(_) => LogicalType::Integer {
|
399
|
+
bit_width: 8,
|
400
|
+
is_signed: false,
|
401
|
+
},
|
402
|
+
Field::UShort(_) => LogicalType::Integer {
|
403
|
+
bit_width: 16,
|
404
|
+
is_signed: false,
|
405
|
+
},
|
406
|
+
Field::UInt(_) => LogicalType::Integer {
|
407
|
+
bit_width: 32,
|
408
|
+
is_signed: false,
|
409
|
+
},
|
410
|
+
Field::ULong(_) => LogicalType::Integer {
|
411
|
+
bit_width: 64,
|
412
|
+
is_signed: false,
|
413
|
+
},
|
414
|
+
Field::Float16(_) => LogicalType::Float16,
|
415
|
+
Field::Float(_) => LogicalType::Decimal {
|
416
|
+
scale: 7,
|
417
|
+
precision: 7,
|
418
|
+
},
|
419
|
+
Field::Double(_) => LogicalType::Decimal {
|
420
|
+
scale: 15,
|
421
|
+
precision: 15,
|
422
|
+
},
|
423
|
+
Field::Decimal(decimal) => LogicalType::Decimal {
|
424
|
+
scale: decimal.scale(),
|
425
|
+
precision: decimal.precision(),
|
426
|
+
},
|
427
|
+
Field::Str(_) => LogicalType::String,
|
428
|
+
Field::Bytes(b) => {
|
429
|
+
if b.data().len() == 16 && uuid::Uuid::from_slice(b.as_bytes()).is_ok() {
|
430
|
+
LogicalType::Uuid
|
431
|
+
} else {
|
432
|
+
LogicalType::Unknown
|
433
|
+
}
|
434
|
+
}
|
435
|
+
Field::Date(_) => LogicalType::Date,
|
436
|
+
Field::TimeMillis(_) => LogicalType::Time {
|
437
|
+
is_adjusted_to_u_t_c: true,
|
438
|
+
unit: parquet::basic::TimeUnit::MILLIS(parquet::format::MilliSeconds {}),
|
439
|
+
},
|
440
|
+
Field::TimeMicros(_) => LogicalType::Time {
|
441
|
+
is_adjusted_to_u_t_c: true,
|
442
|
+
unit: parquet::basic::TimeUnit::MICROS(parquet::format::MicroSeconds {}),
|
443
|
+
},
|
444
|
+
Field::TimestampMillis(_) => LogicalType::Timestamp {
|
445
|
+
is_adjusted_to_u_t_c: true,
|
446
|
+
unit: parquet::basic::TimeUnit::MILLIS(parquet::format::MilliSeconds {}),
|
447
|
+
},
|
448
|
+
Field::TimestampMicros(_) => LogicalType::Timestamp {
|
449
|
+
is_adjusted_to_u_t_c: true,
|
450
|
+
unit: parquet::basic::TimeUnit::MICROS(parquet::format::MicroSeconds {}),
|
451
|
+
},
|
452
|
+
Field::Group(_) => LogicalType::Unknown,
|
453
|
+
Field::ListInternal(_) => LogicalType::List,
|
454
|
+
Field::MapInternal(_) => LogicalType::Map,
|
455
|
+
})
|
456
|
+
}
|
457
|
+
}
|
data/lib/parquet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parquet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Jaremko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|