mirror of
https://github.com/wassname/ray.git
synced 2026-07-24 13:20:22 +08:00
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#ifndef NUMBUF_DICT_H
|
|
#define NUMBUF_DICT_H
|
|
|
|
#include <arrow/api.h>
|
|
|
|
#include "sequence.h"
|
|
|
|
namespace numbuf {
|
|
|
|
/*! Constructing dictionaries of key/value pairs. Sequences of
|
|
keys and values are built separately using a pair of
|
|
SequenceBuilders. The resulting Arrow representation
|
|
can be obtained via the Finish method.
|
|
*/
|
|
class DictBuilder {
|
|
public:
|
|
DictBuilder(arrow::MemoryPool* pool = nullptr)
|
|
: keys_(pool), vals_(pool) {}
|
|
|
|
//! Builder for the keys of the dictionary
|
|
SequenceBuilder& keys() { return keys_; }
|
|
//! Builder for the values of the dictionary
|
|
SequenceBuilder& vals() { return vals_; }
|
|
|
|
/*! Construct an Arrow StructArray representing the dictionary.
|
|
Contains a field "keys" for the keys and "vals" for the values.
|
|
|
|
\param list_data
|
|
List containing the data from nested lists in the value
|
|
list of the dictionary
|
|
|
|
\param dict_data
|
|
List containing the data from nested dictionaries in the
|
|
value list of the dictionary
|
|
*/
|
|
std::shared_ptr<arrow::StructArray> Finish(
|
|
std::shared_ptr<arrow::Array> key_tuple_data,
|
|
std::shared_ptr<arrow::Array> val_list_data,
|
|
std::shared_ptr<arrow::Array> val_tuple_data,
|
|
std::shared_ptr<arrow::Array> val_dict_data);
|
|
|
|
private:
|
|
SequenceBuilder keys_;
|
|
SequenceBuilder vals_;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|