Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions datafusion/proto/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,6 @@ impl AsLogicalPlan for LogicalPlanNode {
LogicalPlanType::ListingScan(scan) => {
let schema: Schema = convert_required!(scan.schema)?;

let mut projection = None;
if let Some(columns) = &scan.projection {
let column_indices = columns
.columns
.iter()
.map(|name| schema.index_of(name))
.collect::<Result<Vec<usize>, _>>()?;
projection = Some(column_indices);
}

let filters =
from_proto::parse_exprs(&scan.filters, ctx, extension_codec)?;

Expand Down Expand Up @@ -492,6 +482,16 @@ impl AsLogicalPlan for LogicalPlanNode {
let table_name =
from_table_reference(scan.table_name.as_ref(), "ListingTableScan")?;

let mut projection = None;
if let Some(columns) = &scan.projection {
let column_indices = columns
.columns
.iter()
.map(|name| provider.schema().index_of(name))
.collect::<Result<Vec<usize>, _>>()?;
projection = Some(column_indices);
}

LogicalPlanBuilder::scan_with_filters(
table_name,
provider_as_source(Arc::new(provider)),
Expand Down
27 changes: 18 additions & 9 deletions datafusion/proto/tests/cases/roundtrip_logical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use datafusion::datasource::file_format::arrow::ArrowFormatFactory;
use datafusion::datasource::file_format::csv::CsvFormatFactory;
use datafusion::datasource::file_format::parquet::ParquetFormatFactory;
use datafusion::datasource::file_format::{format_as_file_type, DefaultFileType};
use datafusion::datasource::DefaultTableSource;
use datafusion::execution::session_state::SessionStateBuilder;
use datafusion::execution::FunctionRegistry;
use datafusion::functions_aggregate::count::count_udaf;
Expand Down Expand Up @@ -75,9 +76,9 @@ use datafusion_expr::expr::{
use datafusion_expr::logical_plan::{Extension, UserDefinedLogicalNodeCore};
use datafusion_expr::{
Accumulator, AggregateUDF, ColumnarValue, ExprFunctionExt, ExprSchemable, Literal,
LogicalPlan, Operator, PartitionEvaluator, ScalarUDF, Signature, TryCast, Volatility,
WindowFrame, WindowFrameBound, WindowFrameUnits, WindowFunctionDefinition, WindowUDF,
WindowUDFImpl,
LogicalPlan, LogicalPlanBuilder, Operator, PartitionEvaluator, ScalarUDF, Signature,
TryCast, Volatility, WindowFrame, WindowFrameBound, WindowFrameUnits,
WindowFunctionDefinition, WindowUDF, WindowUDFImpl,
};
use datafusion_functions_aggregate::average::avg_udaf;
use datafusion_functions_aggregate::expr_fn::{
Expand Down Expand Up @@ -2643,16 +2644,24 @@ async fn roundtrip_custom_listing_tables_schema() -> Result<()> {
.infer_schema(&ctx.state())
.await?;

ctx.register_table("hive_style", Arc::new(ListingTable::try_new(config)?))?;
let listing_table: Arc<dyn TableProvider> = Arc::new(ListingTable::try_new(config)?);

let plan = ctx
.sql("SELECT part, value FROM hive_style LIMIT 1")
.await?
.logical_plan()
.clone();
let projection = ["part", "value"]
.iter()
.map(|field_name| listing_table.schema().index_of(field_name))
.collect::<Result<Vec<_>, _>>()?;

let plan = LogicalPlanBuilder::scan(
"hive_style",
Arc::new(DefaultTableSource::new(listing_table)),
Some(projection),
)?
.limit(0, Some(1))?
.build()?;

let bytes = logical_plan_to_bytes(&plan)?;
let new_plan = logical_plan_from_bytes(&bytes, &ctx)?;

assert_eq!(plan, new_plan);
Ok(())
}