Returns file groups [`Vec `] for scanning `partitions` of `filename`
(
path: &str,
filename: &str,
partitions: usize,
file_format: &Arc<dyn FileFormat>,
file_compression_type: FileCompressionType,
work_dir: &Path,
)
| 114 | |
| 115 | /// Returns file groups [`Vec<FileGroup>`] for scanning `partitions` of `filename` |
| 116 | pub fn partitioned_file_groups( |
| 117 | path: &str, |
| 118 | filename: &str, |
| 119 | partitions: usize, |
| 120 | file_format: &Arc<dyn FileFormat>, |
| 121 | file_compression_type: FileCompressionType, |
| 122 | work_dir: &Path, |
| 123 | ) -> Result<Vec<FileGroup>> { |
| 124 | let path = format!("{path}/{filename}"); |
| 125 | |
| 126 | let mut writers = vec![]; |
| 127 | let mut files = vec![]; |
| 128 | for i in 0..partitions { |
| 129 | let filename = format!( |
| 130 | "partition-{}{}", |
| 131 | i, |
| 132 | file_format |
| 133 | .get_ext_with_compression(&file_compression_type) |
| 134 | .unwrap() |
| 135 | ); |
| 136 | let filename = work_dir.join(filename); |
| 137 | |
| 138 | let file = File::create(&filename).unwrap(); |
| 139 | |
| 140 | let encoder: Box<dyn Write + Send> = match file_compression_type.to_owned() { |
| 141 | FileCompressionType::UNCOMPRESSED => Box::new(file), |
| 142 | #[cfg(feature = "compression")] |
| 143 | FileCompressionType::GZIP => { |
| 144 | Box::new(GzEncoder::new(file, GzCompression::default())) |
| 145 | } |
| 146 | #[cfg(feature = "compression")] |
| 147 | FileCompressionType::XZ => Box::new(XzEncoder::new(file, 9)), |
| 148 | #[cfg(feature = "compression")] |
| 149 | FileCompressionType::ZSTD => { |
| 150 | let encoder = ZstdEncoder::new(file, 0) |
| 151 | .map_err(|e| DataFusionError::External(Box::new(e)))? |
| 152 | .auto_finish(); |
| 153 | Box::new(encoder) |
| 154 | } |
| 155 | #[cfg(feature = "compression")] |
| 156 | FileCompressionType::BZIP2 => { |
| 157 | Box::new(BzEncoder::new(file, BzCompression::default())) |
| 158 | } |
| 159 | #[cfg(not(feature = "compression"))] |
| 160 | FileCompressionType::GZIP |
| 161 | | FileCompressionType::BZIP2 |
| 162 | | FileCompressionType::XZ |
| 163 | | FileCompressionType::ZSTD => { |
| 164 | panic!("Compression is not supported in this build") |
| 165 | } |
| 166 | }; |
| 167 | |
| 168 | let writer = BufWriter::new(encoder); |
| 169 | writers.push(writer); |
| 170 | files.push(filename); |
| 171 | } |
| 172 | |
| 173 | let f = File::open(path)?; |
no test coverage detected
searching dependent graphs…