ClickHouse/dbms/src/Parsers/ASTColumnsMatcher.cpp

46 lines
1.3 KiB
C++
Raw Normal View History

2019-07-21 17:03:58 +00:00
#include "ASTColumnsMatcher.h"
2019-07-16 20:05:00 +00:00
2019-07-12 11:17:38 +00:00
#include <IO/WriteBuffer.h>
#include <IO/WriteHelpers.h>
2019-07-16 20:05:00 +00:00
#include <IO/WriteBufferFromString.h>
#include <re2/re2.h>
2019-07-12 11:17:38 +00:00
namespace DB
{
2019-07-21 17:03:58 +00:00
ASTPtr ASTColumnsMatcher::clone() const
2019-07-12 11:17:38 +00:00
{
2019-07-21 17:03:58 +00:00
auto clone = std::make_shared<ASTColumnsMatcher>(*this);
2019-07-12 11:17:38 +00:00
clone->cloneChildren();
return clone;
}
2019-07-21 17:03:58 +00:00
void ASTColumnsMatcher::appendColumnName(WriteBuffer & ostr) const { writeString(original_pattern, ostr); }
2019-07-12 11:17:38 +00:00
2019-07-21 17:03:58 +00:00
void ASTColumnsMatcher::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
2019-07-12 11:17:38 +00:00
{
2019-07-16 20:05:00 +00:00
WriteBufferFromOwnString pattern_quoted;
writeQuotedString(original_pattern, pattern_quoted);
settings.ostr << (settings.hilite ? hilite_keyword : "") << "COLUMNS" << (settings.hilite ? hilite_none : "") << "(" << pattern_quoted.str() << ")";
}
2019-07-21 17:03:58 +00:00
void ASTColumnsMatcher::setPattern(String pattern)
2019-07-16 20:05:00 +00:00
{
original_pattern = std::move(pattern);
2019-07-21 02:13:42 +00:00
column_matcher = std::make_shared<RE2>(original_pattern, RE2::Quiet);
2019-07-16 20:05:00 +00:00
if (!column_matcher->ok())
throw DB::Exception("COLUMNS pattern " + original_pattern + " cannot be compiled: " + column_matcher->error(), DB::ErrorCodes::CANNOT_COMPILE_REGEXP);
2019-07-12 11:17:38 +00:00
}
2019-07-21 17:03:58 +00:00
bool ASTColumnsMatcher::isColumnMatching(const String & column_name) const
2019-07-16 20:05:00 +00:00
{
2019-07-21 02:13:42 +00:00
return RE2::PartialMatch(column_name, *column_matcher);
2019-07-16 20:05:00 +00:00
}
2019-07-12 11:17:38 +00:00
}