Skip to content

Commit ff92d0c

Browse files
committed
Add ability to set statistics in the SQLExecutor
1 parent e0496b3 commit ff92d0c

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

datafusion-federation/src/schema_cast/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use async_stream::stream;
22
use datafusion::arrow::datatypes::SchemaRef;
3+
use datafusion::common::Statistics;
34
use datafusion::error::{DataFusionError, Result};
45
use datafusion::execution::{SendableRecordBatchStream, TaskContext};
56
use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
@@ -113,4 +114,8 @@ impl ExecutionPlan for SchemaCastScanExec {
113114
},
114115
)))
115116
}
117+
118+
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
119+
self.input.partition_statistics(partition)
120+
}
116121
}

datafusion-federation/src/sql/executor.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use async_trait::async_trait;
22
use core::fmt;
33
use datafusion::{
44
arrow::datatypes::SchemaRef,
5+
common::Statistics,
56
error::Result,
67
logical_expr::LogicalPlan,
78
physical_plan::SendableRecordBatchStream,
@@ -43,6 +44,18 @@ pub trait SQLExecutor: Sync + Send {
4344
/// Execute a SQL query
4445
fn execute(&self, query: &str, schema: SchemaRef) -> Result<SendableRecordBatchStream>;
4546

47+
/// Returns statistics for this `SQLExecutor` node. If statistics are not available, it should
48+
/// return [`Statistics::new_unknown`] (the default), not an error. See the `ExecutionPlan`
49+
/// trait.
50+
fn partition_statistics(
51+
&self,
52+
_partition: Option<usize>,
53+
_query: &str,
54+
schema: SchemaRef,
55+
) -> Result<Statistics> {
56+
Ok(Statistics::new_unknown(&schema))
57+
}
58+
4659
/// Returns the tables provided by the remote
4760
async fn table_names(&self) -> Result<Vec<String>>;
4861

datafusion-federation/src/sql/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use async_trait::async_trait;
1212
use datafusion::{
1313
arrow::datatypes::{Schema, SchemaRef},
1414
common::tree_node::{Transformed, TreeNode},
15+
common::Statistics,
1516
error::{DataFusionError, Result},
1617
execution::{context::SessionState, TaskContext},
1718
logical_expr::{Extension, LogicalPlan},
@@ -343,6 +344,11 @@ impl ExecutionPlan for VirtualExecutionPlan {
343344
fn properties(&self) -> &PlanProperties {
344345
&self.props
345346
}
347+
348+
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
349+
self.executor
350+
.partition_statistics(partition, &self.final_sql()?, self.schema())
351+
}
346352
}
347353

348354
#[cfg(test)]

0 commit comments

Comments
 (0)