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
27#include <arrow/filesystem/type_fwd.h>
28#include <arrow/io/type_fwd.h>
29
30#include "iceberg/file_io.h"
31#include "iceberg/iceberg_bundle_export.h"
32
33namespace iceberg::arrow {
34
40ICEBERG_BUNDLE_EXPORT Result<std::shared_ptr<::arrow::io::RandomAccessFile>>
41OpenArrowInputStream(const std::shared_ptr<FileIO>& io, const std::string& path,
42 std::optional<size_t> length = std::nullopt);
43
49ICEBERG_BUNDLE_EXPORT Result<std::shared_ptr<::arrow::io::OutputStream>>
50OpenArrowOutputStream(const std::shared_ptr<FileIO>& io, const std::string& path,
51 bool overwrite = true);
52
54class ICEBERG_BUNDLE_EXPORT ArrowFileSystemFileIO : public FileIO {
55 public:
56 explicit ArrowFileSystemFileIO(std::shared_ptr<::arrow::fs::FileSystem> arrow_fs)
57 : arrow_fs_(std::move(arrow_fs)) {}
58
60 static std::unique_ptr<FileIO> MakeMockFileIO();
61
63 static std::unique_ptr<FileIO> MakeLocalFileIO();
64
65 ~ArrowFileSystemFileIO() override = default;
66
68 Result<std::unique_ptr<InputFile>> NewInputFile(std::string file_location) override;
69
71 Result<std::unique_ptr<InputFile>> NewInputFile(std::string file_location,
72 size_t length) override;
73
75 Result<std::unique_ptr<OutputFile>> NewOutputFile(std::string file_location) override;
76
78 Status DeleteFile(const std::string& file_location) override;
79
81 const std::shared_ptr<::arrow::fs::FileSystem>& fs() const { return arrow_fs_; }
82
83 private:
84 friend Result<std::shared_ptr<::arrow::io::RandomAccessFile>> OpenArrowInputStream(
85 const std::shared_ptr<FileIO>& io, const std::string& path,
86 std::optional<size_t> length);
87
88 friend Result<std::shared_ptr<::arrow::io::OutputStream>> OpenArrowOutputStream(
89 const std::shared_ptr<FileIO>& io, const std::string& path, bool overwrite);
90
92 Result<std::string> ResolvePath(const std::string& file_location);
93
94 std::shared_ptr<::arrow::fs::FileSystem> arrow_fs_;
95};
96
97} // namespace iceberg::arrow
Pluggable module for reading, writing, and deleting files.
Definition file_io.h:115
A concrete implementation of FileIO for Arrow file system.
Definition arrow_io_internal.h:54
const std::shared_ptr<::arrow::fs::FileSystem > & fs() const
Get the Arrow file system.
Definition arrow_io_internal.h:81