aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Formats/FormatSchemaInfo.h
blob: e8758c3f76153c35185929bc965ec232d609932c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include <base/types.h>
#include <Formats/FormatSettings.h>
#include <Formats/StructureToCapnProtoSchema.h>
#include <Formats/StructureToProtobufSchema.h>

namespace DB
{
class Context;

/// Extracts information about where the format schema file is from passed context and keep it.
class FormatSchemaInfo
{
public:
    FormatSchemaInfo(const String & format_schema, const String & format, bool require_message, bool is_server, const std::string & format_schema_path);
    FormatSchemaInfo(const FormatSettings & settings, const String & format, bool require_message);

    /// Returns path to the schema file.
    const String & schemaPath() const { return schema_path; }
    String absoluteSchemaPath() const { return schema_directory + schema_path; }

    /// Returns directory containing the schema file.
    const String & schemaDirectory() const { return schema_directory; }

    /// Returns name of the message type.
    const String & messageName() const { return message_name; }

private:
    String schema_path;
    String schema_directory;
    String message_name;
};


template <typename SchemaGenerator>
class MaybeAutogeneratedFormatSchemaInfo
{
public:
    MaybeAutogeneratedFormatSchemaInfo(const FormatSettings & settings, const String & format, const Block & header, bool use_autogenerated_schema);

    ~MaybeAutogeneratedFormatSchemaInfo();

    const FormatSchemaInfo & getSchemaInfo() const { return *schema_info; }
private:

    std::unique_ptr<FormatSchemaInfo> schema_info;
    String tmp_file_path;
};

using CapnProtoSchemaInfo = MaybeAutogeneratedFormatSchemaInfo<StructureToCapnProtoSchema>;
using ProtobufSchemaInfo = MaybeAutogeneratedFormatSchemaInfo<StructureToProtobufSchema>;

}