Skip to content

Commit 12cc86f

Browse files
committed
test(datafusion): trim scan constructor coverage
1 parent 3ce07d5 commit 12cc86f

1 file changed

Lines changed: 33 additions & 75 deletions

File tree

  • crates/integrations/datafusion/src/physical_plan

crates/integrations/datafusion/src/physical_plan/scan.rs

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ mod tests {
437437

438438
use datafusion::arrow::datatypes::{DataType, Field, Schema as ArrowSchema};
439439
use datafusion::physical_plan::ExecutionPlan;
440-
use datafusion::prelude::{Expr, col, lit};
441440
use iceberg::TableIdent;
442441
use iceberg::expr::Reference;
443442
use iceberg::io::FileIO;
@@ -446,118 +445,77 @@ mod tests {
446445

447446
use super::*;
448447

449-
async fn test_table() -> Table {
450-
let metadata_path = format!(
451-
"{}/tests/test_data/TableMetadataV2Valid.json",
452-
env!("CARGO_MANIFEST_DIR")
448+
async fn get_test_table_from_metadata_file() -> Table {
449+
let metadata_file_name = "TableMetadataV2Valid.json";
450+
let metadata_file_path = format!(
451+
"{}/tests/test_data/{}",
452+
env!("CARGO_MANIFEST_DIR"),
453+
metadata_file_name
453454
);
454455
let ident = TableIdent::from_strs(["ns", "scan_table"]).unwrap();
455-
StaticTable::from_metadata_file(&metadata_path, ident, FileIO::new_with_fs())
456+
StaticTable::from_metadata_file(&metadata_file_path, ident, FileIO::new_with_fs())
456457
.await
457458
.unwrap()
458459
.into_table()
459460
}
460461

461-
fn arrow_schema() -> ArrowSchemaRef {
462+
fn create_test_arrow_schema() -> ArrowSchemaRef {
462463
Arc::new(ArrowSchema::new(vec![
463464
Field::new("x", DataType::Int64, false),
464465
Field::new("y", DataType::Int64, false),
465466
Field::new("z", DataType::Int64, false),
466467
]))
467468
}
468469

469-
fn filters() -> Vec<Expr> {
470-
vec![col("x").gt(lit(5i64))]
471-
}
472-
473-
// The Expr and predicate constructors must agree: `new_with_tasks` only
474-
// pre-converts the filters that `new_with_tasks_from_predicate` takes raw.
475470
#[tokio::test]
476-
async fn expr_and_predicate_constructors_agree() {
477-
let table = test_table().await;
471+
async fn test_predicate_constructor_exposes_rebuild_inputs() {
472+
let schema = create_test_arrow_schema();
478473
let projection = vec![0usize, 2];
479-
let from_filters = IcebergTableScan::new_with_tasks(
480-
table.clone(),
481-
None,
482-
arrow_schema(),
483-
Some(&projection),
484-
&filters(),
485-
Some(100),
486-
vec![vec![], vec![]],
487-
Partitioning::UnknownPartitioning(2),
488-
);
489-
let from_predicate = IcebergTableScan::new_with_tasks_from_predicate(
490-
table,
474+
let predicate = Reference::new("x").greater_than(Datum::long(5));
475+
let scan = IcebergTableScan::new_with_tasks_from_predicate(
476+
get_test_table_from_metadata_file().await,
491477
None,
492-
arrow_schema(),
478+
schema.clone(),
493479
Some(&projection),
494-
convert_filters_to_predicate(&filters()),
480+
Some(predicate.clone()),
495481
Some(100),
496482
vec![vec![], vec![]],
497483
Partitioning::UnknownPartitioning(2),
498484
);
499485

500-
assert_eq!(from_filters.predicates(), from_predicate.predicates());
501-
assert_eq!(from_filters.projection(), from_predicate.projection());
502-
assert_eq!(
503-
from_filters.schema().fields(),
504-
from_predicate.schema().fields()
505-
);
506-
assert_eq!(
507-
format!("{:?}", from_filters.properties().output_partitioning()),
508-
format!("{:?}", from_predicate.properties().output_partitioning()),
509-
);
510-
}
511-
512-
// table_schema() exposes the full pre-projection schema; schema() is projected.
513-
#[tokio::test]
514-
async fn getters_expose_full_schema_and_indices() {
515-
let projection = vec![0usize, 2];
516-
let scan = IcebergTableScan::new(
517-
test_table().await,
518-
None,
519-
arrow_schema(),
520-
Some(&projection),
521-
&[],
522-
None,
523-
);
524-
525-
assert_eq!(scan.table_schema().fields(), arrow_schema().fields());
486+
assert_eq!(scan.predicates(), Some(&predicate));
487+
assert_eq!(scan.table_schema().fields(), schema.fields());
526488
assert_eq!(scan.table_schema().fields().len(), 3);
527489
assert_eq!(scan.schema().fields().len(), 2);
528490
assert_ne!(scan.schema().fields(), scan.table_schema().fields());
529491

530492
assert_eq!(scan.projection_indices(), Some(projection.as_slice()));
531-
let names = ["x".to_string(), "z".to_string()];
532-
assert_eq!(scan.projection(), Some(names.as_slice()));
533-
}
534-
535-
// Without a projection, indices/names are None and the full schema is kept.
536-
#[tokio::test]
537-
async fn no_projection_keeps_full_schema() {
538-
let scan = IcebergTableScan::new(test_table().await, None, arrow_schema(), None, &[], None);
539-
540-
assert_eq!(scan.projection_indices(), None);
541-
assert_eq!(scan.projection(), None);
542-
assert_eq!(scan.schema().fields(), scan.table_schema().fields());
543-
assert_eq!(scan.table_schema().fields(), arrow_schema().fields());
493+
let expected_projection = vec!["x".to_string(), "z".to_string()];
494+
assert_eq!(scan.projection(), Some(expected_projection.as_slice()));
495+
assert!(matches!(
496+
scan.properties().partitioning,
497+
Partitioning::UnknownPartitioning(2)
498+
));
544499
}
545500

546-
// A predicate passed to the new constructor round-trips unchanged.
547501
#[tokio::test]
548-
async fn predicate_round_trips() {
549-
let predicate = Reference::new("x").greater_than(Datum::long(5));
502+
async fn test_no_projection_keeps_full_schema() {
503+
let schema = create_test_arrow_schema();
550504
let scan = IcebergTableScan::new_with_tasks_from_predicate(
551-
test_table().await,
505+
get_test_table_from_metadata_file().await,
506+
None,
507+
schema.clone(),
552508
None,
553-
arrow_schema(),
554509
None,
555-
Some(predicate.clone()),
556510
None,
557511
vec![vec![]],
558512
Partitioning::UnknownPartitioning(1),
559513
);
560514

561-
assert_eq!(scan.predicates(), Some(&predicate));
515+
assert_eq!(scan.projection_indices(), None);
516+
assert_eq!(scan.projection(), None);
517+
assert_eq!(scan.predicates(), None);
518+
assert_eq!(scan.schema().fields(), scan.table_schema().fields());
519+
assert_eq!(scan.table_schema().fields(), schema.fields());
562520
}
563521
}

0 commit comments

Comments
 (0)