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

Function test_alias

datafusion/core/tests/dataframe/mod.rs:6154–6194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6152
6153#[tokio::test]
6154async fn test_alias() -> Result<()> {
6155 let df = create_test_table("test")
6156 .await?
6157 .select(vec![col("a"), col("test.b"), lit(1).alias("one")])?
6158 .alias("table_alias")?;
6159 // All output column qualifiers are changed to "table_alias"
6160 df.schema().columns().iter().for_each(|c| {
6161 assert_eq!(c.relation, Some("table_alias".into()));
6162 });
6163
6164 let plan = df
6165 .clone()
6166 .into_unoptimized_plan()
6167 .display_indent_schema()
6168 .to_string();
6169 assert_snapshot!(plan, @r"
6170 SubqueryAlias: table_alias [a:Utf8, b:Int32, one:Int32]
6171 Projection: test.a, test.b, Int32(1) AS one [a:Utf8, b:Int32, one:Int32]
6172 TableScan: test [a:Utf8, b:Int32]
6173 ");
6174
6175 // Select over the aliased DataFrame
6176 let df = df.select(vec![
6177 col("table_alias.a"),
6178 col("b") + col("table_alias.one"),
6179 ])?;
6180 assert_snapshot!(
6181 batches_to_sort_string(&df.collect().await.unwrap()),
6182 @r"
6183 +-----------+---------------------------------+
6184 | a | table_alias.b + table_alias.one |
6185 +-----------+---------------------------------+
6186 | 123AbcDef | 101 |
6187 | CBAdef | 11 |
6188 | abc123 | 11 |
6189 | abcDEF | 2 |
6190 +-----------+---------------------------------+
6191 "
6192 );
6193 Ok(())
6194}
6195
6196#[tokio::test]
6197async fn test_alias_with_metadata() -> Result<()> {

Callers

nothing calls this directly

Calls 10

columnsMethod · 0.80
display_indent_schemaMethod · 0.80
into_unoptimized_planMethod · 0.80
create_test_tableFunction · 0.70
aliasMethod · 0.45
selectMethod · 0.45
iterMethod · 0.45
schemaMethod · 0.45
to_stringMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…