Skip to content

Commit 69ba82f

Browse files
smallzhongfengzhongjingxiong
andauthored
Fix: dataframe_subquery example Optimizer rule common_sub_expression_eliminate failed (#8016)
* Fix: Optimizer rule 'common_sub_expression_eliminate' failed * nit * nit * nit --------- Co-authored-by: zhongjingxiong <zhongjingxiong@bytedance.com>
1 parent aef95ed commit 69ba82f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

datafusion-examples/examples/dataframe_subquery.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use arrow_schema::DataType;
1819
use std::sync::Arc;
1920

2021
use datafusion::error::Result;
@@ -38,15 +39,15 @@ async fn main() -> Result<()> {
3839
Ok(())
3940
}
4041

41-
//select c1,c2 from t1 where (select avg(t2.c2) from t2 where t1.c1 = t2.c1)>0 limit 10;
42+
//select c1,c2 from t1 where (select avg(t2.c2) from t2 where t1.c1 = t2.c1)>0 limit 3;
4243
async fn where_scalar_subquery(ctx: &SessionContext) -> Result<()> {
4344
ctx.table("t1")
4445
.await?
4546
.filter(
4647
scalar_subquery(Arc::new(
4748
ctx.table("t2")
4849
.await?
49-
.filter(col("t1.c1").eq(col("t2.c1")))?
50+
.filter(out_ref_col(DataType::Utf8, "t1.c1").eq(col("t2.c1")))?
5051
.aggregate(vec![], vec![avg(col("t2.c2"))])?
5152
.select(vec![avg(col("t2.c2"))])?
5253
.into_unoptimized_plan(),
@@ -60,7 +61,7 @@ async fn where_scalar_subquery(ctx: &SessionContext) -> Result<()> {
6061
Ok(())
6162
}
6263

63-
//SELECT t1.c1, t1.c2 FROM t1 WHERE t1.c2 in (select max(t2.c2) from t2 where t2.c1 > 0 ) limit 10
64+
//SELECT t1.c1, t1.c2 FROM t1 WHERE t1.c2 in (select max(t2.c2) from t2 where t2.c1 > 0 ) limit 3;
6465
async fn where_in_subquery(ctx: &SessionContext) -> Result<()> {
6566
ctx.table("t1")
6667
.await?
@@ -82,14 +83,14 @@ async fn where_in_subquery(ctx: &SessionContext) -> Result<()> {
8283
Ok(())
8384
}
8485

85-
//SELECT t1.c1, t1.c2 FROM t1 WHERE EXISTS (select t2.c2 from t2 where t1.c1 = t2.c1) limit 10
86+
//SELECT t1.c1, t1.c2 FROM t1 WHERE EXISTS (select t2.c2 from t2 where t1.c1 = t2.c1) limit 3;
8687
async fn where_exist_subquery(ctx: &SessionContext) -> Result<()> {
8788
ctx.table("t1")
8889
.await?
8990
.filter(exists(Arc::new(
9091
ctx.table("t2")
9192
.await?
92-
.filter(col("t1.c1").eq(col("t2.c1")))?
93+
.filter(out_ref_col(DataType::Utf8, "t1.c1").eq(col("t2.c1")))?
9394
.select(vec![col("t2.c2")])?
9495
.into_unoptimized_plan(),
9596
)))?

0 commit comments

Comments
 (0)