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

Function test_expr_placeholder

datafusion/expr/src/expr_schema.rs:1098–1146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1096
1097 #[test]
1098 fn test_expr_placeholder() {
1099 let schema = MockExprSchema::new();
1100
1101 let mut placeholder_meta = HashMap::new();
1102 placeholder_meta.insert("bar".to_string(), "buzz".to_string());
1103 let placeholder_meta = FieldMetadata::from(placeholder_meta);
1104
1105 let expr = Expr::Placeholder(Placeholder::new_with_field(
1106 "".to_string(),
1107 Some(
1108 Field::new("", DataType::Utf8, true)
1109 .with_metadata(placeholder_meta.to_hashmap())
1110 .into(),
1111 ),
1112 ));
1113
1114 let field = expr.to_field(&schema).unwrap().1;
1115 assert_eq!(
1116 (field.data_type(), field.is_nullable()),
1117 (&DataType::Utf8, true)
1118 );
1119 assert_eq!(placeholder_meta, expr.metadata(&schema).unwrap());
1120
1121 let expr_alias = expr.alias("a placeholder by any other name");
1122 let expr_alias_field = expr_alias.to_field(&schema).unwrap().1;
1123 assert_eq!(
1124 (expr_alias_field.data_type(), expr_alias_field.is_nullable()),
1125 (&DataType::Utf8, true)
1126 );
1127 assert_eq!(placeholder_meta, expr_alias.metadata(&schema).unwrap());
1128
1129 // Non-nullable placeholder field should remain non-nullable
1130 let expr = Expr::Placeholder(Placeholder::new_with_field(
1131 "".to_string(),
1132 Some(Field::new("", DataType::Utf8, false).into()),
1133 ));
1134 let expr_field = expr.to_field(&schema).unwrap().1;
1135 assert_eq!(
1136 (expr_field.data_type(), expr_field.is_nullable()),
1137 (&DataType::Utf8, false)
1138 );
1139
1140 let expr_alias = expr.alias("a placeholder by any other name");
1141 let expr_alias_field = expr_alias.to_field(&schema).unwrap().1;
1142 assert_eq!(
1143 (expr_alias_field.data_type(), expr_alias_field.is_nullable()),
1144 (&DataType::Utf8, false)
1145 );
1146 }
1147
1148 #[derive(Debug)]
1149 struct MockExprSchema {

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
PlaceholderClass · 0.85
to_hashmapMethod · 0.80
to_fieldMethod · 0.80
insertMethod · 0.45
to_stringMethod · 0.45
intoMethod · 0.45
with_metadataMethod · 0.45
aliasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…