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

[I] How to write csv file to disk from a empty dataframe? [datafusion]

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

   I want write a csv file only include headers;
   
   ```
   use datafusion::config::CsvOptions;
   use datafusion::dataframe::DataFrameWriteOptions;
   use datafusion::error::Result;
   use datafusion::prelude::*;
   use std::path::Path;
   
   #[tokio::main]
   async fn main() -> Result<()> {
       let ctx = SessionContext::new();
   
       let df = ctx.sql("SELECT 1 limit 0").await?;
   
       let mut cfg1 = DataFrameWriteOptions::new();
       cfg1 = cfg1.with_single_file_output(true);
   
       let mut cfg2 = CsvOptions::default();
       cfg2.has_header = Some(true);
   
       df.write_csv("/tmp/t.csv", cfg1, Some(cfg2)).await?;
       assert_eq!(Path::new("/tmp/t.csv").exists(), true);  // panic!
       Ok(())
   }
   ```


-- 
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] How to write csv file to disk from a empty dataframe? [datafusion]

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

   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] How to write csv file to disk from a empty dataframe? [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #16240: How to write csv file to disk from a empty dataframe?
URL: https://github.com/apache/datafusion/issues/16240


-- 
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] How to write csv file to disk from a empty dataframe? [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew closed issue #16240: How to write csv file to disk from a empty dataframe?
URL: https://github.com/apache/datafusion/issues/16240


-- 
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] How to write csv file to disk from a empty dataframe? [datafusion]

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

   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] How to write csv file to disk from a empty dataframe? [datafusion]

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

   I am not sure -- it seems like maybe we should have an option in DataFrameWriteOptions that will force an empty file to be written even if there are no rows 🤔 


-- 
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] How to write csv file to disk from a empty dataframe? [datafusion]

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

   I want do something like materialized view. I have to deal with this special case if datafusion can't write empty data frame;


-- 
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] How to write csv file to disk from a empty dataframe? [datafusion]

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

   I can add that for Arrow format the empty DataFrame also does not create a file.


-- 
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] How to write csv file to disk from a empty dataframe? [datafusion]

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

   Unfortunately, we had to revert the original fix, see
   -  https://github.com/apache/datafusion/pull/16682
   
   So I am reopening the ticket to track


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