1#include "ASTColumnsMatcher.h"
2#include <IO/WriteHelpers.h>
3#include <Common/quoteString.h>
4#include <re2/re2.h>
5
6
7
8namespace DB
9{
10
11ASTPtr ASTColumnsMatcher::clone() const
12{
13 auto clone = std::make_shared<ASTColumnsMatcher>(*this);
14 clone->cloneChildren();
15 return clone;
16}
17
18void ASTColumnsMatcher::appendColumnName(WriteBuffer & ostr) const { writeString(original_pattern, ostr); }
19
20void ASTColumnsMatcher::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
21{
22 settings.ostr << (settings.hilite ? hilite_keyword : "") << "COLUMNS" << (settings.hilite ? hilite_none : "") << "("
23 << quoteString(original_pattern) << ")";
24}
25
26void ASTColumnsMatcher::setPattern(String pattern)
27{
28 original_pattern = std::move(pattern);
29 column_matcher = std::make_shared<RE2>(original_pattern, RE2::Quiet);
30 if (!column_matcher->ok())
31 throw DB::Exception("COLUMNS pattern " + original_pattern + " cannot be compiled: " + column_matcher->error(), DB::ErrorCodes::CANNOT_COMPILE_REGEXP);
32}
33
34bool ASTColumnsMatcher::isColumnMatching(const String & column_name) const
35{
36 return RE2::PartialMatch(column_name, *column_matcher);
37}
38
39
40}
41