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

[PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

xudong963 opened a new pull request, #15416:
URL: https://github.com/apache/datafusion/pull/15416

   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   When I upgraded the df46, It was annoying for me to do the following thing(a series of `downcast_ref`) and it's also easy to call the wrong method, such as mixing `file_source()` and `data_source()`:
   
   ```rust
   if let Some(scan_config) = self.data_source().as_any().downcast_ref::<FileScanConfig>() {
         if let Some(parquet_source) = scan_config
             .file_source()
             .as_any()
             .downcast_ref::<ParquetSource>(){...}
   ```
   
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Add the `downcast_to_source` method for `DataSourceExec` to make life easy
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   Yes, I replace the existing code with the new method.
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#discussion_r2015023075


##########
docs/source/library-user-guide/upgrading.md:
##########
@@ -129,6 +129,20 @@ if let Some(datasource_exec) = plan.as_any().downcast_ref::<DataSourceExec>() {
 # */
 ```
 
+There's also a more convenient helper method `downcast_to_file_source` on `DataSourceExec`

Review Comment:
   Yes, i totally forgot that 🤦‍♂️



-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "mertak-synnada (via GitHub)" <gi...@apache.org>.
mertak-synnada commented on code in PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#discussion_r2011761950


##########
datafusion/datasource/src/source.rs:
##########
@@ -230,4 +231,17 @@ impl DataSourceExec {
             Boundedness::Bounded,
         )
     }
+
+    /// Downcast the `DataSourceExec` to a specific file source
+    pub fn downcast_to_source<T: 'static>(&self) -> Option<(&FileScanConfig, &T)> {

Review Comment:
   Looks like a great simplification I think, thanks!
   
   But since `data_source` can be both `FileScanConfig` or `MemorySourceConfig` maybe renaming this function as `downcast_to_file_source` would be better. Or we can dynamically check the `T` and downcast properly I think.
   
   Also is there any need for '`static` ?



-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#discussion_r2011719252


##########
datafusion/datasource/src/source.rs:
##########
@@ -230,4 +231,17 @@ impl DataSourceExec {
             Boundedness::Bounded,
         )
     }
+
+    /// Downcast the `DataSourceExec` to a specific file source
+    pub fn downcast_to_source<T: 'static>(&self) -> Option<(&FileScanConfig, &T)> {

Review Comment:
   The main change.
   
   The changed code of other files is replaced with the method.



-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#issuecomment-2756308249

   @alamb Thanks for your review!


-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#discussion_r2014969803


##########
docs/source/library-user-guide/upgrading.md:
##########
@@ -129,6 +129,20 @@ if let Some(datasource_exec) = plan.as_any().downcast_ref::<DataSourceExec>() {
 # */
 ```
 
+There's also a more convenient helper method `downcast_to_file_source` on `DataSourceExec`

Review Comment:
   This code will not be available until DataFusion 47, so we probably need to put this into a new heading for 47 upgrade guide



##########
datafusion/datasource/src/source.rs:
##########
@@ -230,4 +231,18 @@ impl DataSourceExec {
             Boundedness::Bounded,
         )
     }
+
+    /// Downcast the `DataSourceExec` to a specific file source

Review Comment:
   ```suggestion
       /// Downcast the `DataSourceExec`'s `data_source` to a specific file source
       ///
       /// Returns `None` if 
       /// 1. the datasource is not scanning files (`FileScanConfig`)
       /// 2. The [`FileScanConfig::file_source`] is not of type <T>
   ```



-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#discussion_r2011873162


##########
datafusion/datasource/src/source.rs:
##########
@@ -230,4 +231,17 @@ impl DataSourceExec {
             Boundedness::Bounded,
         )
     }
+
+    /// Downcast the `DataSourceExec` to a specific file source
+    pub fn downcast_to_source<T: 'static>(&self) -> Option<(&FileScanConfig, &T)> {

Review Comment:
   Agree, `downcast_to_file_source` is better.
   
   
   
   > Also is there any need for '`static` ?
   
   Yes, compiler told me to do this lol



-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "mertak-synnada (via GitHub)" <gi...@apache.org>.
mertak-synnada commented on code in PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#discussion_r2011761950


##########
datafusion/datasource/src/source.rs:
##########
@@ -230,4 +231,17 @@ impl DataSourceExec {
             Boundedness::Bounded,
         )
     }
+
+    /// Downcast the `DataSourceExec` to a specific file source
+    pub fn downcast_to_source<T: 'static>(&self) -> Option<(&FileScanConfig, &T)> {

Review Comment:
   Looks like a great simplification I think, thanks!
   
   But since `data_source` can be both `FileScanConfig` or `MemorySourceConfig` maybe renaming this function as `downcast_to_file_source` would be better. Or we can dynamically check the `T` and downcast properly I think.



-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on PR #15416:
URL: https://github.com/apache/datafusion/pull/15416#issuecomment-2753986238

   I added the change to the upgrading doc to let users find it easily: https://github.com/apache/datafusion/pull/15416/commits/4682fcdc22c52774e6c1d5cef5ab25a0fab7937c


-- 
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: [PR] Add `downcast_to_source` method for `DataSourceExec` [datafusion]

Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 merged PR #15416:
URL: https://github.com/apache/datafusion/pull/15416


-- 
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