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

Function test_transform_bottom_unnest

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

Source from the content-addressed store, hash-verified

839
840 #[test]
841 fn test_transform_bottom_unnest() -> Result<()> {
842 let schema = Schema::new(vec![
843 Field::new(
844 "struct_col",
845 ArrowDataType::Struct(Fields::from(vec![
846 Field::new("field1", ArrowDataType::Int32, false),
847 Field::new("field2", ArrowDataType::Int32, false),
848 ])),
849 false,
850 ),
851 Field::new(
852 "array_col",
853 ArrowDataType::List(Arc::new(Field::new_list_field(
854 ArrowDataType::Int64,
855 true,
856 ))),
857 true,
858 ),
859 Field::new("int_col", ArrowDataType::Int32, false),
860 ]);
861
862 let dfschema = DFSchema::try_from(schema)?;
863
864 let input = LogicalPlan::EmptyRelation(EmptyRelation {
865 produce_one_row: false,
866 schema: Arc::new(dfschema),
867 });
868
869 let mut unnest_placeholder_columns = IndexMap::new();
870 let mut inner_projection_exprs = vec![];
871
872 // unnest(struct_col)
873 let original_expr = unnest(col("struct_col"));
874 let transformed_exprs = rewrite_recursive_unnest_bottom_up(
875 &input,
876 &mut unnest_placeholder_columns,
877 &mut inner_projection_exprs,
878 &original_expr,
879 )?;
880 assert_eq!(
881 transformed_exprs,
882 vec![
883 col("__unnest_placeholder(struct_col).field1"),
884 col("__unnest_placeholder(struct_col).field2"),
885 ]
886 );
887 column_unnests_eq(
888 vec!["__unnest_placeholder(struct_col)"],
889 &unnest_placeholder_columns,
890 );
891 // Still reference struct_col in original schema but with alias,
892 // to avoid colliding with the projection on the column itself if any
893 assert_eq!(
894 inner_projection_exprs,
895 vec![col("struct_col").alias("__unnest_placeholder(struct_col)"),]
896 );
897
898 // unnest(array_col) + 1

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…