File indexing completed on 2025-08-28 08:26:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #pragma once
0021
0022 #include <memory>
0023 #include <string>
0024
0025 #include "arrow/dataset/file_base.h"
0026 #include "arrow/dataset/type_fwd.h"
0027 #include "arrow/dataset/visibility.h"
0028 #include "arrow/io/type_fwd.h"
0029 #include "arrow/ipc/type_fwd.h"
0030 #include "arrow/result.h"
0031
0032 namespace arrow {
0033 namespace dataset {
0034
0035
0036
0037
0038
0039 constexpr char kIpcTypeName[] = "ipc";
0040
0041
0042 class ARROW_DS_EXPORT IpcFileFormat : public FileFormat {
0043 public:
0044 std::string type_name() const override { return kIpcTypeName; }
0045
0046 IpcFileFormat();
0047
0048 bool Equals(const FileFormat& other) const override {
0049 return type_name() == other.type_name();
0050 }
0051
0052 Result<bool> IsSupported(const FileSource& source) const override;
0053
0054
0055 Result<std::shared_ptr<Schema>> Inspect(const FileSource& source) const override;
0056
0057 Result<RecordBatchGenerator> ScanBatchesAsync(
0058 const std::shared_ptr<ScanOptions>& options,
0059 const std::shared_ptr<FileFragment>& file) const override;
0060
0061 Future<std::optional<int64_t>> CountRows(
0062 const std::shared_ptr<FileFragment>& file, compute::Expression predicate,
0063 const std::shared_ptr<ScanOptions>& options) override;
0064
0065 Result<std::shared_ptr<FileWriter>> MakeWriter(
0066 std::shared_ptr<io::OutputStream> destination, std::shared_ptr<Schema> schema,
0067 std::shared_ptr<FileWriteOptions> options,
0068 fs::FileLocator destination_locator) const override;
0069
0070 std::shared_ptr<FileWriteOptions> DefaultWriteOptions() override;
0071 };
0072
0073
0074 class ARROW_DS_EXPORT IpcFragmentScanOptions : public FragmentScanOptions {
0075 public:
0076 std::string type_name() const override { return kIpcTypeName; }
0077
0078
0079
0080 std::shared_ptr<ipc::IpcReadOptions> options;
0081
0082
0083 std::shared_ptr<io::CacheOptions> cache_options;
0084 };
0085
0086 class ARROW_DS_EXPORT IpcFileWriteOptions : public FileWriteOptions {
0087 public:
0088
0089 std::shared_ptr<ipc::IpcWriteOptions> options;
0090
0091
0092 std::shared_ptr<const KeyValueMetadata> metadata;
0093
0094 protected:
0095 explicit IpcFileWriteOptions(std::shared_ptr<FileFormat> format)
0096 : FileWriteOptions(std::move(format)) {}
0097
0098 friend class IpcFileFormat;
0099 };
0100
0101 class ARROW_DS_EXPORT IpcFileWriter : public FileWriter {
0102 public:
0103 Status Write(const std::shared_ptr<RecordBatch>& batch) override;
0104
0105 private:
0106 IpcFileWriter(std::shared_ptr<io::OutputStream> destination,
0107 std::shared_ptr<ipc::RecordBatchWriter> writer,
0108 std::shared_ptr<Schema> schema,
0109 std::shared_ptr<IpcFileWriteOptions> options,
0110 fs::FileLocator destination_locator);
0111
0112 Future<> FinishInternal() override;
0113
0114 std::shared_ptr<io::OutputStream> destination_;
0115 std::shared_ptr<ipc::RecordBatchWriter> batch_writer_;
0116
0117 friend class IpcFileFormat;
0118 };
0119
0120
0121
0122 }
0123 }