Skip to main content

datafusion_common/file_options/
json_writer.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! Options related to how json files should be written
6
7use crate::{
8    config::JsonOptions,
9    error::{DataFusionError, Result},
10    parsers::CompressionTypeVariant,
11};
12
13/// Options for writing JSON files
14#[derive(Clone, Debug)]
15pub struct JsonWriterOptions {
16    pub compression: CompressionTypeVariant,
17    pub compression_level: Option<u32>,
18}
19
20impl JsonWriterOptions {
21    pub fn new(compression: CompressionTypeVariant) -> Self {
22        Self {
23            compression,
24            compression_level: None,
25        }
26    }
27
28    /// Create a new `JsonWriterOptions` with the specified compression and level.
29    pub fn new_with_level(
30        compression: CompressionTypeVariant,
31        compression_level: u32,
32    ) -> Self {
33        Self {
34            compression,
35            compression_level: Some(compression_level),
36        }
37    }
38}
39
40impl TryFrom<&JsonOptions> for JsonWriterOptions {
41    type Error = DataFusionError;
42
43    fn try_from(value: &JsonOptions) -> Result<Self> {
44        Ok(JsonWriterOptions {
45            compression: value.compression,
46            compression_level: value.compression_level,
47        })
48    }
49}