OpenMS
Loading...
Searching...
No Matches
ParquetFile.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Justin Sing $
6// $Authors: Justin Sing $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
13
14#include <arrow/api.h>
15#include <arrow/io/interfaces.h>
16
17#include <memory>
18#include <string>
19#include <vector>
20
21namespace OpenMS
22{
23
43 class OPENMS_DLLAPI ParquetFile
44 {
45 public:
49
58 static void appendOrThrow(const arrow::Status& status, const std::string& column);
59
70 template <typename BuilderT>
71 static std::shared_ptr<arrow::Array> finishArray(BuilderT& builder, const std::string& name)
72 {
73 std::shared_ptr<arrow::Array> array;
74 auto status = builder.Finish(&array);
75 if (!status.ok())
76 {
77 throw_finish_error_(name, status.ToString());
78 }
79 return array;
80 }
81
83
87
98 static void writeTable(const std::shared_ptr<arrow::Table>& table, const std::string& filename,
99 int64_t row_group_size = 262144);
100
112 static std::shared_ptr<arrow::Table> readTable(const std::string& filename);
118 static std::shared_ptr<arrow::Table> readTable(const std::shared_ptr<arrow::io::RandomAccessFile>& infile);
119
121
125
137 static std::shared_ptr<arrow::Array> getColumn(const std::shared_ptr<arrow::Table>& table,
138 const std::string& name);
139
150 static std::shared_ptr<arrow::Array> getOptionalColumn(const std::shared_ptr<arrow::Table>& table,
151 const std::string& name);
152
154
158
174 static int64_t getInt64(const std::shared_ptr<arrow::Array>& array, int64_t row,
175 int64_t default_value, bool allow_null);
176
192 static double getDouble(const std::shared_ptr<arrow::Array>& array, int64_t row,
193 double default_value, bool allow_null);
194
210 static bool getBool(const std::shared_ptr<arrow::Array>& array, int64_t row,
211 bool default_value, bool allow_null);
212
225 static std::string getString(const std::shared_ptr<arrow::Array>& array, int64_t row);
226
239 static std::vector<std::string> getStringList(const std::shared_ptr<arrow::Array>& array, int64_t row);
240
242
246
254 static std::string jsonEscape(const std::string& input);
255
260 static int64_t rowCount(const std::string& filename);
261
263
264
265 private:
267 static void throw_finish_error_(const std::string& name, const std::string& error);
268 };
269
270} // namespace OpenMS
Shared utilities for reading, writing, and packaging Parquet-based file formats.
Definition ParquetFile.h:44
static void throw_finish_error_(const std::string &name, const std::string &error)
Internal helper to throw a consistent error from finishArray.
static std::shared_ptr< arrow::Array > finishArray(BuilderT &builder, const std::string &name)
Finish an Arrow builder and return the resulting Array.
Definition ParquetFile.h:71
static void appendOrThrow(const arrow::Status &status, const std::string &column)
Append a value to an Arrow builder, throwing on failure.
static std::vector< std::string > getStringList(const std::shared_ptr< arrow::Array > &array, int64_t row)
Read a list of strings from an Arrow Array.
static int64_t getInt64(const std::shared_ptr< arrow::Array > &array, int64_t row, int64_t default_value, bool allow_null)
Read an integer value from an Arrow Array with type coercion.
static double getDouble(const std::shared_ptr< arrow::Array > &array, int64_t row, double default_value, bool allow_null)
Read a floating-point value from an Arrow Array with type coercion.
static std::string jsonEscape(const std::string &input)
Escape a string for safe embedding into JSON values.
static std::string getString(const std::shared_ptr< arrow::Array > &array, int64_t row)
Read a string value from an Arrow Array.
static std::shared_ptr< arrow::Table > readTable(const std::string &filename)
Read a Parquet file into an Arrow Table.
static std::shared_ptr< arrow::Array > getOptionalColumn(const std::shared_ptr< arrow::Table > &table, const std::string &name)
Get an optional column from an Arrow Table by name.
static bool getBool(const std::shared_ptr< arrow::Array > &array, int64_t row, bool default_value, bool allow_null)
Read a boolean value from an Arrow Array with type coercion.
static int64_t rowCount(const std::string &filename)
Return the number of rows in a parquet file using the low-level parquet reader metadata....
static void writeTable(const std::shared_ptr< arrow::Table > &table, const std::string &filename, int64_t row_group_size=262144)
Write an Arrow Table to a Parquet file.
static std::shared_ptr< arrow::Array > getColumn(const std::shared_ptr< arrow::Table > &table, const std::string &name)
Get a required column from an Arrow Table by name.
static std::shared_ptr< arrow::Table > readTable(const std::shared_ptr< arrow::io::RandomAccessFile > &infile)
Read a Parquet file from an Arrow RandomAccessFile into an Arrow Table.
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19