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

Function test_expr_metadata

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

Source from the content-addressed store, hash-verified

1035
1036 #[test]
1037 fn test_expr_metadata() {
1038 let mut meta = HashMap::new();
1039 meta.insert("bar".to_string(), "buzz".to_string());
1040 let meta = FieldMetadata::from(meta);
1041 let expr = col("foo");
1042 let schema = MockExprSchema::new()
1043 .with_data_type(DataType::Int32)
1044 .with_metadata(meta.clone());
1045
1046 // col, alias, and cast should be metadata-preserving
1047 assert_eq!(meta, expr.metadata(&schema).unwrap());
1048 assert_eq!(meta, expr.clone().alias("bar").metadata(&schema).unwrap());
1049 assert_eq!(
1050 meta,
1051 expr.clone()
1052 .cast_to(&DataType::Int64, &schema)
1053 .unwrap()
1054 .metadata(&schema)
1055 .unwrap()
1056 );
1057
1058 let schema = DFSchema::from_unqualified_fields(
1059 vec![meta.add_to_field(Field::new("foo", DataType::Int32, true))].into(),
1060 HashMap::new(),
1061 )
1062 .unwrap();
1063
1064 // verify to_field method populates metadata
1065 assert_eq!(meta, expr.metadata(&schema).unwrap());
1066
1067 // outer ref constructed by `out_ref_col_with_metadata` should be metadata-preserving
1068 let outer_ref = out_ref_col_with_metadata(
1069 DataType::Int32,
1070 meta.to_hashmap(),
1071 Column::from_name("foo"),
1072 );
1073 assert_eq!(meta, outer_ref.metadata(&schema).unwrap());
1074 }
1075
1076 #[test]
1077 fn test_alias_metadata_is_preserved_in_field_metadata() {

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
with_data_typeMethod · 0.80
to_hashmapMethod · 0.80
colFunction · 0.70
insertMethod · 0.45
to_stringMethod · 0.45
with_metadataMethod · 0.45
cloneMethod · 0.45
intoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…