aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/TableFunctions/ITableFunctionFileLike.h
blob: 5fe86587797805f4f02e920be0e5a3e457333aa2 (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
55
56
57
58
59
60
61
#pragma once

#include <TableFunctions/ITableFunction.h>
#include "Parsers/IAST_fwd.h"

namespace DB
{
class ColumnsDescription;
class Context;

/*
 * function(source, [format, structure, compression_method]) - creates a temporary storage from formatted source
 */
class ITableFunctionFileLike : public ITableFunction
{
public:
    static constexpr auto signature = " - filename\n"
                                      " - filename, format\n"
                                      " - filename, format, structure\n"
                                      " - filename, format, structure, compression_method\n";
    virtual String getSignature() const
    {
        return signature;
    }

    bool needStructureHint() const override { return structure == "auto"; }

    void setStructureHint(const ColumnsDescription & structure_hint_) override { structure_hint = structure_hint_; }

    bool supportsReadingSubsetOfColumns(const ContextPtr & context) override;

    static size_t getMaxNumberOfArguments() { return 4; }

    static void addColumnsStructureToArguments(ASTs & args, const String & structure, const ContextPtr &);

protected:

    void parseArguments(const ASTPtr & ast_function, ContextPtr context) override;
    virtual void parseArgumentsImpl(ASTs & args, const ContextPtr & context);

    virtual void parseFirstArguments(const ASTPtr & arg, const ContextPtr & context);
    virtual String getFormatFromFirstArgument();

    String filename;
    String path_to_archive;
    String format = "auto";
    String structure = "auto";
    String compression_method = "auto";
    ColumnsDescription structure_hint;

private:
    StoragePtr executeImpl(const ASTPtr & ast_function, ContextPtr context, const std::string & table_name, ColumnsDescription cached_columns, bool is_insert_query) const override;

    virtual StoragePtr getStorage(
        const String & source, const String & format, const ColumnsDescription & columns, ContextPtr global_context,
        const std::string & table_name, const String & compression_method) const = 0;

    bool hasStaticStructure() const override { return structure != "auto"; }
};

}