|
19 | 19 | //! create them and depend on them. Test executable semantics of logical plans. |
20 | 20 |
|
21 | 21 | use arrow::array::Int64Array; |
22 | | -use arrow::datatypes::{DataType, Field}; |
| 22 | +use arrow::datatypes::{DataType, Field, Schema}; |
| 23 | +use datafusion::datasource::{provider_as_source, ViewTable}; |
23 | 24 | use datafusion::execution::session_state::SessionStateBuilder; |
24 | | -use datafusion_common::{Column, DFSchema, Result, ScalarValue, Spans}; |
| 25 | +use datafusion_common::{Column, DFSchema, DFSchemaRef, Result, ScalarValue, Spans}; |
25 | 26 | use datafusion_execution::TaskContext; |
26 | 27 | use datafusion_expr::expr::{AggregateFunction, AggregateFunctionParams}; |
27 | 28 | use datafusion_expr::logical_plan::{LogicalPlan, Values}; |
28 | | -use datafusion_expr::{Aggregate, AggregateUDF, Expr}; |
| 29 | +use datafusion_expr::{ |
| 30 | + Aggregate, AggregateUDF, EmptyRelation, Expr, LogicalPlanBuilder, UNNAMED_TABLE, |
| 31 | +}; |
29 | 32 | use datafusion_functions_aggregate::count::Count; |
30 | 33 | use datafusion_physical_plan::collect; |
| 34 | +use insta::assert_snapshot; |
31 | 35 | use std::collections::HashMap; |
32 | 36 | use std::fmt::Debug; |
33 | 37 | use std::ops::Deref; |
@@ -96,3 +100,37 @@ where |
96 | 100 | }; |
97 | 101 | element |
98 | 102 | } |
| 103 | + |
| 104 | +#[test] |
| 105 | +fn inline_scan_projection_test() -> Result<()> { |
| 106 | + let name = UNNAMED_TABLE; |
| 107 | + let column = "a"; |
| 108 | + |
| 109 | + let schema = Schema::new(vec![ |
| 110 | + Field::new("a", DataType::Int32, false), |
| 111 | + Field::new("b", DataType::Int32, false), |
| 112 | + ]); |
| 113 | + let projection = vec![schema.index_of(column)?]; |
| 114 | + |
| 115 | + let provider = ViewTable::new( |
| 116 | + LogicalPlan::EmptyRelation(EmptyRelation { |
| 117 | + produce_one_row: false, |
| 118 | + schema: DFSchemaRef::new(DFSchema::try_from(schema)?), |
| 119 | + }), |
| 120 | + None, |
| 121 | + ); |
| 122 | + let source = provider_as_source(Arc::new(provider)); |
| 123 | + |
| 124 | + let plan = LogicalPlanBuilder::scan(name, source, Some(projection))?.build()?; |
| 125 | + |
| 126 | + assert_snapshot!( |
| 127 | + format!("{plan}"), |
| 128 | + @r" |
| 129 | + SubqueryAlias: ?table? |
| 130 | + Projection: a |
| 131 | + EmptyRelation |
| 132 | + " |
| 133 | + ); |
| 134 | + |
| 135 | + Ok(()) |
| 136 | +} |
0 commit comments