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 file_format;
24pub mod source;
25pub mod utils;
26
27pub use file_format::*;
28
29#[cfg(test)]
30pub(crate) mod test_utils {
31 use std::sync::Arc;
32
33 use bytes::Bytes;
34 use object_store::chunked::ChunkedStore;
35 use object_store::memory::InMemory;
36 use object_store::path::Path;
37 use object_store::{ObjectStore, ObjectStoreExt, PutPayload};
38
39 /// Chunk sizes exercised by every parameterised test.
40 ///
41 /// `usize::MAX` is intentionally included: `ChunkedStore` treats it as
42 /// "one chunk containing everything", giving the single-chunk fast path.
43 pub const CHUNK_SIZES: &[usize] = &[1, 2, 3, 4, 5, 7, 8, 11, 13, 16, usize::MAX];
44
45 /// Seed a fresh `InMemory` store with `data` and wrap it in a
46 /// [`ChunkedStore`] that splits every GET response into `chunk_size`-byte
47 /// pieces.
48 pub async fn make_chunked_store(
49 data: &[u8],
50 chunk_size: usize,
51 ) -> (Arc<dyn ObjectStore>, Path) {
52 let inner = Arc::new(InMemory::new());
53 let path = Path::from("test");
54 inner
55 .put(&path, PutPayload::from(Bytes::copy_from_slice(data)))
56 .await
57 .unwrap();
58 (Arc::new(ChunkedStore::new(inner, chunk_size)), path)
59 }
60}