ClickHouse/src/Storages/ColumnDependency.h

61 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include <Common/SipHash.h>
2020-09-15 09:55:57 +00:00
#include <common/types.h>
#include <unordered_set>
namespace DB
{
2020-02-21 16:53:33 +00:00
/// Represents dependency from other column.
/// Used to determine, which columns we have to read, if we want to update some other column.
2020-08-08 00:47:03 +00:00
/// Necessary, because table can have some dependencies, which requires several columns for calculation.
struct ColumnDependency
{
2020-02-18 19:03:40 +00:00
enum Kind : UInt8
{
2020-02-21 16:53:33 +00:00
/// Exists any skip index, that requires @column_name
SKIP_INDEX,
/// Exists any projection, that requires @column_name
PROJECTION,
2020-02-21 16:53:33 +00:00
/// Exists any TTL expression, that requires @column_name
TTL_EXPRESSION,
/// TTL is set for @column_name.
TTL_TARGET
};
ColumnDependency(const String & column_name_, Kind kind_)
: column_name(column_name_), kind(kind_) {}
String column_name;
Kind kind;
bool isReadOnly() const
{
return kind == SKIP_INDEX || kind == PROJECTION || kind == TTL_EXPRESSION;
}
bool operator==(const ColumnDependency & other) const
{
return kind == other.kind && column_name == other.column_name;
}
struct Hash
{
UInt64 operator()(const ColumnDependency & dependency) const
{
SipHash hash;
hash.update(dependency.column_name);
hash.update(dependency.kind);
return hash.get64();
}
};
};
using ColumnDependencies = std::unordered_set<ColumnDependency, ColumnDependency::Hash>;
}