@@ -32,7 +32,7 @@ use datafusion_common::alias::AliasGenerator;
3232use datafusion_execution:: registry:: SerializerRegistry ;
3333use datafusion_expr:: {
3434 logical_plan:: { DdlStatement , Statement } ,
35- DescribeTable , StringifiedPlan , UserDefinedLogicalNode , WindowUDF ,
35+ DescribeTable , Partitioning , StringifiedPlan , UserDefinedLogicalNode , WindowUDF ,
3636} ;
3737pub use datafusion_physical_expr:: execution_props:: ExecutionProps ;
3838use datafusion_physical_expr:: var_provider:: is_system_variables;
@@ -917,11 +917,16 @@ impl SessionContext {
917917 /// Creates a [`DataFrame`] for a [`TableProvider`] such as a
918918 /// [`ListingTable`] or a custom user defined provider.
919919 pub fn read_table ( & self , provider : Arc < dyn TableProvider > ) -> Result < DataFrame > {
920- Ok ( DataFrame :: new (
921- self . state ( ) ,
922- LogicalPlanBuilder :: scan ( UNNAMED_TABLE , provider_as_source ( provider) , None ) ?
923- . build ( ) ?,
924- ) )
920+ let state = self . state ( ) ;
921+ let mut builder =
922+ LogicalPlanBuilder :: scan ( UNNAMED_TABLE , provider_as_source ( provider) , None ) ?;
923+ let target_partitions = state. config . target_partitions ( ) ;
924+ if target_partitions > 1 {
925+ // Keep the data in the target number of partitions
926+ builder =
927+ builder. repartition ( Partitioning :: RoundRobinBatch ( target_partitions) ) ?;
928+ }
929+ Ok ( DataFrame :: new ( state, builder. build ( ) ?) )
925930 }
926931
927932 /// Creates a [`DataFrame`] for reading a [`RecordBatch`]
0 commit comments