You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "osipovartem (via GitHub)" <gi...@apache.org> on 2025/05/09 08:04:27 UTC

[I] Select with order by from empty table triggers SanityCheckPlan error [datafusion]

osipovartem opened a new issue, #16001:
URL: https://github.com/apache/datafusion/issues/16001

   ### Describe the bug
   
   ```sql
   CREATE TABLE test (vendor_id INT)
   SELECT * FROM test ORDER BY by app_id
   ```
   ```rust
   Fails with DataFusion error: SanityCheckPlan caused by Error during planning: Plan: [\"SortExec: expr=[vendor_id@0 ASC NULLS LAST], preserve_partitioning=[false]\", \"  DataSourceExec: file_groups={0 groups: []}, projection=[vendor_id], file_type=parquet\"] does not satisfy distribution requirements: SinglePartition. Child-0 output partitioning: UnknownPartitioning(0)
   ```
   
   ### To Reproduce
   
   ```sql
   CREATE TABLE test (vendor_id INT)
   SELECT * FROM test ORDER BY by app_id
   ```
   
   ### Expected behavior
   
   Return empty records batch
   
   ### Additional context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Select with order by from empty table triggers SanityCheckPlan error [datafusion]

Posted by "berkaysynnada (via GitHub)" <gi...@apache.org>.
berkaysynnada commented on issue #16001:
URL: https://github.com/apache/datafusion/issues/16001#issuecomment-2869898307

   I think there shouldn't be a SortExec there at all


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Select with order by from empty table triggers SanityCheckPlan error [datafusion]

Posted by "VaibhaveS (via GitHub)" <gi...@apache.org>.
VaibhaveS commented on issue #16001:
URL: https://github.com/apache/datafusion/issues/16001#issuecomment-5230907911

   take


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Select with order by from empty table triggers SanityCheckPlan error [datafusion]

Posted by "osipovartem (via GitHub)" <gi...@apache.org>.
osipovartem commented on issue #16001:
URL: https://github.com/apache/datafusion/issues/16001#issuecomment-2866169342

   We cannot pass DF SanityCheck since FileScanConfig implements DataSource trait with
   ```rust
   impl DataSource for FileScanConfig {
      .....
      fn output_partitioning(&self) -> Partitioning {
           Partitioning::UnknownPartitioning(self.file_groups.len())
       }
   ```
   Because of that we have UnknownPartitioning(0) (as we don't have any files, just empty table) 
   But SortExec creates by default UnknownPartitioning(1)
   Here is the full execution plan for the select query above
   ```
   SortExec {
       input: DataSourceExec {
           data_source: FileScanConfig {object_store_url=ObjectStoreUrl { url: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/", query: None, fragment: None } }, statistics=Statistics { num_rows: Exact(0), total_byte_size: Exact(0), column_statistics: [ColumnStatistics { null_count: Absent, max_value: Absent, min_value: Absent, sum_value: Absent, distinct_count: Absent }] }, file_groups={0 groups: []}, projection=[app_id]},
           cache: PlanProperties {
               eq_properties: EquivalenceProperties {
                   eq_group: EquivalenceGroup {
                       classes: [],
                   },
                   oeq_class: OrderingEquivalenceClass {
                       orderings: [],
                   },
                   constants: [],
                   constraints: Constraints {
                       inner: [],
                   },
                   schema: Schema {
                       fields: [
                           Field {
                               name: "app_id",
                               data_type: Int32,
                               nullable: true,
                               dict_id: 0,
                               dict_is_ordered: false,
                               metadata: {
                                   "PARQUET:field_id": "1",
                               },
                           },
                       ],
                       metadata: {},
                   },
               },
               partitioning: UnknownPartitioning(
                   0,
               ),
               emission_type: Incremental,
               boundedness: Bounded,
               output_ordering: None,
           },
       },
       expr: LexOrdering {
           inner: [
               PhysicalSortExpr {
                   expr: Column {
                       name: "app_id",
                       index: 0,
                   },
                   options: SortOptions {
                       descending: false,
                       nulls_first: false,
                   },
               },
           ],
       },
       metrics_set: ExecutionPlanMetricsSet {
           inner: Mutex {
               data: MetricsSet {
                   metrics: [],
               },
           },
       },
       preserve_partitioning: false,
       fetch: None,
       common_sort_prefix: LexOrdering {
           inner: [],
       },
       cache: PlanProperties {
           eq_properties: EquivalenceProperties {
               eq_group: EquivalenceGroup {
                   classes: [],
               },
               oeq_class: OrderingEquivalenceClass {
                   orderings: [
                       LexOrdering {
                           inner: [
                               PhysicalSortExpr {
                                   expr: Column {
                                       name: "app_id",
                                       index: 0,
                                   },
                                   options: SortOptions {
                                       descending: false,
                                       nulls_first: false,
                                   },
                               },
                           ],
                       },
                   ],
               },
               constants: [],
               constraints: Constraints {
                   inner: [],
               },
               schema: Schema {
                   fields: [
                       Field {
                           name: "app_id",
                           data_type: Int32,
                           nullable: true,
                           dict_id: 0,
                           dict_is_ordered: false,
                           metadata: {
                               "PARQUET:field_id": "1",
                           },
                       },
                   ],
                   metadata: {},
               },
           },
           partitioning: **UnknownPartitioning(
               1,
           )**,
           emission_type: Final,
           boundedness: Bounded,
           output_ordering: Some(
               LexOrdering {
                   inner: [
                       PhysicalSortExpr {
                           expr: Column {
                               name: "app_id",
                               index: 0,
                           },
                           options: SortOptions {
                               descending: false,
                               nulls_first: false,
                           },
                       },
                   ],
               },
           ),
       },
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org