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

Function with_column_join_same_columns

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

Source from the content-addressed store, hash-verified

1948// The join operation outputs two identical column names, but they belong to different relations.
1949#[tokio::test]
1950async fn with_column_join_same_columns() -> Result<()> {
1951 let df = test_table().await?.select_columns(&["c1"])?;
1952 let ctx = SessionContext::new();
1953
1954 let table = df.into_view();
1955 ctx.register_table("t1", table.clone())?;
1956 ctx.register_table("t2", table)?;
1957 let df = ctx
1958 .table("t1")
1959 .await?
1960 .join(
1961 ctx.table("t2").await?,
1962 JoinType::Inner,
1963 &["c1"],
1964 &["c1"],
1965 None,
1966 )?
1967 .sort(vec![
1968 // make the test deterministic
1969 col("t1.c1").sort(true, true),
1970 ])?
1971 .limit(0, Some(1))?;
1972
1973 let df_results = df.clone().collect().await?;
1974 assert_snapshot!(
1975 batches_to_sort_string(&df_results),
1976 @r"
1977 +----+----+
1978 | c1 | c1 |
1979 +----+----+
1980 | a | a |
1981 +----+----+
1982 "
1983 );
1984
1985 let df_with_column = df.clone().with_column("new_column", lit(true))?;
1986
1987 assert_snapshot!(
1988 df_with_column.logical_plan(),
1989 @r"
1990 Projection: t1.c1, t2.c1, Boolean(true) AS new_column
1991 Limit: skip=0, fetch=1
1992 Sort: t1.c1 ASC NULLS FIRST
1993 Inner Join: t1.c1 = t2.c1
1994 SubqueryAlias: t1
1995 Projection: aggregate_test_100.c1
1996 TableScan: aggregate_test_100
1997 SubqueryAlias: t2
1998 Projection: aggregate_test_100.c1
1999 TableScan: aggregate_test_100
2000 "
2001 );
2002
2003 assert_snapshot!(
2004 df_with_column.clone().into_optimized_plan().unwrap(),
2005 @r"
2006 Projection: t1.c1, t2.c1, Boolean(true) AS new_column
2007 Sort: t1.c1 ASC NULLS FIRST, fetch=1

Callers

nothing calls this directly

Calls 13

test_tableFunction · 0.85
newFunction · 0.85
select_columnsMethod · 0.80
into_viewMethod · 0.80
collectMethod · 0.80
with_columnMethod · 0.80
litFunction · 0.50
register_tableMethod · 0.45
cloneMethod · 0.45
limitMethod · 0.45
sortMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…