Skip to content

Commit d5701d2

Browse files
authored
[Variant] Enhance the variant fuzzy test to cover time/timestamp/uuid primitive type (apache#8200)
# Which issue does this PR close? - Closes apache#8199. # Rationale for this change Add logic for the fuzzy test to cover time/timestampnanos/uuid. # What changes are included in this PR? - Add more cases in Variant Fuzzy Testing to cover the time/TimestampNanos/UUID # Are these changes tested? Covered by the existing test # Are there any user-facing changes? No
1 parent c71edce commit d5701d2

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

parquet-variant/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rust-version = { workspace = true }
3434
arrow-schema = { workspace = true }
3535
chrono = { workspace = true }
3636
indexmap = "2.10.0"
37-
uuid = { version = "1.18.0"}
37+
uuid = { version = "1.18.0", features = ["v4"]}
3838

3939
simdutf8 = { workspace = true , optional = true }
4040

parquet-variant/src/variant.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,12 @@ impl From<NaiveTime> for Variant<'_, '_> {
13281328
}
13291329
}
13301330

1331+
impl From<Uuid> for Variant<'_, '_> {
1332+
fn from(value: Uuid) -> Self {
1333+
Variant::Uuid(value)
1334+
}
1335+
}
1336+
13311337
impl<'v> From<&'v str> for Variant<'_, 'v> {
13321338
fn from(value: &'v str) -> Self {
13331339
if value.len() > MAX_SHORT_STRING_BYTES {

parquet-variant/tests/variant_interop.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use std::path::{Path, PathBuf};
2222
use std::{env, fs};
2323

24-
use chrono::{NaiveDate, NaiveTime};
24+
use chrono::{DateTime, NaiveDate, NaiveTime};
2525
use parquet_variant::{
2626
ShortString, Variant, VariantBuilder, VariantDecimal16, VariantDecimal4, VariantDecimal8,
2727
};
@@ -323,7 +323,7 @@ fn generate_random_value(rng: &mut StdRng, builder: &mut VariantBuilder, max_dep
323323
return;
324324
}
325325

326-
match rng.random_range(0..15) {
326+
match rng.random_range(0..18) {
327327
0 => builder.append_value(()),
328328
1 => builder.append_value(rng.random::<bool>()),
329329
2 => builder.append_value(rng.random::<i8>()),
@@ -333,11 +333,13 @@ fn generate_random_value(rng: &mut StdRng, builder: &mut VariantBuilder, max_dep
333333
6 => builder.append_value(rng.random::<f32>()),
334334
7 => builder.append_value(rng.random::<f64>()),
335335
8 => {
336+
// String
336337
let len = rng.random_range(0..50);
337338
let s: String = (0..len).map(|_| rng.random::<char>()).collect();
338339
builder.append_value(s.as_str());
339340
}
340341
9 => {
342+
// Binary
341343
let len = rng.random_range(0..50);
342344
let bytes: Vec<u8> = (0..len).map(|_| rng.random()).collect();
343345
builder.append_value(bytes.as_slice());
@@ -384,6 +386,34 @@ fn generate_random_value(rng: &mut StdRng, builder: &mut VariantBuilder, max_dep
384386
}
385387
object_builder.finish().unwrap();
386388
}
389+
15 => {
390+
// Time
391+
builder.append_value(
392+
NaiveTime::from_num_seconds_from_midnight_opt(
393+
// make the argument always valid
394+
rng.random_range(0..86_400),
395+
rng.random_range(0..1_000_000_000),
396+
)
397+
.unwrap(),
398+
)
399+
}
400+
16 => {
401+
let data_time = DateTime::from_timestamp(
402+
// make the argument always valid
403+
rng.random_range(0..86_400),
404+
rng.random_range(0..1_000_000_000),
405+
)
406+
.unwrap();
407+
408+
// timestamp w/o timezone
409+
builder.append_value(data_time.naive_local());
410+
411+
// timestamp with timezone
412+
builder.append_value(data_time.naive_utc().and_utc());
413+
}
414+
17 => {
415+
builder.append_value(Uuid::new_v4());
416+
}
387417
_ => unreachable!(),
388418
}
389419
}

0 commit comments

Comments
 (0)