ClickHouse/src/Storages/ConstraintsDescription.h

56 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <Parsers/ASTConstraintDeclaration.h>
#include <Interpreters/ExpressionActions.h>
2021-03-04 12:11:43 +00:00
#include <Interpreters/TreeCNFConverter.h>
2021-04-03 12:12:45 +00:00
#include <Interpreters/ComparisonGraph.h>
namespace DB
{
2019-05-19 05:27:00 +00:00
using ConstraintsExpressions = std::vector<ExpressionActionsPtr>;
struct ConstraintsDescription
{
2021-04-26 14:19:18 +00:00
public:
ConstraintsDescription() { update(); }
bool empty() const { return constraints.empty(); }
String toString() const;
static ConstraintsDescription parse(const String & str);
2019-05-19 05:27:00 +00:00
2021-01-04 20:55:32 +00:00
enum class ConstraintType {
CHECK = 1,
ASSUME = 2,
ALWAYS_TRUE = CHECK | ASSUME,
ALL = CHECK | ASSUME,
};
ASTs filterConstraints(ConstraintType selection) const;
2021-04-03 12:12:45 +00:00
2021-04-26 14:19:18 +00:00
const std::vector<ASTPtr> & getConstraints() const;
void updateConstraints(const std::vector<ASTPtr> & constraints);
const std::vector<std::vector<CNFQuery::AtomicFormula>> & getConstraintData() const;
2021-04-03 12:12:45 +00:00
std::vector<CNFQuery::AtomicFormula> getAtomicConstraintData() const;
2021-04-26 14:19:18 +00:00
const ComparisonGraph & getGraph() const;
2021-01-03 15:02:00 +00:00
ConstraintsExpressions getExpressions(ContextPtr context, const NamesAndTypesList & source_columns_) const;
2020-06-05 17:29:40 +00:00
ConstraintsDescription(const ConstraintsDescription & other);
ConstraintsDescription & operator=(const ConstraintsDescription & other);
2021-04-26 14:19:18 +00:00
private:
std::vector<std::vector<CNFQuery::AtomicFormula>> buildConstraintData() const;
std::unique_ptr<ComparisonGraph> buildGraph() const;
void update();
std::vector<ASTPtr> constraints;
std::vector<std::vector<CNFQuery::AtomicFormula>> cnf_constraints;
std::unique_ptr<ComparisonGraph> graph;
};
}