Execute the `DataFrame` and return a string representation of the results. # Example ``` # use datafusion::prelude::*; # use datafusion::error::Result; # use datafusion::execution::SessionStateBuilder; # #[tokio::main] # async fn main() -> Result<()> { let cfg = SessionConfig::new() .set_str("datafusion.format.null", "no-value"); let session_state = SessionStateBuilder::new() .with_config(cfg) .
(self)
| 1516 | /// # Ok(()) |
| 1517 | /// # } |
| 1518 | pub async fn to_string(self) -> Result<String> { |
| 1519 | let options = self.session_state.config().options().format.clone(); |
| 1520 | let arrow_options: arrow::util::display::FormatOptions = (&options).try_into()?; |
| 1521 | |
| 1522 | let registry = self.session_state.extension_type_registry(); |
| 1523 | let formatter_factory = DFArrayFormatterFactory::new(Arc::clone(registry)); |
| 1524 | let arrow_options = |
| 1525 | arrow_options.with_formatter_factory(Some(&formatter_factory)); |
| 1526 | |
| 1527 | let results = self.collect().await?; |
| 1528 | Ok( |
| 1529 | pretty::pretty_format_batches_with_options(&results, &arrow_options)? |
| 1530 | .to_string(), |
| 1531 | ) |
| 1532 | } |
| 1533 | |
| 1534 | /// Execute the `DataFrame` and print only the first `num` rows of the |
| 1535 | /// result to the console. |