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

Function test_alias_nested

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

Source from the content-addressed store, hash-verified

6264
6265#[tokio::test]
6266async fn test_alias_nested() -> Result<()> {
6267 let df = create_test_table("test")
6268 .await?
6269 .select(vec![col("a"), col("test.b"), lit(1).alias("one")])?
6270 .alias("alias1")?
6271 .alias("alias2")?;
6272
6273 let plan = df
6274 .clone()
6275 .into_optimized_plan()?
6276 .display_indent_schema()
6277 .to_string();
6278 assert_snapshot!(plan, @r"
6279 SubqueryAlias: alias2 [a:Utf8, b:Int32, one:Int32]
6280 SubqueryAlias: alias1 [a:Utf8, b:Int32, one:Int32]
6281 Projection: test.a, test.b, Int32(1) AS one [a:Utf8, b:Int32, one:Int32]
6282 TableScan: test projection=[a, b] [a:Utf8, b:Int32]
6283 ");
6284
6285 // Select over the aliased DataFrame
6286 let select1 = df
6287 .clone()
6288 .select(vec![col("alias2.a"), col("b") + col("alias2.one")])?;
6289
6290 assert_snapshot!(
6291 batches_to_sort_string(&select1.collect().await.unwrap()),
6292 @r"
6293 +-----------+-----------------------+
6294 | a | alias2.b + alias2.one |
6295 +-----------+-----------------------+
6296 | 123AbcDef | 101 |
6297 | CBAdef | 11 |
6298 | abc123 | 11 |
6299 | abcDEF | 2 |
6300 +-----------+-----------------------+
6301 "
6302 );
6303
6304 // Only the outermost alias is visible
6305 let select2 = df.select(vec![col("alias1.a")]);
6306 assert_snapshot!(
6307 select2.unwrap_err().strip_backtrace(),
6308 @"Schema error: No field named alias1.a. Valid fields are alias2.a, alias2.b, alias2.one."
6309 );
6310 Ok(())
6311}
6312
6313#[tokio::test]
6314async fn register_non_json_file() {

Callers

nothing calls this directly

Calls 7

display_indent_schemaMethod · 0.80
into_optimized_planMethod · 0.80
create_test_tableFunction · 0.70
aliasMethod · 0.45
selectMethod · 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…