2019-05-13 23:44:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Common/Exception.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2019-05-13 23:44:55 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This class can be used as an argument for the template class FunctionJSON when we unable to parse JSONs.
|
|
|
|
/// It can't do anything useful and just throws an exception.
|
|
|
|
struct DummyJSONParser
|
|
|
|
{
|
2020-07-11 21:04:22 +00:00
|
|
|
class Array;
|
|
|
|
class Object;
|
|
|
|
|
2020-07-20 17:01:58 +00:00
|
|
|
/// References an element in a JSON document, representing a JSON null, boolean, string, number,
|
|
|
|
/// array or object.
|
2020-07-11 21:04:22 +00:00
|
|
|
class Element
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Element() {}
|
|
|
|
bool isInt64() const { return false; }
|
|
|
|
bool isUInt64() const { return false; }
|
|
|
|
bool isDouble() const { return false; }
|
|
|
|
bool isString() const { return false; }
|
|
|
|
bool isArray() const { return false; }
|
|
|
|
bool isObject() const { return false; }
|
|
|
|
bool isBool() const { return false; }
|
|
|
|
bool isNull() const { return false; }
|
|
|
|
|
|
|
|
Int64 getInt64() const { return 0; }
|
|
|
|
UInt64 getUInt64() const { return 0; }
|
|
|
|
double getDouble() const { return 0; }
|
|
|
|
bool getBool() const { return false; }
|
|
|
|
std::string_view getString() const { return {}; }
|
2020-07-23 21:54:13 +00:00
|
|
|
Array getArray() const { return {}; }
|
|
|
|
Object getObject() const { return {}; }
|
2021-05-15 10:10:19 +00:00
|
|
|
|
2021-06-25 15:33:31 +00:00
|
|
|
Element getElement() { return {}; }
|
2020-07-11 21:04:22 +00:00
|
|
|
};
|
|
|
|
|
2020-07-20 17:01:58 +00:00
|
|
|
/// References an array in a JSON document.
|
2020-07-11 21:04:22 +00:00
|
|
|
class Array
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Iterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Element operator*() const { return {}; }
|
2020-07-20 17:01:58 +00:00
|
|
|
Iterator & operator++() { return *this; }
|
|
|
|
Iterator operator++(int) { return *this; }
|
|
|
|
friend bool operator==(const Iterator &, const Iterator &) { return true; }
|
|
|
|
friend bool operator!=(const Iterator &, const Iterator &) { return false; }
|
2020-07-11 21:04:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Iterator begin() const { return {}; }
|
|
|
|
Iterator end() const { return {}; }
|
|
|
|
size_t size() const { return 0; }
|
|
|
|
Element operator[](size_t) const { return {}; }
|
|
|
|
};
|
|
|
|
|
2020-07-20 17:01:58 +00:00
|
|
|
using KeyValuePair = std::pair<std::string_view, Element>;
|
|
|
|
|
|
|
|
/// References an object in a JSON document.
|
2020-07-11 21:04:22 +00:00
|
|
|
class Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Iterator
|
|
|
|
{
|
|
|
|
public:
|
2020-07-20 17:01:58 +00:00
|
|
|
KeyValuePair operator*() const { return {}; }
|
|
|
|
Iterator & operator++() { return *this; }
|
|
|
|
Iterator operator++(int) { return *this; }
|
|
|
|
friend bool operator==(const Iterator &, const Iterator &) { return true; }
|
|
|
|
friend bool operator!=(const Iterator &, const Iterator &) { return false; }
|
2020-07-11 21:04:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Iterator begin() const { return {}; }
|
|
|
|
Iterator end() const { return {}; }
|
|
|
|
size_t size() const { return 0; }
|
|
|
|
bool find(const std::string_view &, Element &) const { return false; }
|
2020-07-20 17:01:58 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/// Optional: Provides access to an object's element by index.
|
|
|
|
KeyValuePair operator[](size_t) const { return {}; }
|
|
|
|
#endif
|
2020-07-11 21:04:22 +00:00
|
|
|
};
|
|
|
|
|
2020-07-20 17:01:58 +00:00
|
|
|
/// Parses a JSON document, returns the reference to its root element if succeeded.
|
2020-07-11 21:04:22 +00:00
|
|
|
bool parse(const std::string_view &, Element &) { throw Exception{"Functions JSON* are not supported", ErrorCodes::NOT_IMPLEMENTED}; }
|
2020-07-20 17:01:58 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/// Optional: Allocates memory to parse JSON documents faster.
|
|
|
|
void reserve(size_t max_size);
|
|
|
|
#endif
|
2019-05-13 23:44:55 +00:00
|
|
|
};
|
|
|
|
|
2021-06-25 15:33:31 +00:00
|
|
|
inline ALWAYS_INLINE std::ostream& operator<<(std::ostream& out, DummyJSONParser::Element)
|
2021-06-03 21:17:51 +00:00
|
|
|
{
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2019-05-13 23:44:55 +00:00
|
|
|
}
|