ClickHouse/src/Interpreters/TableOverrideUtils.h
Stig Bakken 6fbb9f5e87 Implement EXPLAIN TABLE OVERRIDE for pre-validating overrides.
Example:

```sql
EXPLAIN TABLE OVERRIDE mysql('127.0.0.1:3306', 'db', 'table', 'user', 'pw')
    PARTITION BY tuple(toYYYYMM(created), id % 8)
```

Validations done:

 * check that storage overrides do not reference unknown or nullable columns
 * check that default specifier is not modified for columns
2021-12-30 09:02:27 +01:00

39 lines
895 B
C++

#pragma once
#include <Common/assert_cast.h>
#include <Core/Names.h>
#include <Core/NamesAndTypes.h>
#include <Parsers/ASTTableOverrides.h>
namespace DB
{
struct StorageInMemoryMetadata;
using NameToTypeMap = std::map<String, DataTypePtr>;
struct TableOverrideAnalyzer
{
struct Result
{
NameToTypeMap existing_types;
NamesAndTypes order_by_columns;
NamesAndTypes primary_key_columns;
NamesAndTypes partition_by_columns;
NamesAndTypes sample_by_columns;
NamesAndTypes ttl_columns;
NamesAndTypes added_columns;
NamesAndTypes modified_columns;
void appendTo(WriteBuffer &);
};
ASTTableOverride * override;
explicit TableOverrideAnalyzer(ASTPtr ast) : override(assert_cast<ASTTableOverride *>(ast.get())) { }
void analyze(const StorageInMemoryMetadata & metadata, Result & result) const;
};
}