MCPcopy Create free account
hub / github.com/apache/datafusion / write_json

Method write_json

datafusion/core/src/dataframe/mod.rs:2115–2162  ·  view source on GitHub ↗

Execute the `DataFrame` and write the results to JSON file(s). # Example ``` # use datafusion::prelude::*; # use datafusion::error::Result; # use std::fs; # #[tokio::main] # async fn main() -> Result<()> { use datafusion::dataframe::DataFrameWriteOptions; let ctx = SessionContext::new(); // Sort the data by column "b" and write it to a new location ctx.read_csv("tests/data/example.csv", CsvReadOp

(
        self,
        path: &str,
        options: DataFrameWriteOptions,
        writer_options: Option<JsonOptions>,
    )

Source from the content-addressed store, hash-verified

2113 /// # }
2114 /// ```
2115 pub async fn write_json(
2116 self,
2117 path: &str,
2118 options: DataFrameWriteOptions,
2119 writer_options: Option<JsonOptions>,
2120 ) -> Result<Vec<RecordBatch>, DataFusionError> {
2121 if options.insert_op != InsertOp::Append {
2122 return not_impl_err!(
2123 "{} is not implemented for DataFrame::write_json.",
2124 options.insert_op
2125 );
2126 }
2127
2128 let format = if let Some(json_opts) = writer_options {
2129 Arc::new(JsonFormatFactory::new_with_options(json_opts))
2130 } else {
2131 Arc::new(JsonFormatFactory::new())
2132 };
2133
2134 let file_type = format_as_file_type(format);
2135
2136 let copy_options = options.build_sink_options();
2137
2138 let plan = if options.sort_by.is_empty() {
2139 self.plan
2140 } else {
2141 LogicalPlanBuilder::from(self.plan)
2142 .sort(options.sort_by)?
2143 .build()?
2144 };
2145
2146 let plan = LogicalPlanBuilder::copy_to(
2147 plan,
2148 path.into(),
2149 file_type,
2150 copy_options,
2151 options.partition_by,
2152 )?
2153 .build()?;
2154
2155 DataFrame {
2156 session_state: self.session_state,
2157 plan,
2158 projection_requires_validation: self.projection_requires_validation,
2159 }
2160 .collect()
2161 .await
2162 }
2163
2164 /// Add or replace a column in the DataFrame.
2165 ///

Callers 7

write_outFunction · 0.45
dataframe_to_s3Function · 0.45
write_json_resultsFunction · 0.45
write_json_with_orderFunction · 0.45

Calls 8

newFunction · 0.85
format_as_file_typeFunction · 0.85
build_sink_optionsMethod · 0.80
collectMethod · 0.80
is_emptyMethod · 0.45
buildMethod · 0.45
sortMethod · 0.45
intoMethod · 0.45