Skip to main content

datafusion_datasource_json/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#![cfg_attr(test, allow(clippy::needless_pass_by_value))]
19// Make sure fast / cheap clones on Arc are explicit:
20// https://github.com/apache/datafusion/issues/11143
21#![cfg_attr(not(test), deny(clippy::clone_on_ref_ptr))]
22
23pub mod boundary_stream;
24pub mod file_format;
25pub mod source;
26pub mod utils;
27
28pub use file_format::*;
29
30#[cfg(test)]
31pub(crate) mod test_utils {
32    use std::sync::Arc;
33
34    use bytes::Bytes;
35    use object_store::chunked::ChunkedStore;
36    use object_store::memory::InMemory;
37    use object_store::path::Path;
38    use object_store::{ObjectStore, ObjectStoreExt, PutPayload};
39
40    /// Chunk sizes exercised by every parameterised test.
41    ///
42    /// `usize::MAX` is intentionally included: `ChunkedStore` treats it as
43    /// "one chunk containing everything", giving the single-chunk fast path.
44    pub const CHUNK_SIZES: &[usize] = &[1, 2, 3, 4, 5, 7, 8, 11, 13, 16, usize::MAX];
45
46    /// Seed a fresh `InMemory` store with `data` and wrap it in a
47    /// [`ChunkedStore`] that splits every GET response into `chunk_size`-byte
48    /// pieces.
49    pub async fn make_chunked_store(
50        data: &[u8],
51        chunk_size: usize,
52    ) -> (Arc<dyn ObjectStore>, Path) {
53        let inner = Arc::new(InMemory::new());
54        let path = Path::from("test");
55        inner
56            .put(&path, PutPayload::from(Bytes::copy_from_slice(data)))
57            .await
58            .unwrap();
59        (Arc::new(ChunkedStore::new(inner, chunk_size)), path)
60    }
61}