2019-08-29 19:29:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
2019-09-24 14:25:22 +00:00
|
|
|
#include <Formats/FormatSchemaInfo.h>
|
2019-12-25 19:17:41 +00:00
|
|
|
#include <Formats/FormatSettings.h>
|
2019-08-29 19:29:54 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-09-24 19:56:45 +00:00
|
|
|
class Block;
|
|
|
|
|
2019-08-29 19:29:54 +00:00
|
|
|
struct ParsedTemplateFormatString
|
|
|
|
{
|
|
|
|
enum class ColumnFormat
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Escaped,
|
|
|
|
Quoted,
|
|
|
|
Csv,
|
|
|
|
Json,
|
|
|
|
Xml,
|
|
|
|
Raw
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Format string has syntax: "Delimiter0 ${ColumnName0:Format0} Delimiter1 ${ColumnName1:Format1} Delimiter2"
|
|
|
|
/// The following vectors is filled with corresponding values, delimiters.size() - 1 = formats.size() = format_idx_to_column_idx.size()
|
|
|
|
/// If format_idx_to_column_idx[i] has no value, then TemplateRowInputFormat will skip i-th column.
|
|
|
|
|
|
|
|
std::vector<String> delimiters;
|
|
|
|
std::vector<ColumnFormat> formats;
|
|
|
|
std::vector<std::optional<size_t>> format_idx_to_column_idx;
|
|
|
|
|
|
|
|
/// For diagnostic info
|
|
|
|
Strings column_names;
|
|
|
|
|
|
|
|
typedef std::function<std::optional<size_t>(const String &)> ColumnIdxGetter;
|
|
|
|
|
|
|
|
ParsedTemplateFormatString() = default;
|
2019-09-24 14:25:22 +00:00
|
|
|
ParsedTemplateFormatString(const FormatSchemaInfo & schema, const ColumnIdxGetter & idx_by_name);
|
2019-08-29 19:29:54 +00:00
|
|
|
|
|
|
|
void parse(const String & format_string, const ColumnIdxGetter & idx_by_name);
|
|
|
|
|
2019-09-24 19:56:45 +00:00
|
|
|
static ColumnFormat stringToFormat(const String & format);
|
2019-08-29 19:29:54 +00:00
|
|
|
static String formatToString(ColumnFormat format);
|
|
|
|
static const char * readMayBeQuotedColumnNameInto(const char * pos, size_t size, String & s);
|
|
|
|
size_t columnsCount() const;
|
|
|
|
|
|
|
|
String dump() const;
|
|
|
|
[[noreturn]] void throwInvalidFormat(const String & message, size_t column) const;
|
2019-09-24 19:56:45 +00:00
|
|
|
|
2019-12-25 19:17:41 +00:00
|
|
|
static ParsedTemplateFormatString setupCustomSeparatedResultsetFormat(const FormatSettings::Custom & settings);
|
|
|
|
static ParsedTemplateFormatString setupCustomSeparatedRowFormat(const FormatSettings::Custom & settings, const Block & sample);
|
2019-08-29 19:29:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|