iceberg-cpp
Loading...
Searching...
No Matches
arrow_io_internal.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <cstddef>
23#include <memory>
24#include <optional>
25#include <string>
26#include <vector>
27
28#include <arrow/filesystem/type_fwd.h>
29#include <arrow/io/type_fwd.h>
30
31#include "iceberg/file_io.h"
32#include "iceberg/iceberg_bundle_export.h"
33
34namespace iceberg::arrow {
35
41ICEBERG_BUNDLE_EXPORT Result<std::shared_ptr<::arrow::io::RandomAccessFile>>
42OpenArrowInputStream(const std::shared_ptr<FileIO>& io, const std::string& path,
43 std::optional<size_t> length = std::nullopt);
44
50ICEBERG_BUNDLE_EXPORT Result<std::shared_ptr<::arrow::io::OutputStream>>
51OpenArrowOutputStream(const std::shared_ptr<FileIO>& io, const std::string& path,
52 bool overwrite = true);
53
55class ICEBERG_BUNDLE_EXPORT ArrowFileSystemFileIO : public FileIO {
56 public:
57 explicit ArrowFileSystemFileIO(std::shared_ptr<::arrow::fs::FileSystem> arrow_fs)
58 : arrow_fs_(std::move(arrow_fs)) {}
59
61 static std::unique_ptr<FileIO> MakeMockFileIO();
62
64 static std::unique_ptr<FileIO> MakeLocalFileIO();
65
66 ~ArrowFileSystemFileIO() override = default;
67
69 Result<std::unique_ptr<InputFile>> NewInputFile(std::string file_location) override;
70
72 Result<std::unique_ptr<InputFile>> NewInputFile(std::string file_location,
73 size_t length) override;
74
76 Result<std::unique_ptr<OutputFile>> NewOutputFile(std::string file_location) override;
77
79 Status DeleteFile(const std::string& file_location) override;
80
82 Status DeleteFiles(const std::vector<std::string>& file_locations) override;
83
85 const std::shared_ptr<::arrow::fs::FileSystem>& fs() const { return arrow_fs_; }
86
87 private:
88 friend Result<std::shared_ptr<::arrow::io::RandomAccessFile>> OpenArrowInputStream(
89 const std::shared_ptr<FileIO>& io, const std::string& path,
90 std::optional<size_t> length);
91
92 friend Result<std::shared_ptr<::arrow::io::OutputStream>> OpenArrowOutputStream(
93 const std::shared_ptr<FileIO>& io, const std::string& path, bool overwrite);
94
96 Result<std::string> ResolvePath(const std::string& file_location);
97
98 std::shared_ptr<::arrow::fs::FileSystem> arrow_fs_;
99};
100
101} // namespace iceberg::arrow
API for deleting data files from a table.
Definition delete_files.h:44
Pluggable module for reading, writing, and deleting files.
Definition file_io.h:125
A concrete implementation of FileIO for Arrow file system.
Definition arrow_io_internal.h:55
const std::shared_ptr<::arrow::fs::FileSystem > & fs() const
Get the Arrow file system.
Definition arrow_io_internal.h:85