2020-03-26 16:33:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-07-16 11:08:26 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
# include "config_formats.h"
|
|
|
|
# include "config_core.h"
|
|
|
|
#endif
|
|
|
|
|
2020-07-10 19:08:18 +00:00
|
|
|
|
|
|
|
#if USE_MSGPACK
|
|
|
|
|
2020-03-26 16:33:00 +00:00
|
|
|
#include <Processors/Formats/IRowInputFormat.h>
|
|
|
|
#include <Formats/FormatFactory.h>
|
2020-04-03 20:44:13 +00:00
|
|
|
#include <IO/PeekableReadBuffer.h>
|
2020-03-26 16:33:00 +00:00
|
|
|
#include <msgpack.hpp>
|
2020-04-17 09:35:38 +00:00
|
|
|
#include <stack>
|
2020-03-26 16:33:00 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ReadBuffer;
|
|
|
|
|
2020-04-17 19:19:03 +00:00
|
|
|
class MsgPackVisitor : public msgpack::null_visitor
|
|
|
|
{
|
2020-04-17 09:35:38 +00:00
|
|
|
public:
|
|
|
|
struct Info
|
|
|
|
{
|
|
|
|
IColumn & column;
|
|
|
|
DataTypePtr type;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// These functions are called when parser meets corresponding object in parsed data
|
|
|
|
bool visit_positive_integer(UInt64 value);
|
|
|
|
bool visit_negative_integer(Int64 value);
|
|
|
|
bool visit_float32(Float32 value);
|
|
|
|
bool visit_float64(Float64 value);
|
|
|
|
bool visit_str(const char* value, size_t size);
|
|
|
|
bool start_array(size_t size);
|
|
|
|
bool end_array();
|
|
|
|
|
|
|
|
/// This function will be called if error occurs in parsing
|
2020-04-17 20:51:53 +00:00
|
|
|
[[noreturn]] void parse_error(size_t parsed_offset, size_t error_offset);
|
2020-04-17 09:35:38 +00:00
|
|
|
|
|
|
|
/// Update info_stack
|
|
|
|
void set_info(IColumn & column, DataTypePtr type);
|
|
|
|
|
|
|
|
void insert_integer(UInt64 value);
|
|
|
|
|
2020-06-11 00:51:27 +00:00
|
|
|
void reset();
|
|
|
|
|
2020-04-17 09:35:38 +00:00
|
|
|
private:
|
|
|
|
/// Stack is needed to process nested arrays
|
|
|
|
std::stack<Info> info_stack;
|
|
|
|
};
|
|
|
|
|
2020-03-26 16:33:00 +00:00
|
|
|
class MsgPackRowInputFormat : public IRowInputFormat
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MsgPackRowInputFormat(const Block & header_, ReadBuffer & in_, Params params_);
|
|
|
|
|
|
|
|
bool readRow(MutableColumns & columns, RowReadExtension & ext) override;
|
|
|
|
String getName() const override { return "MagPackRowInputFormat"; }
|
2020-06-11 00:51:27 +00:00
|
|
|
void resetParser() override;
|
|
|
|
|
2020-03-26 16:33:00 +00:00
|
|
|
private:
|
|
|
|
bool readObject();
|
|
|
|
|
2020-04-03 20:44:13 +00:00
|
|
|
PeekableReadBuffer buf;
|
2020-04-17 09:35:38 +00:00
|
|
|
MsgPackVisitor visitor;
|
|
|
|
msgpack::detail::parse_helper<MsgPackVisitor> parser;
|
2020-06-11 00:51:27 +00:00
|
|
|
const DataTypes data_types;
|
2020-03-26 16:33:00 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 21:11:33 +00:00
|
|
|
}
|
2020-07-10 19:08:18 +00:00
|
|
|
|
|
|
|
#endif
|