MCPcopy Create free account
hub / github.com/apache/datafusion / test_transform_bottom_unnest_recursive

Function test_transform_bottom_unnest_recursive

datafusion/sql/src/utils.rs:737–838  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

735
736 #[test]
737 fn test_transform_bottom_unnest_recursive() -> Result<()> {
738 let schema = Schema::new(vec![
739 Field::new(
740 "3d_col",
741 ArrowDataType::List(Arc::new(Field::new(
742 "2d_col",
743 ArrowDataType::List(Arc::new(Field::new(
744 "elements",
745 ArrowDataType::Int64,
746 true,
747 ))),
748 true,
749 ))),
750 true,
751 ),
752 Field::new("i64_col", ArrowDataType::Int64, true),
753 ]);
754
755 let dfschema = DFSchema::try_from(schema)?;
756
757 let input = LogicalPlan::EmptyRelation(EmptyRelation {
758 produce_one_row: false,
759 schema: Arc::new(dfschema),
760 });
761
762 let mut unnest_placeholder_columns = IndexMap::new();
763 let mut inner_projection_exprs = vec![];
764
765 // unnest(unnest(3d_col)) + unnest(unnest(3d_col))
766 let original_expr = unnest(unnest(col("3d_col")))
767 .add(unnest(unnest(col("3d_col"))))
768 .add(col("i64_col"));
769 let transformed_exprs = rewrite_recursive_unnest_bottom_up(
770 &input,
771 &mut unnest_placeholder_columns,
772 &mut inner_projection_exprs,
773 &original_expr,
774 )?;
775 // Only the bottom most unnest exprs are transformed
776 assert_eq!(
777 transformed_exprs,
778 vec![
779 col("__unnest_placeholder(3d_col,depth=2)")
780 .alias("UNNEST(UNNEST(3d_col))")
781 .add(
782 col("__unnest_placeholder(3d_col,depth=2)")
783 .alias("UNNEST(UNNEST(3d_col))")
784 )
785 .add(col("i64_col"))
786 ]
787 );
788 column_unnests_eq(
789 vec![
790 "__unnest_placeholder(3d_col)=>[__unnest_placeholder(3d_col,depth=2)|depth=2]",
791 ],
792 &unnest_placeholder_columns,
793 );
794

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
EmptyRelationClass · 0.85
column_unnests_eqFunction · 0.85
unnestFunction · 0.50
colFunction · 0.50
addMethod · 0.45
aliasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…