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

Function test_transform_non_consecutive_unnests

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

Source from the content-addressed store, hash-verified

937 // Unnest -> field access -> unnest
938 #[test]
939 fn test_transform_non_consecutive_unnests() -> Result<()> {
940 // List of struct
941 // [struct{'subfield1':list(i64), 'subfield2':list(utf8)}]
942 let schema = Schema::new(vec![
943 Field::new(
944 "struct_list",
945 ArrowDataType::List(Arc::new(Field::new(
946 "element",
947 ArrowDataType::Struct(Fields::from(vec![
948 Field::new(
949 // list of i64
950 "subfield1",
951 ArrowDataType::List(Arc::new(Field::new(
952 "i64_element",
953 ArrowDataType::Int64,
954 true,
955 ))),
956 true,
957 ),
958 Field::new(
959 // list of utf8
960 "subfield2",
961 ArrowDataType::List(Arc::new(Field::new(
962 "utf8_element",
963 ArrowDataType::Utf8,
964 true,
965 ))),
966 true,
967 ),
968 ])),
969 true,
970 ))),
971 true,
972 ),
973 Field::new("int_col", ArrowDataType::Int32, false),
974 ]);
975
976 let dfschema = DFSchema::try_from(schema)?;
977
978 let input = LogicalPlan::EmptyRelation(EmptyRelation {
979 produce_one_row: false,
980 schema: Arc::new(dfschema),
981 });
982
983 let mut unnest_placeholder_columns = IndexMap::new();
984 let mut inner_projection_exprs = vec![];
985
986 // An expr with multiple unnest
987 let select_expr1 = unnest(unnest(col("struct_list")).field("subfield1"));
988 let transformed_exprs = rewrite_recursive_unnest_bottom_up(
989 &input,
990 &mut unnest_placeholder_columns,
991 &mut inner_projection_exprs,
992 &select_expr1,
993 )?;
994 // Only the inner most/ bottom most unnest is transformed
995 assert_eq!(
996 transformed_exprs,

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
EmptyRelationClass · 0.85
column_unnests_eqFunction · 0.85
unnestFunction · 0.50
colFunction · 0.50
fieldMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…